How do you monitor when a resource is unavailable? There are many tools and products that will do this, often with integrations into ticketing systems or alerting methods. Let's look at virtual machines and how we can post a message into Microsoft Teams, if they are down.
Instead of us having to define what a resource looks like when it is unavailable (what metrics, log events or network responses would occur), we're going to use Azure Resource Health.
Azure Resource Health captures events whether they are related to the platform (such as a problem with VMs in an affected region of an Azure incident) or if they are user initiated (like a shutdown request being initiated by a person, even if that's from inside the virtual machine's operating system and not via any action through the Azure Resource Manager).
It relies on signals from different Azure services to assess whether a resource is healthy (available) or not. The exact checks and signals depend on what the resource type is and not all resource types are supported. For a full list including the checks, visit Resource health types and checks.
So, if Resource Health is going to fire an event if a virtual machine is down, let's capture that and post the details into a message in a Microsoft Teams channel.
In essence, we're generating a monitoring alert from a Resource Health event, then sending that to an action group which calls a Logic App. The Logic App receives the alert as an http message and posts the relevant data as a Teams message.
Hold up, I thought we were going to create a monitoring alert? We are however setting up the logic app first makes the rest of the process a little easier.
{
"schemaId": "Microsoft.Insights/activityLogs",
"data": {
"status": "Activated",
"context": {
"activityLog": {
"channels": "Admin",
"correlationId": "7055f77b-bf9a-4c10-8985-12db6d9a3ddc",
"description": "…",
"eventSource": "ResourceHealth",
"eventTimestamp": "2018-04-03T22:44:43.7467716+00:00",
"eventDataId": "fedb3ebe-b6af-4920-adb7-10d43514db0f",
"level": "Critical",
"operationName": "Microsoft.Resourcehealth/healthevent/Activated/action",
"operationId": "e416ed3c-8874-4ec8-bc6b-54e3c92a24d4",
"properties": {
"title": "...",
"details": "...",
"currentHealthStatus": "Degraded",
"previousHealthStatus": "Available",
"type": "Downtime",
"cause": "PlatformInitiated"
},
"status": "Active",
"subscriptionId": "...",
"submissionTimestamp": "2018-04-03T22:44:50.8013523+00:00"
}
},
"properties": {}
}
}
ALERT: 'eventSource' The resource 'resourceId'. is currently 'currentHealthStatus' This was 'cause' Event timestamp: 'eventTimestamp'
You need to use the Dynamic content picker and search to find and select each of the elements above in the ' ' marks, so it looks more like this:
And when it posts, the resulting Teams message looks like this:
ALERT: ResourceHealth The resource /subscriptions/redactednumber/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/VMname is currently Unavailable This was UserInitiated Event timestamp: 2020-10-26T06:47:36.6975752+00:00
With the Expressions in logic app, you could get a little fancier by shrinking the resource name to just the VM name or changing the event timestamp to display in your preferred timezone.
Click Save and your logic app is done!
You'll find Resource health in the Service health blade of the Azure portal, or in the Support + troubleshooting section of a supported resource. Note: this one is a little tricky as you don't go to Azure Monitor to create it.
Now, remember how I said you don't go to Azure Monitor to create the resource health alert? Surprise! You do go to Azure Monitor alerts and choose Manage alert rules to now find this and any other resource health alerts you have already created. They'll also show up in the Azure monitor alert statistics.
Azure Resource Health is free service. For information on Logic Apps pricing, visit Pricing model for Azure Logic Apps and Logic Apps pricing.
Interested in capturing a Service Health alert or a metric alert instead? Or maybe posting to a different application or messaging platform? Check out the other examples at How to trigger complex actions with Azure Monitor alerts.
Want more information on monitoring virtual machines? Visit Monitoring Azure virtual machines with Azure Monitor.
You can even create resource health alerts using a template. Visit Configure resource health alerts using Resource Manager templates.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.