I created an App Insights in Central US region using this script:
New-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $defaultRgName -Tag @{ Name = "AppInsightsApp"; Value = $appInsightsName} -ResourceType "Microsoft.Insights/Components" -Location $defaultLocation -PropertyObject @{"Type"="ASP.NET"} -Force
Now I'm trying to add an Alert to this App Insights instance using following script:
$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 $defaultLocation -RuleType Metric -Verbose
And I always getting following error:
Add-AlertRule : ResourceNotSupported: The target resource id
'/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/resourceGroups/RG-Dev-CentralUS/providers/Microsoft.Insights/components/testkktest-appinsights' is not supported.
How can I fix this issue?
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
来源:https://stackoverflow.com/questions/36354057/alert-creation-for-appinsights-fails-with-coderesourcenotsupported