2
votes

Want to update Smart detection setting alerts provided under Azure application insights using powershell cmdlets.

I want to update Smart detection setting alerts provided under Azure application insights using powershell cmdlets, following is a scenario which i want to accomplish.

Scenario: I want to update Failure Anomalies alert and register my emailid under additional email recipients and want to disable the default mail to subscription owner configuration.

Is there any way above mentioned scenario can be accomplished using powershell cmdlets?

1
You are asking folks to write code for you, since you are not showing any. That's not really the mission here: What have you searched for? What code have you tried? Have you installed the needed Azure module(s)? Why have you not already reviewed the help / examples in the Azure module(s)? This sort of use case is documented in in the MS Azure tech guidance docs. There are modules on the MS poershellgallery.com, that can be used for Azure scenarios. - postanote
Hello, if the answer below works for you, please help mark it as answer. Thanks. - Ivan Yang

1 Answers

1
votes

Update:

Here is a solution and assume your have azure powershell az module installed(it's ok if you're using powershell azureRM module, but you need to just change the cmdlet respectively):

#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

it works well at my side, and test result as below:

enter image description here