azure - 如何查找 Azure 警报的自动化参数?

标签 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 ''"
}'

最佳答案

我可以根据您提供的 DOC 为虚拟机创建警报只需替换参数文件中的resourceId 和actionGroupId 的值即可。使用PowerShell成功部署模板文件和参数文件。

enter image description here

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

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

enter image description here

更新

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

enter image description here

关于azure - 如何查找 Azure 警报的自动化参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53297990/

相关文章:

Azure Function Service Bus 触发器引发错误启动操作期间发生主机错误

azure - 添加虚拟网络网关的连接

powershell - Start-Process 可以在 Azure 自动化中使用吗?

Azure 自动化帐户和 Runbooks ARM 模板,uri 问题?

用于访问 Microsoft 图形 API 的 Azure ADAL 库

azure - QnA Maker 正式版与预览版 : it doesn't find the answers

java - Spring Boot 应用程序 SocketException 与 Cosmos DB

Azure Functions 未显示在 Function App 中

azure - 从 ARM 模板中的 Azure key 保管库获取最新版本的证书

sql - 如何在 Azure Runbook 中运行 SQL 批处理?