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

时间:2018-11-14 10:28:13

标签: azure azure-resource-manager azure-automation

我已在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 ''"
}'

1 个答案:

答案 0 :(得分:2)

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

enter image description here

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

如果要导出特定警报模板而不是当前组中的所有资源。您可以参考以下步骤:转到资源组页-在设置-部署下-单击新创建的警报部署名称。您将在模板中找到资源和参数,然后将其下载。获取有关viewing template的更多详细信息。

enter image description here

更新

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

enter image description here