Reputation: 95
I want to create an metric alert rule and add two existing action groups to that rule through PowerShell . I got some code from azure docs that describes how to create and attach a new action group to an alert rule. Help me , if you know ! (Remember, I want to attach existing action groups)
Upvotes: 0
Views: 1518
Reputation: 81
Check the new cmdlet in updated Az.Monitor module - it has ActionGroup
parameter:
NAME
Add-AzMetricAlertRuleV2
SYNOPSIS
Adds or updates a V2 (non-classic) metric-based alert rule.
SYNTAX
Add-AzMetricAlertRuleV2 -ActionGroup <Microsoft.Azure.Management.Monitor.Models.ActivityLogAlertActionGroup[]> -Condition
<System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricCriteria]> [-DefaultProfile
<Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] [-Description <System.String>] [-DisableRule] -Frequency <System.TimeSpan>
-Name <System.String> -ResourceGroupName <System.String> -Severity <System.Int32> -TargetResourceId <System.String> -WindowSize <System.TimeSpan> [-Confirm] [-WhatIf]
[<CommonParameters>]
Add-AzMetricAlertRuleV2 -ActionGroup <Microsoft.Azure.Management.Monitor.Models.ActivityLogAlertActionGroup[]> -Condition
<System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricCriteria]> [-DefaultProfile
<Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer>] [-Description <System.String>] [-DisableRule] -Frequency <System.TimeSpan>
-Name <System.String> -ResourceGroupName <System.String> -Severity <System.Int32> -TargetResourceRegion <System.String> -TargetResourceScope <System.String[]>
-TargetResourceType <System.String> -WindowSize <System.TimeSpan> [-Confirm] [-WhatIf] [<CommonParameters>]
DESCRIPTION
Adds or updates a V2 (non-classic) metric-based alert rule . The added rule is associated with a resource group and has a name. This cmdlet implements the ShouldProcess
pattern, i.e. it might request confirmation from the user before actually creating, modifying, or removing the resource.
Upvotes: 1
Reputation: 42063
I suppose you are using Add-AzMetricAlertRule
, if so, I don't think you can add action group to it. The command will create metric alert(classic)
, its resource type is Microsoft.Insights/alertRules
, it does not support to use action group. The -Action
parameter which you can see is to set action(email, webhook), not action group. If you check the rule in the portal, you can also find there is nowhere to set action group.
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, seems there is no built-in powershell command, we need to use an ARM template and New-AzResourceGroupDeployment
to create it. See : https://learn.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-create-templates
You can find the actions
in the template, just specific the actionGroupId
, you will be able to add the action group.
"actions": [
{
"actionGroupId": "[parameters('actionGroupId')]"
}
]
Upvotes: 1