Azure Resource Manager警报创建

时间:2016-04-21 02:49:55

标签: azure azure-resource-manager azure-application-insights

我尝试使用Azure Resource Manager模板在Application Insights中创建警报。我遇到的问题是我应该为resourceUri赋予什么价值。我尝试了一些不同的价值观,我不确定它是否应该是我监控的资源或其他什么。文档是最无益的。当我尝试使用下面的值时,它会给我一个验证错误。

我还不清楚我是如何将警报与组件关联起来的。它应该嵌套为组件中的资源吗?我有dependsOn引用该组件,但据我所知,这将确保首先创建其他资源。

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "apiVersion": "2014-04-01",
            "type": "Microsoft.Insights/components",
            "name": "testmetrics",
            "location": "Central US"
        },
        {
            "apiVersion": "2014-04-01",
            "type": "Microsoft.Insights/alertrules",
            "name": "testAlert1",
            "dependsOn": [
                "[concat('Microsoft.Insights/components/', 'testmetrics')]"
            ],
            "location": "Central US",
            "properties": {
                "description": "Test description",
                "action": {
                    "customEmails": [ "me@somewhere.com" ]
                },
                "condition": {
                    "failedLocationCount": "1",
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
                    "threshold": "0",
                    "dataSource": {
                        "metricName": "BackupFailed",
                        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
                        "resourceUri": "/Microsoft.Web/sites/mytestsite"
                    },
                    "operator": "GreaterThan",
                    "windowSize": "1"
                }
            }
        }
    ]
}

2 个答案:

答案 0 :(得分:2)

resourceUrl应按以下格式引用Application Insights服务:

"resourceUri": "[concat(resourceGroup().id, '/providers/Microsoft.Insights/components/', 'testmetrics')]"

答案 1 :(得分:0)

找出如何正确编写这些模板的好方法(如果在ARM quickstart templates的Github存储库中找不到引用)是在Azure portal中创建资源组,配置您的系统然后导出到JSON模板(单击资源组时在“设置”刀片中找到)。

我刚创建了一个带有警报的示例Application Insights资源,并获得了下面的一个。

您可以看到依赖项是如何嵌套的以及正确的语法。另请注意,美国中部地区的位置为“centralus”

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "alertrules_analertname_name": {
        "defaultValue": "analertname",
        "type": "String"
    },
    "components_appinsightname_name": {
        "defaultValue": "appinsightname",
        "type": "String"
    }
},
"variables": {},
"resources": [
    {
        "comments": "Generalized from resource: '/subscriptions/SOME-SUBSCRIPTIN-GUID/resourceGroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/alertrules/analertname'.",
        "type": "microsoft.insights/alertrules",
        "name": "[parameters('alertrules_analertname_name')]",
        "apiVersion": "2014-04-01",
        "location": "East US",
        "tags": {
            "hidden-link:/subscriptions/SOME-SUBSCRIPTIN-GUID/resourcegroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/components/appinsightname": "Resource"
        },
        "properties": {
            "name": "[parameters('alertrules_analertname_name')]",
            "description": "Some alert",
            "isEnabled": true,
            "condition": {
                "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
                "dataSource": {
                    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
                    "resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsightname_name'))]",
                    "metricName": "availability.availabilityMetric.value"
                },
                "threshold": 1,
                "windowSize": "PT5M"
            },
            "action": {
                "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
                "customEmails": [
                    "someemail@example.com"
                ]
            }
        },
        "dependsOn": [
            "[resourceId('microsoft.insights/components', parameters('components_appinsightname_name'))]"
        ]
    },
    {
        "comments": "Generalized from resource: '/subscriptions/SOME-SUBSCRIPTIN-GUID/resourceGroups/Default-ApplicationInsights-CentralUS/providers/microsoft.insights/components/appinsightname'.",
        "type": "microsoft.insights/components",
        "kind": "web",
        "name": "[parameters('components_appinsightname_name')]",
        "apiVersion": "2014-04-01",
        "location": "centralus",
        "tags": {},
        "properties": {
            "ApplicationId": "[parameters('components_appinsightname_name')]"
        },
        "dependsOn": []
    }
]

}

希望这有帮助。