Azure ARM: There is no target resource for this alert

…衆ロ難τιáo~ 提交于 2019-12-24 18:57:23

问题


I'm trying to tie microsoft.insights/alertrules to Microsoft.Web/sites during ARM deployment at azure.

The error is: There is no target resource for this alert CPU default-app-name-plan-ins-westeurope-default-environment

I created the resources in the template using 'automation script' of manually created resources as sample.

The alertrule:

{
  "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')]"
      ]
    }
  }
},

The stack deployed with New-AzureRmResourceGroupDeployment -Verbose -ResourceGroupName rg.test.ARM -TemplateFile azuredeploy.json -TemplateParameterFile azuredeploy.parameters.json -DeploymentDebugLogLevel All

The full code is here and parameters are here

What am I doing wrong?


回答1:


I had the same error message but resolved it by adding the $type properties to conditions and actions, and a tag for the resource, following the example from this template

So it looks like:

  {
  "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": []
      }
    ]
  }
}


来源:https://stackoverflow.com/questions/50056600/azure-arm-there-is-no-target-resource-for-this-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!