使用资源管理器模板创建操作组Create an action group with a Resource Manager template

本文说明如何使用 Azure 资源管理器模板配置操作组。This article shows you how to use an Azure Resource Manager template to configure action groups. 使用模板,可以自动设置可以在某些类型的警报中重复使用的操作组。By using templates, you can automatically set up action groups that can be reused in certain types of alerts. 这些操作组可确保警报触发时所有相应的当事方可以收到通知。These action groups ensure that all the correct parties are notified when an alert is triggered.

基本步骤如下:The basic steps are:

  1. 以 JSON 文件的形式创建一个描述如何创建操作组的模板。Create a template as a JSON file that describes how to create the action group.

  2. 使用任意部署方法部署模板。Deploy the template by using any deployment method.

首先,我们将介绍如何为操作定义在模板中进行了硬编码的操作组创建资源管理器模板。First, we describe how to create a Resource Manager template for an action group where the action definitions are hard-coded in the template. 其次,我们将介绍如何创建在部署模板时以输入参数形式接受 webhook 配置信息的模板。Second, we describe how to create a template that takes the webhook configuration information as input parameters when the template is deployed.

用于操作组的资源管理器模板Resource Manager templates for an action group

若要使用资源管理器模板创建操作组,需要创建 Microsoft.Insights/actionGroups 类型的资源。To create an action group using a Resource Manager template, you create a resource of the type Microsoft.Insights/actionGroups. 然后,填充所有相关属性。Then you fill in all related properties. 以下是两个用于创建操作组的示例模板。Here are two sample templates that create an action group.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "actionGroupName": {
      "type": "string",
      "metadata": {
        "description": "Unique name (within the Resource Group) for the Action group."
      }
    },
    "actionGroupShortName": {
      "type": "string",
      "metadata": {
        "description": "Short name (maximum 12 characters) for the Action group."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Insights/actionGroups",
      "apiVersion": "2018-03-01",
      "name": "[parameters('actionGroupName')]",
      "location": "Global",
      "properties": {
        "groupShortName": "[parameters('actionGroupShortName')]",
        "enabled": true,
        "smsReceivers": [
          {
            "name": "contosoSMS",
            "countryCode": "1",
            "phoneNumber": "5555551212"
          },
          {
            "name": "contosoSMS2",
            "countryCode": "1",
            "phoneNumber": "5555552121"
          }
        ],
        "emailReceivers": [
          {
            "name": "contosoEmail",
            "emailAddress": "devops@contoso.com"
          },
          {
            "name": "contosoEmail2",
            "emailAddress": "devops2@contoso.com"
          }
        ],
        "webhookReceivers": [
          {
            "name": "contosoHook",
            "serviceUri": "http://requestb.in/1bq62iu1"
          },
          {
            "name": "contosoHook2",
            "serviceUri": "http://requestb.in/1bq62iu2"
          }
        ]
      }
    }
  ],
  "outputs":{
      "actionGroupId":{
          "type":"string",
          "value":"[resourceId('Microsoft.Insights/actionGroups',parameters('actionGroupName'))]"
      }
  }
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "actionGroupName": {
      "type": "string",
      "metadata": {
        "description": "Unique name (within the Resource Group) for the Action group."
      }
    },
    "actionGroupShortName": {
      "type": "string",
      "metadata": {
        "description": "Short name (maximum 12 characters) for the Action group."
      }
    },
    "webhookReceiverName": {
      "type": "string",
      "metadata": {
        "description": "Webhook receiver service Name."
      }
    },    
    "webhookServiceUri": {
      "type": "string",
      "metadata": {
        "description": "Webhook receiver service URI."
      }
    }    
  },
  "resources": [
    {
      "type": "Microsoft.Insights/actionGroups",
      "apiVersion": "2018-03-01",
      "name": "[parameters('actionGroupName')]",
      "location": "Global",
      "properties": {
        "groupShortName": "[parameters('actionGroupShortName')]",
        "enabled": true,
        "smsReceivers": [
        ],
        "emailReceivers": [
        ],
        "webhookReceivers": [
          {
            "name": "[parameters('webhookReceiverName')]",
            "serviceUri": "[parameters('webhookServiceUri')]"
          }
        ]
      }
    }
  ],
  "outputs":{
      "actionGroupResourceId":{
          "type":"string",
          "value":"[resourceId('Microsoft.Insights/actionGroups',parameters('actionGroupName'))]"
      }
  }
}

后续步骤Next steps