question

MSTechie-7364 avatar image
0 Votes"
MSTechie-7364 asked Monalla-MSFT commented

How to add more than 1 action group to an Azure Alert using PowerShell ?

How to add more than 1 action group to an Azure Alert using PowerShell ?

azure-monitor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Monalla-MSFT avatar image
0 Votes"
Monalla-MSFT answered Monalla-MSFT commented

@MSTechie-7364 - Thanks for reaching out.

If you want to use action group, you need to create the new metric alert rule, its resource type is Microsoft.Insights/metricAlerts.

For the new metric alert rule, I don't think there is any built-in PowerShell command, we need to use ARM template and New-AzResourceGroupDeployment to create it.

Take a look at this document for more reference : Alert Metrics Create Template

You can find the actions in the template, just specify the actionGroupId, you will be able to add the action group.

 "actions": [
                     {
                         "actionGroupId": "[parameters('actionGroupId')]"
                     }
                 ]

Hope this helps.

If the above response helped, Please feel free to "Accept as Answer" so it can be beneficial to the community.




· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This PowerShell command takes ActionGroup as an array.
How to supply more than 1 action groups to this. Example please

New-AzScheduledQueryRuleAznsActionGroup
[-ActionGroup <String[]>]

[-EmailSubject <String>]
[-CustomWebhookPayload <String>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]

The parameter -ActionGroup <String[] is an array. How to pass multiple action groups here ?
https://docs.microsoft.com/en-us/powershell/module/az.monitor/new-azscheduledqueryruleaznsactiongroup?view=azps-6.4.0





0 Votes 0 ·

Use the '@' syntex:
https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.1#create-an-array

From the docs:
https://docs.microsoft.com/en-us/powershell/module/az.monitor/new-azscheduledqueryruleaznsactiongroup?view=azps-6.4.0#example-1


$aznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup @("/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup", "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup2") -EmailSubject "Email subject" -CustomWebhookPayload "{}"

0 Votes 0 ·

$aznsActionGroup = New-AzScheduledQueryRuleAznsActionGroup -ActionGroup @("/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup", "/subscriptions/ad825170-845c-47db-8f00-11978947b089/resourcegroups/MyResourceGroup/providers/microsoft.insights/actiongroups/MyActionGroup2") -EmailSubject "Email subject" -CustomWebhookPayload "{}"

Actually i had already tried this option with @ symbol and separating the next action group with a comma (,), but it does not create another action group . it does not give any error as well

You can try and see... it does not create 2 action groups.

0 Votes 0 ·
Show more comments