Alert creation for AppInsights fails with “Code”:“ResourceNotSupported”

醉酒当歌 提交于 2019-12-02 05:48:21

It looks like alert rules can be created only in East US. The same in Azure Portal - you cannot select location, but all rules are created in East US.

Try to use East US location in Powershell command:

$appInsights =  Get-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $defaultRgName -ResourceType "Microsoft.Insights/Components" -Verbose

Add-AlertRule -Name "Exception Occured" -Description "Exception occured alert" -ResourceGroup $defaultRgName -ResourceId $appInsights.ResourceId -MetricName "Server Exceptions" -Operator GreaterThanOrEqual -Threshold 1 -WindowSize 00:05:00 -CustomEmails "ops@uptick.com" -Location "East US" -RuleType Metric -Verbose

Azure Resources are not all available in every region or cloud type. So you will have to check before you build out your templates or execute PS create/move resource scripts.

Powershell command for checking the availability region of a resource:

$resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Insights -ApiVersion "2015-05-01"
$resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'components')}.Locations

You'll notice that I used the ApiVersion flag. This is going to be required since some resources are only available in regions with their newer APIs.

Because I had this same issue when deploying my ARM Templates, I needed to makes sure that my deployable region list did not include invalid values. So I generated a list of valid regions that I can deploy the following.

  • Microsoft.Insights/components
  • Microsoft.Insights/webtests
  • microsoft.insights/alertrules

Here is the Powershell I generated my list with. I am targeting the 2015-05-01 API as of this post.

$resources = Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Insights -ApiVersion "2015-05-01"
$components = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'components')}.Locations
$webtests = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'webtests')}.Locations
$alertrules = $resources.ResourceTypes.Where{($_.ResourceTypeName -eq 'alertrules')}.Locations

$components | ?{ $webtests -contains $_ } | ?{ $alertrules -contains $_ }

And the resulting list is:

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