如何找到 Azure 警报的自动化参数?

How do I find the automation parameters for Azure alerts?

我已在 Azure 门户中为平均响应时间指标设置警报。现在我想自动化它,以便在每次新部署时都设置此警报。 当我转到我的资源组下的自动化脚本选项卡时,我可以看到警报指标已添加,但我找不到警报标准参数,有人知道它们在哪里定义吗?

我在 docs 中找到了这个资源,我已经关注了。

这部分我可以在我的自动化脚本中看到

"resources": [
    {
        "comments": "Generalized from resource: '/subscriptions/XXX/resourceGroups/resourcegroup-dev-weu/providers/microsoft.insights/metricAlerts/response-time-avg'.",
        "type": "microsoft.insights/metricAlerts",
        "name": "[parameters('metricAlerts_response_time_avg_name')]",
        "apiVersion": "2018-03-01",
        "location": "global",
        "tags": {},
        "scale": null,
        "properties": {
            "description": "Alert if the response time get above 1 second on average for the last 1 minute, 1 minute intervals.",
            "severity": 3,
            "enabled": true,
            "scopes": [
                "/subscriptions/XXX/resourceGroups/resourcegroup-dev-weu/providers/Microsoft.Web/sites/webapp-dev-weu"
            ],
            "evaluationFrequency": "PT1M",
            "windowSize": "PT1M",
            "criteria": {
                "odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
            },
            "actions": [
                {
                    "actionGroupId": "[parameters('metricAlerts_response_time_avg_actionGroupId')]",
                    "webHookProperties": {}
                }
            ]
        },
        "dependsOn": []
    }
]

但是这部分我找不到

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "alertName": {
            "value": "New Metric Alert"
        },
        "alertDescription": {
            "value": "New metric alert created via template"
        },
        "alertSeverity": {
            "value":3
        },
        "isEnabled": {
            "value": true
        },
        "resourceId": {
            "value": "/subscriptions/replace-with-subscription-id/resourceGroups/replace-with-resourceGroup-name/providers/Microsoft.Compute/virtualMachines/replace-with-resource-name"
        },
        "metricName": {
            "value": "Percentage CPU"
        },
        "operator": {
             "value": "GreaterThan"
        },
        "threshold": {
            "value": "80"
        },
        "timeAggregation": {
            "value": "Average"
        },
        "actionGroupId": {
            "value": "/subscriptions/replace-with-subscription-id/resourceGroups/resource-group-name/providers/Microsoft.Insights/actionGroups/replace-with-action-group"
        }
    }
}

当我在未定义参数的情况下尝试 运行 时出现此错误:

New-AzureRmResourceGroupDeployment : 17:07:53 - Resource microsoft.insights/metricAlerts 'response-time-avg' failed with message '{
  "Code": "BadRequest",
  "Message": "Unable to find any of the requested metrics ''"
}'

我可以在您提供 DOC 之后为 VM 创建警报,只需替换为参数文件中的 resourceId 和 actionGroupId 的值。使用 PowerShell 成功部署模板文件和参数文件。

之后,您可以在自动化脚本选项卡中看到资源类型microsoft.insights/metricAlerts。创建警报后,您可以看到 criteria 属性和 criteria 参数,请参阅以下内容。

如果您想导出特定的警报模板而不是当前组中的所有资源。您可以参考这些步骤:转到资源组页面-设置-部署-单击新创建的警报 部署名称。您将在模板中找到资源和参数并下载它。获取 viewing template.

的更多详细信息

更新

使用与上面相同的部署,我可以使用 Azure REST API 查看更多 criteria 参数,如下所示。自动化选项卡似乎没有显示所有必要的信息。获取完整自动化脚本的唯一方法是使用 Azure REST API 获取指标警报。