快速入门:使用 ARM 模板创建有关服务通知的活动日志警报Quickstart: Create activity log alerts on service notifications using an ARM template

本文介绍如何使用 Azure 资源管理器模板(ARM 模板)为服务运行状况通知设置活动日志警报。This article shows you how to set up activity log alerts for service health notifications by using an Azure Resource Manager template (ARM template).

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

服务运行状况通知存储在 Azure 活动日志中。Service health notifications are stored in the Azure activity log. 鉴于活动日志中存储的信息量可能很大,因此有一个单独的用户界面,以便更轻松地查看和设置有关服务运行状况通知的警报。Given the possibly large volume of information stored in the activity log, there is a separate user interface to make it easier to view and set up alerts on service health notifications.

当 Azure 将服务运行状况通知发送到 Azure 订阅时,可以收到警报。You can receive an alert when Azure sends service health notifications to your Azure subscription. 可以基于以下内容配置警报:You can configure the alert based on:

  • 服务运行状况通知的类别(服务问题、计划内维护、运行状况公告)。The class of service health notification (Service issues, Planned maintenance, Health advisories).
  • 受影响的订阅。The subscription affected.
  • 受影响的服务。The service(s) affected.
  • 受影响的区域。The region(s) affected.

备注

服务运行状况通知不会发送有关资源运行状况事件的警报。Service health notifications does not send an alert regarding resource health events.

还可以配置向其发送警报的人员:You also can configure who the alert should be sent to:

  • 选择现有操作组。Select an existing action group.
  • 创建新操作组(可以用于将来的警报)。Create a new action group (that can be used for future alerts).

若要了解有关操作组的详细信息,请参阅创建和管理操作组To learn more about action groups, see Create and manage action groups.

先决条件Prerequisites

查看模板Review the template

以下模板将创建以电子邮件为目标的操作组,并为目标订阅启用所有服务运行状况通知。The following template creates an action group with an email target and enables all service health notifications for the target subscription. 将此模板另存为 CreateServiceHealthAlert.json。Save this template as CreateServiceHealthAlert.json .

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "actionGroups_name": {
      "type": "String",
      "defaultValue": "SubHealth"
    },
    "activityLogAlerts_name": {
      "type": "String",
      "defaultValue": "ServiceHealthActivityLogAlert"
    },
    "emailAddress": {
      "type": "string"
    }
  },
  "variables": {
    "alertScope": "[concat('/','subscriptions','/',subscription().subscriptionId)]"
  },
  "resources": [
    {
      "comments": "Action Group",
      "type": "microsoft.insights/actionGroups",
      "apiVersion": "2019-06-01",
      "name": "[parameters('actionGroups_name')]",
      "location": "Global",
      "scale": null,
      "dependsOn": [],
      "tags": {},
      "properties": {
        "groupShortName": "[parameters('actionGroups_name')]",
        "enabled": true,
        "emailReceivers": [
          {
            "name": "[parameters('actionGroups_name')]",
            "emailAddress": "[parameters('emailAddress')]"
          }
        ],
        "smsReceivers": [],
        "webhookReceivers": []
      }
    },
    {
      "comments": "Service Health Activity Log Alert",
      "type": "microsoft.insights/activityLogAlerts",
      "apiVersion": "2017-04-01",
      "name": "[parameters('activityLogAlerts_name')]",
      "location": "Global",
      "scale": null,
      "dependsOn": [
        "[resourceId('microsoft.insights/actionGroups', parameters('actionGroups_name'))]"
      ],
      "tags": {},
      "properties": {
        "scopes": [
          "[variables('alertScope')]"
        ],
        "condition": {
          "allOf": [
            {
              "field": "category",
              "equals": "ServiceHealth"
            },
            {
              "field": "properties.incidentType",
              "equals": "Incident"
            }
          ]
        },
        "actions": {
          "actionGroups": [
            {
              "actionGroupId": "[resourceId('microsoft.insights/actionGroups', parameters('actionGroups_name'))]",
              "webhookProperties": {}
            }
          ]
        },
        "enabled": true,
        "description": ""
      }
    }
  ]
}

该模板定义了两个资源:The template defines two resources:

部署模板Deploy the template

使用部署 ARM 模板的任何标准方法来部署模板,如以下使用 CLI 和 PowerShell 的示例。Deploy the template using any standard method for deploying an ARM template such as the following examples using CLI and PowerShell. 将“资源组”和“emailAddress”的示例值替换为环境的相应值 。Replace the sample values for Resource Group and emailAddress with appropriate values for your environment.

az login
az deployment group create --name CreateServiceHealthAlert --resource-group my-resource-group --template-file CreateServiceHealthAlert.json --parameters emailAddress='user@contoso.com'

验证部署Validate the deployment

验证是否已使用以下命令之一创建工作区。Verify that the workspace has been created using one of the following commands. 将“资源组”的示例值替换为上面使用的值。Replace the sample values for Resource Group with the value you used above.

az monitor activity-log alert show --resource-group my-resource-group --name ServiceHealthActivityLogAlert

清理资源Clean up resources

如果打算继续使用后续的快速入门和教程,则可能需要保留这些资源。If you plan to continue working with subsequent quickstarts and tutorials, you might want to leave these resources in place. 如果不再需要资源组,可以将其删除,这将删除警报规则和相关的资源。When no longer needed, delete the resource group, which deletes the alert rule and the related resources. 使用 Azure CLI 或 Azure PowerShell 删除资源组To delete the resource group by using Azure CLI or Azure PowerShell

az group delete --name my-resource-group

后续步骤Next steps