0

我创建了一个管道 yaml 文件来创建天蓝色警报。但是使用的逻辑过于复杂,无法将值输入管道。有什么方法可以将输入通过 excel 表(如阈值)传递到管道 yaml 或使用 arm 模板以使其更容易?这应该可以在一次尝试中重复用于 n 个具有不同设置和阈值的警报

parameters:
- name: subscription
  type: string
  default: 'MySubscription'
- name: resourceGroup
  type: string
  default: 'myrg'
- name: alerttype
  type: string
  values:
  - scheduledQueryRules
  - metricAlerts
  default: ''  
- name: alertquerylist
  type: object
  default:
  - query1
  - query2
- name: alertdeploymentname
  type: string
  default: ''   
  values:
  - deployment1
  - deployment2
  - deployment3
  -
  -
  - deploymentn
- name: querytype
  type: string
  default: 'ResultCount'
- name: alertname
  type: string
  default: ''
 
  
trigger: none

stages:
- stage: Create_Log_Alert
  displayName: 'Create logaAnalytics Query based Alert'
  variables:
    - group: alert-config
    - name: alertquery
      value: ${{ parameters.alertquery }}
    - name: querytype
      value: ${{ parameters.querytype }}
    - name: alertname
      value: ${{ parameters.alertname }}-${{ parameters.alertdeploymentname}}
  condition: eq('${{ parameters.alerttype }}', 'scheduledQueryRules')

- ${{ each alertquery in parameters.alertquerylist }}:  
  jobs:
  - job: Create_Alert
    pool:
      name: az-dev-spoke    
    steps:
    - task: replacetokens@3
      inputs:
        rootDirectory: '$(System.DefaultWorkingDirectory)/'
        targetFiles: '**/parameters.json'
        encoding: 'auto'
        writeBOM: true
        actionOnMissing: 'warn'
        keepToken: false
        tokenPrefix: '#{'
        tokenSuffix: '}#'
        useLegacyPattern: false
        enableTelemetry: true
    - task: AzureResourceGroupDeployment@2
      inputs:
        azureSubscription: ${{ parameters.subscription }}
        action: 'Create Or Update Resource Group'
        resourceGroupName: ${{ parameters.resourceGroup }}
        location: 'West Europe'
        templateLocation: 'Linked artifact'
        csmFile: '$(System.DefaultWorkingDirectory)/template.json'
        csmParametersFile: '$(System.DefaultWorkingDirectory)/parameters.json'
        deploymentMode: 'Incremental'
        deploymentName: ${{ parameters.alertdeploymentname }}

- stage: Create_Metric_Alert
  displayName: 'Create Metric based Alert'
  variables:
    - group: metric-alert-config
    - name: alertquery
      value: ${{ parameters.alertquery }}
    - name: querytype
      value: ${{ parameters.querytype }}
    - name: alertname
      value: ${{ parameters.alertname }}-${{ parameters.alertdeploymentname}}
  condition: eq('${{ parameters.alerttype }}', 'scheduledQueryRules')

- ${{ each alertquery in parameters.alertquerylist }}:  
  jobs:
  - job: Create_Alert
    pool:
      name: mypool   
    steps:
    - task: replacetokens@3
      inputs:
        rootDirectory: '$(System.DefaultWorkingDirectory)/'
        targetFiles: '**/metric-parameters.json'
        encoding: 'auto'
        writeBOM: true
        actionOnMissing: 'warn'
        keepToken: false
        tokenPrefix: '#{'
        tokenSuffix: '}#'
        useLegacyPattern: false
        enableTelemetry: true
    - task: AzureResourceGroupDeployment@2
      inputs:
        azureSubscription: ${{ parameters.subscription }}
        action: 'Create Or Update Resource Group'
        resourceGroupName: ${{ parameters.resourceGroup }}
        location: 'West Europe'
        templateLocation: 'Linked artifact'
        csmFile: '$(System.DefaultWorkingDirectory)/template.json'
        csmParametersFile: '$(System.DefaultWorkingDirectory)/parameters.json'
        deploymentMode: 'Incremental'
        deploymentName: ${{ parameters.alertdeploymentname }}    
4

0 回答 0