How to use Azure Resource Health API to gain visibility into the health of a VM, Web App or SQL Database
In this post, Principal Application Development Manager, Rick Caudle, demonstrates how to use Azure Resource Health API to query the health of Azure services.
As a developer, I am always interested ways to gain deeper insight into the health of the resources that my solutions are deployed to, especially if an API is involved! I mean, what developer wouldn’t like this? Today, we are going to take a look at how to use the Azure Resource Health API to check the health status of a VM (you can also do this for other resources).
Azure Resource Health is also exposed to you via the Azure Portal via the Resource Health Blade, you can check here to quickly navigate to the blade within one of your subscriptions. Please read the post by Bernardo Muñoz for a full description of Azure Resource Health.
Let’s get right into it.
Important notes about using the Azure Resource Health API
In Bernardo’s post, he assumes you are familiar with using the ARM API, how to authenticate, etc. I won’t cover all that as there are several posts on these topics already, but I want to call out the fact that if you read his post and you have never used the ARM API, you may assume that a simple POST & GET using the URL’s he outlined is all that is needed, when in fact, there are things that need to be done before using those REST endpoints.
For this post, I use the ARMClient.exe to make things simple for the purpose of this example (in a future post, I will demonstrate how to do this from Automation and post results to a message queue).
Using the API to check the Health of a VM
- First, install the ARMClient tool by following the procedure outlined in the following post. If you wish to use a different approach to install the tool that is fine as well. Side note: I have to agree with David Ebbo if you don’t have Chocolatey installed, you are missing out!
- Next thing we need is the subscription ID of where the resource exists. You can click here to navigate to the subscription blade to pull the subscription ID.
- Authenticate to Azure (2 ways to do this): 1- use manual approach or 2- Use a Service Principal – see following post on what it is and how to create one. For this example, I am going to leverage the Login feature of the ARMClient
- In the Command Window you will see the following type of welcome output from the ARM Client after entering your credentials:
This response verifies that you have authenticated and it will list the tenant and subscription details associated with your account. At this point we can make use of the URLs that Bernardo outlines in his post.
- Let’s use the ARMClient to run three different types of GET requests. Please note that you will need to replace <subid>, <ResourceGroupName> with the subscription ID and resource group name you are pulling the results from.
GET the Health of all the resources in a subscription:
Run the following command from the Command Prompt making sure to replace <SubID> with the SubID you collected in the earlier step.
ARMClient GET armclient GET /subscriptions/<strong><SubID></strong>/providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2015-01-01
ARMClient GET /subscriptions/<strong><SubID>/</strong>resourceGroups/<strong><ResourceGroupName></strong>/providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2015-01-01
GET Health of a single resource
The following example checks the health of a VM deployed as a classic VM. If you have a VM deployed under ARM, you would use the Microsoft.Compute provider. For more details on the various providers you can read the following post or you can click here to open resource provider blade in the portal.
ARMClient GET /subscriptions/0f10767b-d7c8-47a5-8287-b26227ccad2a/resourceGroups/VS2015DevRDC/providers/Microsoft.ClassicCompute/virtualMachines/VS2015DevRDC/providers/Microsoft.ResourceHealth/availabilityStatuses/current?api-version=2015-01-0
That does it for this post. Stay tuned and for my next post I will likely dive into how to do this from Azure Automation, PowerShell, or something else that would be fun to play with.
Premier Support for Developers provides strategic technology guidance, critical support coverage, and a range of essential services to help teams optimize development lifecycles and improve software quality. Contact your Application Development Manager (ADM) or email us to learn more about what we can do for you.