You can create a new alert rule using the the CLI, PowerShell, or an Azure Resource Manager template.
PrerequisitesTo create or edit an alert rule, you must have the following permissions:
You can create a new alert rule using the Azure CLI. The following code examples use Azure Cloud Shell. You can see the full list of the Azure CLI commands for Azure Monitor.
In the portal, select Cloud Shell. At the prompt, use these.
For example, to create a metric alert rule that monitors if average Percentage CPU on a virtual machine (VM) is greater than 90:
az monitor metrics alert create -n {nameofthealert} -g {ResourceGroup} --scopes {VirtualMachineResourceID} --condition "avg Percentage CPU > 90" --description {descriptionofthealert}
To create a metric alert rule using PowerShell, use the Add-AzMetricAlertRuleV2 cmdlet.
Note
When you create a metric alert on a single resource, the syntax uses the TargetResourceId
. When you create a metric alert on multiple resources, the syntax contains the TargetResourceScope
, TargetResourceType
, and TargetResourceRegion
.
To create a log search alert rule using PowerShell, use the New-AzScheduledQueryRule cmdlet.
To create an activity log alert rule using PowerShell, use the New-AzActivityLogAlert cmdlet.
You can use an Azure Resource Manager template (ARM template) to configure alert rules consistently in all of your environments.
Create a new resource, using the following resource types:
For metric alerts: Microsoft.Insights/metricAlerts
Note
Microsoft.OperationalInsights/workspaces
) are configured differently than other metric alerts. For more information, see Resource Template for Metric Alerts for Logs.ResourceId
of the target resource. If you're creating a metric alert for multiple resources, the template uses the scope
, TargetResourceType
, and TargetResourceRegion
for the target resources.For log search alerts: Microsoft.Insights/scheduledQueryRules
For activity log, service health, and resource health alerts: microsoft.Insights/activityLogAlerts
Copy one of the templates from these sample ARM templates.
Edit the template file to contain appropriate information for your alert, and save the file as <your-alert-template-file>.json.
Edit the corresponding parameters file to customize the alert, and save as <your-alert-template-file>.parameters.json.
Set the metricName
parameter, using one of the values in Azure Monitor supported metrics.
Deploy the template using PowerShell or the CLI.
Was this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4