用于经典警报到新警报转换的 ARM 模板

用于经典警报到新警报转换的 ARM 模板

我已经通过 Azure 门户创建了 1 个 Web 测试经典警报。现在我想将经典警报转换为新警报。我使用以下 ARM 模板进行此操作。

{
    "name": "TestMetricAlert",
    "type": "Microsoft.Insights/metricAlerts",
    "apiVersion": "2018-03-01",
    "location": "global",
    "tags": {},
    "properties": {
      "description": "Test Metric Description",
      "severity": 2,
      "enabled": true,
      "scopes": [

      ],
      "evaluationFrequency": "PT5M",
      "windowSize": "PT5M",
      "targetResourceType": "Microsoft.Insights/webtests",
      "targetResourceRegion": "eastus",
      "criteria": {
        "additionalProperties": {},
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource"
      },
      "dependsOn": [
        "/subscriptions/a85f72bb-4bc4-4a9a-b77b-83db1cc0e1e4/resourceGroups/TestProjectRG/providers/microsoft.insights/webtests/testalert-testappinsights"
      ],
      "autoMitigate": false,
      "actions": [
        {
          "actionGroupId": "/subscriptions/a85f72bb-4bc4-4a9a-b77b-83db1cc0e1e4/resourceGroups/TestProjectRG/providers/microsoft.insights/actionGroups/TestAction"
        }
      ]
    }
  }

但在部署过程中我收到以下错误。

模板部署返回以下错误:
11:56:16 - 11:56:15 AM - 资源 Microsoft.Insights/metricAlerts“TestMetricAlert”失败,消息为“{
11:56:16 - “代码”:“BadRequest”,
11:56:16 - “消息”:“未创建对象。”
11:56:16 - }”

有人能帮助我纠正这里的错误或者 ARM 模板中需要更改的任何内容吗?

答案1

除了尝试迁移工具在 Azure 门户中,您还可以参考doc,甚至可以从 Azure 门户导出模板来检查表示。以下模板对我有用:

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "metricalerts_test_new_alerts_test_log_analytics_name": {
        "defaultValue": "test-new-alerts-test-log-analytics",
        "type": "String"
    },
    "webtests_test_new_alerts_test_log_analytics_externalid": {
        "defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics",
        "type": "String"
    },
    "components_test_log_analytics_externalid": {
        "defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/components/test-log-analytics",
        "type": "String"
    }
},
"variables": {},
"resources": [
    {
        "type": "microsoft.insights/metricalerts",
        "apiVersion": "2018-03-01",
        "name": "[parameters('metricalerts_test_new_alerts_test_log_analytics_name')]",
        "location": "global",
        "tags": {
            "hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/components/test-log-analytics": "Resource",
            "hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics": "Resource"
        },
        "properties": {
            "description": "[concat('Automatically created alert rule for availability test \"', parameters('metricalerts_test_new_alerts_test_log_analytics_name'), '\"')]",
            "severity": 1,
            "enabled": true,
            "scopes": [
                "[parameters('webtests_test_new_alerts_test_log_analytics_externalid')]",
                "[parameters('components_test_log_analytics_externalid')]"
            ],
            "evaluationFrequency": "PT1M",
            "windowSize": "PT5M",
            "criteria": {
                "odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
            },
            "actions": []
        }
    }
]
}

希望这可以帮助!

笔记:经典警报迁移的停用日期已从最初宣布的 2019 年 6 月 30 日延长至 2019 年 8 月 31 日。

相关内容