[英]Create log alert rule through powershell and attach more than one action groups to that rule
I want to create an metric alert rule and add two existing action groups to that rule through PowerShell . 我想创建一个度量标准警报规则,并通过PowerShell将两个现有操作组添加到该规则。 I got some code from azure docs that describes how to create and attach a new action group to an alert rule.
我从azure文档中获得了一些代码,这些代码描述了如何创建新操作组并将其附加到警报规则。 Help me , if you know !
帮帮我,如果你知道! (Remember, I want to attach existing action groups)
(请记住,我要附加现有的操作组)
Check the new cmdlet in updated Az.Monitor module - it has ActionGroup
parameter: 检查更新的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.
I suppose you are using Add-AzMetricAlertRule
, if so, I don't think you can add action group to it. 我想您正在使用
Add-AzMetricAlertRule
,如果这样,我认为您不能向其中添加操作组。 The command will create metric alert(classic)
, its resource type is Microsoft.Insights/alertRules
, it does not support to use action group. 该命令将创建
metric alert(classic)
,其资源类型为Microsoft.Insights/alertRules
,它不支持使用操作组。 The -Action
parameter which you can see is to set action(email, webhook), not action group. 您可以看到的
-Action
参数是设置操作(电子邮件,webhook),而不是操作组。 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
. 如果要使用操作组,则需要创建新的指标警报规则,其资源类型为
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. 对于新的度量标准警报规则,似乎没有内置的powershell命令,我们需要使用ARM模板和
New-AzResourceGroupDeployment
来创建它。 See : https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric-create-templates 请参阅: https : //docs.microsoft.com/zh-cn/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
即可添加操作组。
"actions": [
{
"actionGroupId": "[parameters('actionGroupId')]"
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.