AppInsights的警报创建失败,并显示“Code”:“ResourceNotSupported”

时间:2016-04-01 10:31:11

标签: azure-powershell azure-application-insights

我使用此脚本在美国中部地区创建了一个App Insights:

New-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $defaultRgName -Tag @{ Name = "AppInsightsApp"; Value = $appInsightsName} -ResourceType "Microsoft.Insights/Components" -Location $defaultLocation -PropertyObject @{"Type"="ASP.NET"} -Force

现在我正在尝试使用以下脚本向此App Insights实例添加警报:

$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

我总是得到以下错误:

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.

如何解决此问题?

2 个答案:

答案 0 :(得分:2)

看起来只能在美国东部创建警报规则。在Azure门户中也是如此 - 您无法选择位置,但所有规则都是在美国东部创建的。

尝试在Powershell命令中使用East USA位置:

$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

答案 1 :(得分:0)

Azure资源并非在每种区域或云类型中都可用。因此,在构建模板或执行PS创建/移动资源脚本之前,您必须进行检查。

用于检查资源可用性区域的Powershell命令:

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

您会注意到我使用了ApiVersion标志。这将是必需的,因为某些资源仅在使用其较新API的区域中可用。

由于在部署ARM模板时遇到了相同的问题,因此需要确保我的可部署区域列表不包含无效值。因此,我生成了一个有效区域列表,可以部署以下区域。

  • Microsoft.Insights /组件
  • Microsoft.Insights / webtests
  • microsoft.insights / alertrules

这是我用来生成列表的Powershell。从这篇文章开始,我的目标是2015年5月1日。

$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-包含$ _} | ?{$ alertrules-包含$ _}

结果列表为:

East US
South Central US
North Europe
West Europe
Southeast Asia
West US 2
Canada Central
Central India