如何通过PowerShell脚本更新智能检测设置警报

问题描述 投票:2回答:1

要使用PowerShell cmdlet更新Azure应用程序洞察下提供的智能检测设置警报。

我想使用powershell cmdlet更新Azure应用程序洞察下提供的智能检测设置警报,以下是我想要完成的方案。

场景:我想更新Failure Anomalies警报并在其他电子邮件收件人下注册我的emailid,并希望禁用默认邮件到订阅所有者配置。

是否有任何方法可以使用PowerShell cmdlet完成上述方案?

azure powershell azure-application-insights
1个回答
1
投票

更新:

这是一个解决方案,并假设您已安装azure powershell az module(如果您使用的是powershell azureRM模块,则可以,但您只需要分别更改cmdlet):

#the -Name parameter is the Failure Anomalies alert name you see in azure portal, like "Failure Anomalies - your_app_insights_name"
$alets_all = Get-AzAlertRule -ResourceGroupName "xxx" -Name "xxx"
$a = $alets_all[0]
$AppIns = "xxx" #the application insights name
$ResourceGroup = "xxxx"
$SubscriptionId ="xxxx"
$Location =$a.Location
$MetricName =$a.Condition.DataSource.MetricName
$action=New-AzAlertRuleEmail -CustomEmail "[email protected]; [email protected]"
$action.SendToServiceOwners=$false
Add-AzMetricAlertRule -Name "Failure Anomalies - $AppIns" -ResourceGroupName $ResourceGroup -TargetResourceId "/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/microsoft.insights/components/$AppIns" -Operator GreaterThan -Threshold 0 -WindowSize 01:00:00 -Location $Location -TimeAggregationOperator Total -Action $action -MetricName $MetricName

它在我身边很好用,测试结果如下:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.