Azure ARM:此警报没有目标资源

时间:2018-04-27 06:34:43

标签: azure azure-application-insights

我正试图在Azure部署期间将microsoft.insights/alertrules绑定到Microsoft.Web/sites

错误是:There is no target resource for this alert CPU default-app-name-plan-ins-westeurope-default-environment

我使用手动创建的资源的“自动化脚本”作为示例在模板中创建了资源。

警报规则:

{
  "type": "microsoft.insights/alertrules",
  "location": "[variables('location')]",
  "apiVersion": "2016-03-01",
  "name": "[concat('CPU ', variables('insightComponentName'))]",
  "dependsOn": [ "[resourceId('microsoft.insights/components', variables('insightComponentName'))]" ],
  "tags": "[parameters('tags')]",
  "properties": {
    "name": "[concat('CPU ', variables('insightComponentName'))]",
    "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', variables('insightComponentName'))]",
        "metricNamespace": null,
        "metricName": "performanceCounter.percentage_processor_time_normalized.value"
      },
      "operator": "GreaterThan",
      "threshold": 85,
      "windowSize": "PT5M"

    },
    "action": {
      "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
      "sendToServiceOwners": false,
      "customEmails": [
        "[parameters('alertReceiver')]"
      ]
    }
  }
},

使用New-AzureRmResourceGroupDeployment -Verbose -ResourceGroupName rg.test.ARM -TemplateFile azuredeploy.json -TemplateParameterFile azuredeploy.parameters.json -DeploymentDebugLogLevel All

部署的堆栈

完整代码为here,参数为here

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我收到了相同的错误消息,但是通过将$type属性添加到conditionsactions以及资源的tag来解决此问题,遵循示例{{ 3}}

所以看起来像:

  {
  "name": "[variables('responseAlertName')]",
  "type": "Microsoft.Insights/alertrules",
  "apiVersion": "2014-04-01",
  "location": "[parameters('location')]",
  "dependsOn": [
    "[resourceId('Microsoft.Insights/components', variables('appInsName'))]"
  ],
  "tags": {
    "[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsName')))]": "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', variables('appInsName'))]",
        "metricName": "request.duration"
      },
      "threshold": "[parameters('responseTime')]",
      "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": []
      }
    ]
  }
}