Powershell to add an action group to alert (Application Insights)

Copper Contributor

Hi all,

 

Whenever I create a new availability test on Application Insights it creates an alert if X amount of locations test fail, I would like to use this alerts instead of creating new ones but I need to add action groups to it.

 

The problem is that I've got over 100 tests created, meaning over 100 alerts and was wondering if there is any way of automating the set of an action group on an existing alert via powershell ou any other way.

 

On Azure Portal I don't think there is any way to apply it to all alerts so that is why I was thinking of powershell as a possible solution.

1 Reply

@techmonit Hi, when you create availability test with alert it actually creates metric alert with the same name in the resource group of the application Insights instance

image.png

I think there are PowerShell cmdlets currently that you can use to get the alerts and modify them. Of course you have to iterate to every resource group if you have multiple application insights instances. These are the commands:

https://docs.microsoft.com/en-us/powershell/module/az.monitor/get-azmetricalertrulev2?view=azps-2.4....

https://docs.microsoft.com/en-us/powershell/module/az.monitor/add-azmetricalertrulev2?view=azps-2.4....

 

 

Other option is to go to the resource group blade. from there you have option for export template. you can grab that template edit it so your alert includes action group (you can remove the other resources that you do not want to modify) and deploy the template. That will modify the alert. Of course you can take that template as well parametrize it so you can apply it to multiple alerts by just changing the input parameters. For example such input parameter could be alert name.

 

Let me know if that helps you solve your task. In both cases I think you will have to do some code writing to achieve the task.