2

我试图使用Azure资源管理器模板在Application Insights中创建警报。我遇到的问题是我应该为resourceUri投入什么价值。我尝试了一些不同的值,我不确定它是否应该是我正在监控的资源或其他内容。该文档是最无助的。当我尝试使用下面的值时,它给我一个验证错误。Azure资源管理器警报创建

这还不清楚我是如何将警报与组件关联的。它是否应该作为组件内的资源嵌套?我有一个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": [ "[email protected]" ] 
       }, 
       "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" 
       } 
      } 
     } 
    ] 
} 
+0

是的,你是对的。 dependsOn仅用于确保首先创建资源。在您的情况下警报规则应取决于应用程序见解服务。 –

回答

0

一个伟大的方式来弄清楚如何正确地写这些模板(如果你不能找到在参考Github存储库ARM quickstart templates)是在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": [ 
        "[email protected]" 
       ] 
      } 
     }, 
     "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": [] 
    } 
] 

}

希望这有助于提供。

+0

绝对有帮助!这正是我正在寻找的那种东西,但我不知道在门户中找到它。我试图在资源组的部署历史记录中找到它。这将使写模板变得更容易。不幸的是,似乎并非所有资源都可以这种方式导出(例如,无法获取“Microsoft.Scheduler/jobcollections”类型的资源,这种类型的资源将不会被导出(代码:ExportTemplateProviderError))。但这是一个与此不同的问题。 –

2

resourceUrl应参考应用洞察服务格式如下:

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

对不起,应该提到我已经尝试过了。它给了我这个错误:不支持目标资源ID'/ subscriptions//resourceGroups/<资源组> /providers/Microsoft.Insights/components/testmetrics'。 (代码:ResourceNotSupported) –

+2

“中央美国”不是警报规则的有效位置,请尝试使用“东美”。 http://stackoverflow.com/questions/36354057/alert-creation-for-appinsights-fails-with-coderesourcenotsupported/36647495#36647495 –

+0

是的,这似乎是问题的一部分。奇怪的是,应用程序见解组件将在一个地区和警报在另一个地区。 –