az monitor alert

Manage classic metric-based alert rules.

Commands

az monitor alert create

Create a classic metric-based alert rule.

az monitor alert delete

Delete an alert rule.

az monitor alert list

List alert rules in a resource group.

az monitor alert list-incidents

List all incidents for an alert rule.

az monitor alert show

Show an alert rule.

az monitor alert show-incident

Get the details of an alert rule incident.

az monitor alert update

Update a classic metric-based alert rule.

az monitor alert create

Create a classic metric-based alert rule.

az monitor alert create --condition
                        --name
                        --target
                        [--action]
                        [--description]
                        [--disabled {false, true}]
                        [--email-service-owners {false, true}]
                        [--location]
                        [--resource-group]
                        [--subscription]
                        [--tags]
                        [--target-namespace]
                        [--target-parent]
                        [--target-type]

Examples

Create a high CPU usage alert on a VM with no actions.

az monitor alert create -n rule1 -g {ResourceGroup} --target {VirtualMachineID} --condition "Percentage CPU > 90 avg 5m"

Create a high CPU usage alert on a VM with email and webhook actions.

az monitor alert create -n rule1 -g {ResourceGroup} --target {VirtualMachineID} \
    --condition "Percentage CPU > 90 avg 5m" \
    --action email bob@contoso.comann@contoso.com --email-service-owners \
    --action webhook https://www.contoso.com/alerts?type=HighCPU \
    --action webhook https://alerts.contoso.com apiKey={APIKey} type=HighCPU

Required Parameters

--condition

The condition which triggers the rule.

--name -n

Name of the alert rule.

--target

Name or ID of the target resource.

Optional Parameters

--action -a

Add an action to fire when the alert is triggered.

--description

Free-text description of the rule. Defaults to the condition expression.

--disabled

Create the rule in a disabled state.

accepted values: false, true
--email-service-owners

Email the service owners if an alert is triggered.

accepted values: false, true
--location -l

Location. Values from: az account list-locations. You can configure the default location using az configure --defaults location=<location>.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--target-namespace

Target resource provider namespace.

--target-parent

Target resource parent path, if applicable.

--target-type

Target resource type. Can also accept namespace/type format (Ex: 'Microsoft.Compute/virtualMachines').

az monitor alert delete

Delete an alert rule.

az monitor alert delete [--ids]
                        [--name]
                        [--resource-group]
                        [--subscription]

Examples

Delete an alert rule. (autogenerated)

az monitor alert delete --name MyAlertRule --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

Name of the alert rule.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor alert list

List alert rules in a resource group.

az monitor alert list --resource-group
                      [--query-examples]
                      [--subscription]

Examples

List alert rules in a resource group. (autogenerated)

az monitor alert list --resource-group MyResourceGroup

Required Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

Optional Parameters

--query-examples

Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor alert list-incidents

List all incidents for an alert rule.

az monitor alert list-incidents --resource-group
                                --rule-name
                                [--subscription]

Examples

List all incidents for an alert rule. (autogenerated)

az monitor alert list-incidents --resource-group MyResourceGroup --rule-name MyRule

Required Parameters

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--rule-name

Name of the alert rule.

Optional Parameters

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor alert show

Show an alert rule.

az monitor alert show [--ids]
                      [--name]
                      [--query-examples]
                      [--resource-group]
                      [--subscription]

Examples

Show an alert rule. (autogenerated)

az monitor alert show --name MyAlertRule --resource-group MyResourceGroup

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

Name of the alert rule.

--query-examples

Recommend JMESPath string for you. You can copy one of the query and paste it after --query parameter within double quotation marks to see the results. You can add one or more positional keywords so that we can give suggestions based on these key words.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor alert show-incident

Get the details of an alert rule incident.

az monitor alert show-incident [--ids]
                               [--name]
                               [--resource-group]
                               [--rule-name]
                               [--subscription]

Optional Parameters

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--name -n

The name of the incident to retrieve.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--rule-name

Name of the alert rule.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

az monitor alert update

Update a classic metric-based alert rule.

az monitor alert update [--add]
                        [--add-action]
                        [--aggregation {avg, last, max, min, total}]
                        [--condition]
                        [--description]
                        [--email-service-owners {false, true}]
                        [--enabled]
                        [--force-string]
                        [--ids]
                        [--metric]
                        [--name]
                        [--operator {<, <=, >, >=}]
                        [--period]
                        [--remove]
                        [--remove-action]
                        [--resource]
                        [--resource-group]
                        [--resource-namespace]
                        [--resource-parent]
                        [--resource-type]
                        [--set]
                        [--subscription]
                        [--tags]
                        [--threshold]

Examples

Update a classic metric-based alert rule. (autogenerated)

az monitor alert update --email-service-owners true --name MyAlertRule --resource-group MyResourceGroup

Update a classic metric-based alert rule. (autogenerated)

az monitor alert update --name MyAlertRule --remove-action email bob@contoso.com --resource-group MyResourceGroup

Update a classic metric-based alert rule. (autogenerated)

az monitor alert update --name MyAlertRule --resource-group MyResourceGroup --set retentionPolicy.days=365

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty <key=value, string or JSON string>.

--add-action -a

Add an action to fire when the alert is triggered.

--aggregation

Type of aggregation to apply based on --period.

accepted values: avg, last, max, min, total
--condition

The condition which triggers the rule.

--description

Description of the rule.

--email-service-owners

Email the service owners if an alert is triggered.

accepted values: false, true
--enabled
--force-string

When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.

--ids

One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

--metric

Name of the metric to base the rule on.

value from: az monitor metrics list-definitions
--name -n

Name of the alert rule.

--operator

How to compare the metric against the threshold.

accepted values: <, <=, >, >=
--period

Time span over which to apply --aggregation, in nDnHnMnS shorthand or full ISO8601 format.

--remove

Remove a property or an element from a list. Example: --remove property.list OR --remove propertyToRemove.

--remove-action -r

Remove one or more actions.

--resource

Name or ID of the target resource.

--resource-group -g

Name of resource group. You can configure the default group using az configure --defaults group=<name>.

--resource-namespace

Target resource provider namespace.

--resource-parent

Target resource parent path, if applicable.

--resource-type

Target resource type. Can also accept namespace/type format (Ex: 'Microsoft.Compute/virtualMachines').

--set

Update an object by specifying a property path and value to set. Example: --set property1.property2=.

--subscription

Name or ID of subscription. You can configure the default subscription using az account set -s NAME_OR_ID.

--tags

Space-separated tags: key[=value] [key[=value] ...]. Use "" to clear existing tags.

--threshold

Numeric threshold at which to trigger the alert.