我想创建一个度量标准警报规则,并通过PowerShell将两个现有操作组添加到该规则。我从azure docs获得了一些代码,这些代码描述了如何创建新的操作组并将其附加到警报规则。如果你知道,请帮助我! (记住,我想附加现有的行动小组)
我想你正在使用Add-AzMetricAlertRule
,如果是这样,我认为你不能添加行动组。该命令将创建metric alert(classic)
,其资源类型为Microsoft.Insights/alertRules
,它不支持使用操作组。您可以看到的-Action
参数是设置操作(电子邮件,webhook),而不是操作组。如果您在门户中检查规则,您还可以发现无处可设置操作组。
如果要使用操作组,则需要创建新的度量标准警报规则,其资源类型为Microsoft.Insights/metricAlerts
。对于新的度量标准警报规则,似乎没有内置的powershell命令,我们需要使用ARM模板和New-AzResourceGroupDeployment
来创建它。见:https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-create-templates
你可以在模板中找到actions
,只需要特定的actionGroupId
,你就可以添加动作组了。
"actions": [
{
"actionGroupId": "[parameters('actionGroupId')]"
}
]
检查更新的Az.Monitor模块中的新cmdlet - 它具有ActionGroup
参数:
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.