az monitor alert

Commands to manage metric-based alert rules.

Commands

az monitor alert create Create a 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 Show details of an alert rule incident.
az monitor alert update Update a metric-based alert rule.

az monitor alert create

Create a metric-based alert rule.

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

Examples

Create a High CPU-based alert on a VM with no actions.

az vm alert rule create -n rule1 -g  --target  --condition "Percentage CPU > 90 avg 5m"

Create a High CPU-based alert on a VM with email and webhook actions.

az vm alert rule create -n rule1 -g  --target      --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= type=HighCPU

Required Parameters

--condition

The condition expression upon which to trigger the rule.

Usage: --condition "METRIC {>,>=,<,<=} THRESHOLD {avg,min,max,total,last} PERIOD" Example: --condition "Percentage CPU > 60 avg 1h30m".

--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=.

--target

Name or ID of the target resource.

Optional Parameters

--action -a

Add an action to fire when the alert is triggered.

Usage: --action TYPE KEY [ARG ...]

                                Email:   --action email bob@contoso.comann@contoso.com

                                Webhook: --action webhook <a href="https://www.contoso.com/alert">https://www.contoso.com/alert</a> apiKey=value

                                Webhook: --action webhook <a href="https://www.contoso.com/alert?apiKey=value">https://www.contoso.com/alert?apiKey=value</a>

                                To specify multiple actions, add multiple --add-action ARGS entries.
--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. You can configure the default location using az configure --defaults location=.

--tags

Space separated tags in 'key[=value]' format. 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 --name
--resource-group

Required Parameters

--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=.

az monitor alert list

List alert rules in a resource group.

az monitor alert list --resource-group

Required Parameters

--resource-group -g

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

az monitor alert list-incidents

List all incidents for an alert rule.

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

Required Parameters

--resource-group -g

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

--rule-name

Name of the alert rule.

az monitor alert show

Show an alert rule.

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

Required Parameters

--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=.

az monitor alert show-incident

Show details of an alert rule incident.

az monitor alert show-incident --name
--resource-group
--rule-name

Required Parameters

--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=.

--rule-name

Name of the alert rule.

az monitor alert update

To specify the condition: --condition METRIC {>,>=,<,<=} THRESHOLD {avg,min,max,total,last} PERIOD.

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

Required Parameters

--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=.

Optional Parameters

--add

Add an object to a list of objects by specifying a path and key value pairs. Example: --add property.listProperty .

--add-action -a

Add an action to fire when the alert is triggered.

Usage: --add-action TYPE KEY [ARG ...]

                                Email:   --add-action email bob@contoso.comann@contoso.com

                                Webhook: --add-action webhook <a href="https://www.contoso.com/alert">https://www.contoso.com/alert</a> apiKey=value

                                Webhook: --add-action webhook <a href="https://www.contoso.com/alert?apiKey=value">https://www.contoso.com/alert?apiKey=value</a>

                                To specify multiple actions, add multiple --add-action ARGS entries.
--aggregation

Type of aggregation to apply based on --period.

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

The condition expression upon which to trigger the rule.

Usage: --condition "METRIC {>,>=,<,<=} THRESHOLD {avg,min,max,total,last} PERIOD" Example: --condition "Percentage CPU > 60 avg 1h30m".

--description

Free-text description of the rule.

--email-service-owners

Email the service owners if an alert is triggered.

accepted values: false, true
--enabled
--metric

Name of the metric to base the rule on.

value from: az monitor metrics list-definitions
--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.

Usage: --remove-action TYPE KEY [KEY ...]

                                Email:   --remove-action email bob@contoso.comann@contoso.com

                                Webhook: --remove-action webhook <a href="https://contoso.com/alert">https://contoso.com/alert</a> <a href="https://alerts.contoso.com">https://alerts.contoso.com</a>.
--set

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

--tags

Space separated tags in 'key[=value]' format. Use "" to clear existing tags.

--target

ID of the resource to target for the alert rule.

--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)').

--threshold

Numeric threshold at which to trigger the alert.