我想创建一个度量标准警报规则,并通过PowerShell将两个现有操作组添加到该规则。我从azure文档中获得了一些代码,这些代码描述了如何创建新操作组并将其附加到警报规则。帮帮我,如果你知道! (请记住,我想附加现有的操作组)
答案 0 :(得分:1)
检查更新的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.
答案 1 :(得分:0)
我想您正在使用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')]"
}
]