I created an App Insights in Central US region using this script:
New-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $defaultRgName -Tag @{ Na
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.
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
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 "some@email.addresss" -Location "East US" -RuleType Metric -Verbose