In this article, we’ll learn how to create action groups and alert rules to automatically monitor our infrastructure and take automated actions based on certain conditions. The service that we’ll use for this tutorial is Azure Monitor.
Alerts in Azure Monitor act as a watchdog, constantly monitoring your infrastructure and application for potential problems. It alerts you before users experience any problems by sending you alerts when something is wrong with your system. This way, you can address the problem quickly and avoid affecting users.
How to Setup Action Groups
Action Groups are a set of actions that you specify to perform when an alert is raised. Once an alert is triggered, the associated Action Group is alerted, and the designated actions are carried out automatically. You can set up Action Groups to send alerts through email, SMS, or voice call or activate webhooks or Azure Functions. Additionally, you can create multiple Action Groups and link them with different Alert Rules to customize your response according to the type of alert.
1. In order to create an action group, you must go to the Azure Monitor service and select the Alerts section on the left side of your screen.
2. Select a subscription and resource group where you want to create the action group, then fill up the remaining required fields (*). When you’re done, click the “Next: Notifications” button.
3. In the notification type, you can select between:
- Email Azure Resource Manager Role – send an email to users who have been assigned to the Azure Resource Manager subscription-level roles.
- Email/SMS message/Push/Voice – send different types of notifications to the added recipients.
For this demo, we’ll use the latter and add the email of the recipient that will be notified by the action group.
4. Next configuration will be the action type:
- Automation runbook
- Azure Functions
- Event Hub
- ITSM
- Logic App
- Secure Webhook
- Webhook
The action type that we’ll select is the Automation Runbook, and it will perform the runbook of scaling up virtual machines. Take note that you also need to create an automation account to add and configure the runbook.
5. Before you create an action group, go over all of the information you’ve entered. If there is any typo or incorrect information, you can click the Previous button beside the Create button.
6. It will take a few minutes to create the action group, but once the status is Enabled, you can test it out by clicking the button “Test action group”. The created action group can be selected when configuring alert rules.
7. When you create an action group with an email notification, the added email address will be notified.
How to Setup Alert Rules
Alert Rules are criteria that you configure to generate an alert when specific conditions are met. These rules can be created from various data types, including metrics, logs, and activity logs. For instance, you can establish an Alert Rule that triggers an alert when the CPU usage of a VM surpasses a particular threshold. Once an alert is triggered, it can be directed to an Action Group that can take automated actions.
An alert rule combines the following:
- Resources to be monitored
- Signal or telemetry from the resource
- Conditions
1. To create an alert rule, go to the Azure Monitor service and select Alerts, then click Alert rules.
2. The first thing that you need to configure is the scope of the alert rule. In the image below, we just selected the subscription, but you can also select a resource.
3. Next thing that you need to set up is the signal source to trigger the alert rule. You can click the “See all signals” to display the various types of signal names. The selected status that you see in the image below is selected by default.
4. The action group that we created earlier can be applied to the alert rule. This will send an email notification to the added recipient.
5. In the Details tab, you need to add the resource group of the alert rule that will be created and also the alert rule name. The description is optional, but it’s always a good practice to include what type of alert rule you just created.
6. Once you’re done configuring the alert rule, click Review + create and wait a few minutes to see the created alert rule in the dashboard of Azure Monitor | Alerts.
Note: After you’ve finished configuring both action groups and alert rules, always delete the resources you won’t be using to avoid any charges to your account.