Home

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

%3CLINGO-SUB%20id%3D%22lingo-sub-754545%22%20slang%3D%22en-US%22%3EPowershell%20to%20add%20an%20action%20group%20to%20alert%20(Application%20Insights)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754545%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhenever%20I%20create%20a%20new%20availability%20test%20on%20Application%20Insights%20it%20creates%20an%20alert%20if%20X%20amount%20of%20locations%20test%20fail%2C%20I%20would%20like%20to%20use%20this%20alerts%20instead%20of%20creating%20new%20ones%20but%20I%20need%20to%20add%20action%20groups%20to%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%20that%20I've%20got%20over%20100%20tests%20created%2C%20meaning%20over%20100%20alerts%20and%20was%20wondering%20if%20there%20is%20any%20way%20of%20automating%20the%20set%20of%20an%20action%20group%20on%20an%20existing%20alert%20via%20powershell%20ou%20any%20other%20way.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20Azure%20Portal%20I%20don't%20think%20there%20is%20any%20way%20to%20apply%20it%20to%20all%20alerts%20so%20that%20is%20why%20I%20was%20thinking%20of%20powershell%20as%20a%20possible%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-754545%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eaction%20groups%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAlerts%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EApplication%20Insights%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-764441%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20to%20add%20an%20action%20group%20to%20alert%20(Application%20Insights)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-764441%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F376383%22%20target%3D%22_blank%22%3E%40techmonit%3C%2FA%3EHi%2C%20when%20you%20create%20availability%20test%20with%20alert%20it%20actually%20creates%20metric%20alert%20with%20the%20same%20name%20in%20the%20resource%20group%20of%20the%20application%20Insights%20instance%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20678px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F123826iF910CED23760BE4F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EI%20think%20there%20are%20PowerShell%20cmdlets%20currently%20that%20you%20can%20use%20to%20get%20the%20alerts%20and%20modify%20them.%20Of%20course%20you%20have%20to%20iterate%20to%20every%20resource%20group%20if%20you%20have%20multiple%20application%20insights%20instances.%20These%20are%20the%20commands%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fget-azmetricalertrulev2%3Fview%3Dazps-2.4.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fget-azmetricalertrulev2%3Fview%3Dazps-2.4.0%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fadd-azmetricalertrulev2%3Fview%3Dazps-2.4.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.monitor%2Fadd-azmetricalertrulev2%3Fview%3Dazps-2.4.0%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOther%20option%20is%20to%20go%20to%20the%20resource%20group%20blade.%20from%20there%20you%20have%20option%20for%20export%20template.%20you%20can%20grab%20that%20template%20edit%20it%20so%20your%20alert%20includes%20action%20group%20(you%20can%20remove%20the%20other%20resources%20that%20you%20do%20not%20want%20to%20modify)%20and%20deploy%20the%20template.%20That%20will%20modify%20the%20alert.%20Of%20course%20you%20can%20take%20that%20template%20as%20well%20parametrize%20it%20so%20you%20can%20apply%20it%20to%20multiple%20alerts%20by%20just%20changing%20the%20input%20parameters.%20For%20example%20such%20input%20parameter%20could%20be%20alert%20name.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%20me%20know%20if%20that%20helps%20you%20solve%20your%20task.%20In%20both%20cases%20I%20think%20you%20will%20have%20to%20do%20some%20code%20writing%20to%20achieve%20the%20task.%3C%2FP%3E%3C%2FLINGO-BODY%3E
techmonit
New 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.