用於經典警報到新警報轉換的 ARM 模板

用於經典警報到新警報轉換的 ARM 模板

我透過 Azure 入口網站建立了 1 個 Web 測試經典警報。現在我想將經典警報轉換為新警報。

{
    "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 - "Code": "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 日。

相關內容