简体   繁体   English

通过Powershell创建日志警报规则,并将多个操作组附加到该规则

[英]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.

相关问题 如何使用 PowerShell 在 Azure 中创建新的警报规则? - How to create a new alert rule in Azure using PowerShell? Azure Log Analytics 工作区警报规则在使用 Azure powershell 禁用警报规则时给出错误网关错误 - Azure Log Analytics workspace alert rule giving bad gateway error while disabling alert rule using Azure powershell 特定时间的 Log Analytics 警报规则 - Log Analytics alert rule at specific time 使用ARM模板成功创建了Azure日志警报规则,但未出现在门户中 - Azure log alert rule created successfully with ARM template but not appearing in portal 在OMS中的Log Analytics中创建警报规则时出错 - Getting error while creating Alert rule in Log Analytics in OMS 如何使用Azure API检索“日志搜索”警报规则 - How to retrieve a “Log Search” alert rule using the Azure API 警报规则定价混乱 - Alert rule pricing confusion 使用 PowerShell 在 Azure 应用程序中创建多个委托权限? - Create more than one delegated permission in Azure application with PowerShell? azure 监控操作规则创建失败,通过 CLI 使用规则类型 ActionGroup - azure monitor action rule create fails with rule type ActionGroup via CLI 禁用具有空 TargetResourceRegion 的警报规则 - Disable alert rule with empty TargetResourceRegion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM