Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Add-AzMetricAlertRuleV2

Adds or updates a V2 (non-classic) metric-based alert rule.

Syntax

CreateAlertByResourceId (Default)

Add-AzMetricAlertRuleV2
 -Name <String>
 -ResourceGroupName <String>
 -WindowSize <TimeSpan>
 -Frequency <TimeSpan>
 -TargetResourceId <String>
 -Condition <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.IPSMultiMetricCriteria]>
 -Severity <Int32>
 [-AutoMitigate <Boolean>]
 [-ActionGroup <ActivityLogAlertActionGroup[]>]
 [-ActionGroupId <String[]>]
 [-DisableRule]
 [-Description <String>]
 [-DefaultProfile <IAzureContextContainer>]
 [-WhatIf]
 [-Confirm]
 [<CommonParameters>]

CreateAlertByScopes

Add-AzMetricAlertRuleV2
 -Name <String>
 -ResourceGroupName <String>
 -WindowSize <TimeSpan>
 -Frequency <TimeSpan>
 -TargetResourceScope <String[]>
 -Condition <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Insights.OutputClasses.IPSMultiMetricCriteria]>
 -Severity <Int32>
 [-TargetResourceType <String>]
 [-TargetResourceRegion <String>]
 [-AutoMitigate <Boolean>]
 [-ActionGroup <ActivityLogAlertActionGroup[]>]
 [-ActionGroupId <String[]>]
 [-DisableRule]
 [-Description <String>]
 [-DefaultProfile <IAzureContextContainer>]
 [-WhatIf]
 [-Confirm]
 [<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.

Examples

Example 1: Add a metric alert rule to a virtual machine

$act = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo")
Add-AzMetricAlertRuleV2 -Name PS3182019 -ResourceGroupName xxxxRG -WindowSize 0:5 -Frequency 0:5 -TargetResourceScope "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM1", "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM2" -TargetResourceType "Microsoft.Compute/virtualMachines" -TargetResourceRegion "eastus" -Description "This is description" -Severity 4 -ActionGroup $act -Condition $condition
Description : This is description
Severity : 4
Enabled : True
Scopes : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM1,
 /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/012345/providers/Microsoft.Compute/virtualMachines/VM2}
EvaluationFrequency : 00:05:00
WindowSize : 00:05:00
TargetResourceType : Microsoft.Compute/virtualMachines
TargetResourceRegion : eastus
Criteria : Microsoft.Azure.Management.Monitor.Models.MetricAlertMultipleResourceMultipleMetricCriteria
AutoMitigate :
Actions : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo}
LastUpdatedTime :
Id : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/xxxxRG/providers/Microsoft.Insights/metricAlerts/PS3182019
Name : PS3182019
Type : Microsoft.Insights/metricAlerts
Location : global
Tags :

This command creates a metric alert rule for a virtual machine. $condition is the output of New-AzMetricAlertRuleV2Criteria cmdlet

Example 2: Add a metric alert rule for all virtual machines in a subscription

$act = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo")
Add-AzMetricAlertRuleV2 -Name AllVM -ResourceGroupName xxxxRG -WindowSize 0:5 -Frequency 0:5 -TargetResourceScope "/subscriptions/00000000-0000-0000-0000-0000000" -TargetResourceType "Microsoft.Compute/virtualMachines" -TargetResourceRegion "eastus" -Description "This is description" -Severity 4 -ActionGroup $act -Condition $condition
Description : This is description
Severity : 4
Enabled : True
Scopes : {/subscriptions/00000000-0000-0000-0000-0000000}
EvaluationFrequency : 00:05:00
WindowSize : 00:05:00
TargetResourceType : Microsoft.Compute/virtualMachines
TargetResourceRegion : eastus
Criteria : Microsoft.Azure.Management.Monitor.Models.MetricAlertMultipleResourceMultipleMetricCriteria
AutoMitigate :
Actions : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo}
LastUpdatedTime :
Id : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/xxxxRG/providers/Microsoft.Insights/metricAlerts/AllVM
Name : AllVM
Type : Microsoft.Insights/metricAlerts
Location : global
Tags :

This command creates a metric alert rule for all virtual machines in the subscription that are in eastus

Example 3: Disable a metric alert rule

Get-AzMetricAlertRuleV2 -ResourceGroupName alertstest -Name TestAlertRule | Add-AzMetricAlertRuleV2 -DisableRule
Description : This new Metric alert rule was created from Powershell version: 1.0.1
Severity : 4
Enabled : False
Scopes : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction}
EvaluationFrequency : 00:05:00
WindowSize : 00:05:00
TargetResourceType :
TargetResourceRegion :
Criteria : Microsoft.Azure.Management.Monitor.Models.MetricAlertSingleResourceMultipleMetricCriteria
AutoMitigate :
Actions : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/demo1}
LastUpdatedTime :
Id : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/metricAlerts/TestAlertRule
Name : TestAlertRule
Type : Microsoft.Insights/metricAlerts
Location : global
Tags :

This command disables a metric alert rule. Here, we are piping output of Get-AzMetricAlertRuleV2 to Add-AzMetricAlertRuleV2

Example 4: Add a metric alert rule with dimensions

$act = [Microsoft.Azure.Management.Monitor.Management.Models.ActivityLogAlertActionGroup]::New("/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo")
$dim1 = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "availabilityResult/name" -ValuesToInclude "gdtest"
$dim2 = New-AzMetricAlertRuleV2DimensionSelection -DimensionName "availabilityResult/location" -ValuesToInclude "*"
$criteria = New-AzMetricAlertRuleV2Criteria -MetricName "availabilityResults/availabilityPercentage" -DimensionSelection $dim1,$dim2 -TimeAggregation Average -Operator GreaterThan -Threshold 2
Add-AzMetricAlertRuleV2 -Name AlertWithDim -ResourceGroupName alertstest -WindowSize 00:05:00 -Frequency 00:05:00 -TargetResourceId "/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction" -Condition $criteria -ActionGroup $act -DisableRule -Severity 4
Description : This new Metric alert rule was created from Powershell version: 1.0.0
Severity : 4
Enabled : False
Scopes : {/subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/components/alertstestFunction}
EvaluationFrequency : 00:05:00
WindowSize : 00:05:00
TargetResourceType :
TargetResourceRegion :
Criteria : Microsoft.Azure.Management.Monitor.Models.MetricAlertSingleResourceMultipleMetricCriteria
AutoMitigate :
Actions : {/subscriptions/00000000-0000-0000-0000-0000000/resourcegroups/default-activitylogalerts/providers/Microsoft.Insights/actiongroups/actionGroupDemo}
LastUpdatedTime :
Id : /subscriptions/00000000-0000-0000-0000-0000000/resourceGroups/alertstest/providers/Microsoft.Insights/metricAlerts/AlertWithDim
Name : AlertWithDim
Type : Microsoft.Insights/metricAlerts
Location : global
Tags :

To create a more complex metric alert rule like the ones that involve selecting dimension values or have multiple criteria, you can use the helper cmdlets New-AzMetricAlertRuleV2DimensionSelection and New-AzMetricAlertRuleV2Criteria.

Above set of cmdlets will create a metric alert rule with dimensions.

Parameters

-ActionGroup

The Action Group for rule

Parameter properties

Type:

ActivityLogAlertActionGroup[]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:Actions

Parameter sets

-ActionGroupId

The Action Group id for rule

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-AutoMitigate

The flag that indicates whether the alert should be auto resolved or not

Parameter properties

Type:Boolean
Default value:True
Supports wildcards:False
DontShow:False

Parameter sets

-Condition

The condition for rule

Parameter properties

Type:

List<T>[IPSMultiMetricCriteria]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:Criteria

Parameter sets

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

-Description

The description of the metric alert rule

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-DisableRule

The disable rule (status) flag

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-Frequency

The evaluation frequency for rule

Parameter properties

Type:TimeSpan
Default value:None
Supports wildcards:False
DontShow:False
Aliases:EvaluationFrequency

Parameter sets

-Name

The name of metric alert rule

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-ResourceGroupName

The Resource Group Name

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:ResourceGroup

Parameter sets

-Severity

The severity for the metric alert rule

Parameter properties

Type:Int32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-TargetResourceId

The target resource id for rule

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-TargetResourceRegion

The target resource region for rule

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-TargetResourceScope

The target resource scope for rule

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:Scopes

Parameter sets

-TargetResourceType

The target resource type for rule

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

-WindowSize

The window size for rule

Parameter properties

Type:TimeSpan
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

TimeSpan

String

List<T>

Microsoft.Azure.Management.Monitor.Models.ActivityLogAlertActionGroup

SwitchParameter

Int32

Outputs

PSMetricAlertRuleV2


Feedback

Was this page helpful?