使用ARM模板的应用洞察力警报

时间:2019-01-25 08:23:35

标签: azure arm-template

我正在尝试使用ARM模板配置应用程序洞察警报。我已将以下内容用于服务器响应时间警报;

{
      "name": "[variables('responseAlertName')]",
      "type": "Microsoft.Insights/alertrules",
      "apiVersion": "2014-04-01",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('components_appinsights_name')))]": "Resource"
      },
      "properties": {
        "name": "[variables('responseAlertName')]",
        "description": "response time alert",
        "isEnabled": true,
        "condition": {
          "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
          "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
          "dataSource": {
            "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
            "resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsights_name'))]",
            "metricName": "request.duration"
          },
          "threshold": "10",
          "windowSize": "PT5M"
        },
        "actions": [
          {
            "$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
            "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
            "sendToServiceOwners": true,
            "customEmails": []
          }
        ]
      }
    }

但是问题是,它正在作为门户中的“经典”警报添加。应该如何更改模板,以便将警报添加为新警报而不是传统警报?

3 个答案:

答案 0 :(得分:1)

类型“ Microsoft.Insights / alertrules”是“经典”指标和Classic alerts in Azure Monitor to retire in June 2019

您可以使用类型为“ Microsoft.Insights / metricAlerts”的新模块为metric alert。请参阅Metric Alert in the template,您将知道可以设置的所有属性。

有关旧警报和新警报之间的区别的更多详细信息,请参见Old and New alerting capabilities

答案 1 :(得分:0)

我最终做了以下事情;

audidate

答案 2 :(得分:0)

您可以使用Azure门户中的Migration tool将所有已配置的警报迁移到较新的警报。您也可以参考this文档中提到的示例模板,甚至可以从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日。