{"id":7595,"date":"2017-04-06T14:44:00","date_gmt":"2017-04-06T14:44:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/?p=7595"},"modified":"2019-03-05T15:25:07","modified_gmt":"2019-03-05T22:25:07","slug":"how-to-use-azure-resource-health-api-to-gain-visibility-into-the-health-of-a-vm-web-app-or-sql-database","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/how-to-use-azure-resource-health-api-to-gain-visibility-into-the-health-of-a-vm-web-app-or-sql-database\/","title":{"rendered":"How to use Azure Resource Health API to gain visibility into the health of a VM, Web App or SQL Database"},"content":{"rendered":"<p>In this post, Principal Application Development Manager, <a href=\"https:\/\/www.linkedin.com\/in\/rickcaudle\/\">Rick Caudle<\/a>, demonstrates how to use Azure Resource Health API to query the health of Azure services.<\/p>\n<hr \/>\n<p>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!\u00a0 I mean, what developer wouldn&#8217;t like this?\u00a0 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).<\/p>\n<p>Azure Resource Health is also exposed to you via the Azure Portal via the Resource Health Blade, you can check <a href=\"https:\/\/portal.azure.com\/#blade\/Microsoft_Azure_Support\/ResourceBlade\">here<\/a> to quickly navigate to the blade within one of your subscriptions.\u00a0 Please read the <a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/reduce-troubleshooting-time-with-azure-resource-health\/\">post<\/a> by Bernardo Mu\u00f1oz for a full description of Azure Resource Health.<\/p>\n<p>Let&#8217;s get right into it.<\/p>\n<h3><b>Important notes about using the Azure Resource Health API<\/b><\/h3>\n<p>In Bernardo\u2019s post, he assumes you are familiar with using the ARM API, how to authenticate, etc.\u00a0 I won&#8217;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 &amp; GET using the URL\u2019s he outlined is all that is needed, when in fact, there are things that need to be done before using those REST endpoints.<\/p>\n<p>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).<\/p>\n<h3>Using the API to check the Health of a VM<\/h3>\n<ol>\n<li>First, install the ARMClient tool by following the procedure outlined in the following <a href=\"http:\/\/blog.davidebbo.com\/2015\/01\/azure-resource-manager-client.html\">post<\/a>.\u00a0 If you wish to use a different approach to install the tool that is fine as well.\u00a0 <b>Side note:<\/b> I have to agree with David Ebbo if you don&#8217;t have <a href=\"https:\/\/chocolatey.org\/\">Chocolatey<\/a> installed, you are missing out!<\/li>\n<li>Next thing we need is the subscription ID of where the resource exists.\u00a0 You can click <a href=\"https:\/\/ms.portal.azure.com\/#blade\/Microsoft_Azure_Billing\/SubscriptionsBlade\">here<\/a> to navigate to the subscription blade to pull the subscription ID.<\/li>\n<li>Authenticate to Azure (2 ways to do this): 1- use manual approach or 2- Use a Service Principal &#8211; see following <a href=\"http:\/\/blog.davidebbo.com\/2014\/12\/azure-service-principal.html\">post<\/a> on what it is and how to create one.\u00a0 For this example, I am going to leverage the Login feature of the ARMClient\n<ol>\n<li>Open a Command Prompt and run the following ARMClient command from a Command Prompt: ARMClient Login\nThe following dialog box will appear asking you to log into Azure:\n<img decoding=\"async\" class=\"alignnone size-full wp-image-35815\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health1.jpg\" alt=\"\" width=\"644\" height=\"463\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health1.jpg 644w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health1-300x216.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/>\nEnter your credentials and sign in.<\/li>\n<\/ol>\n<\/li>\n<li>In the Command Window you will see the following type of welcome output from the ARM Client after entering your credentials:\n<img decoding=\"async\" class=\"alignnone size-full wp-image-35816\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health2.jpg\" alt=\"\" width=\"644\" height=\"90\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health2.jpg 644w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health2-300x42.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/>\nThis 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 <a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/reduce-troubleshooting-time-with-azure-resource-health\/\">post<\/a>.<\/li>\n<li>Let&#8217;s use the ARMClient to run three different types of GET requests. Please note that you will need to replace <b>&lt;subid&gt;, &lt;ResourceGroupName&gt; <\/b>with the subscription ID and resource group name you are pulling the results from.<\/li>\n<\/ol>\n<h3><b>GET the Health of all the resources in a subscription:<\/b><\/h3>\n<p>Run the following command from the Command Prompt making sure to replace <b>&lt;SubID&gt; <\/b>with the <b>SubID <\/b>you collected in the earlier step.<\/p>\n<pre>ARMClient GET armclient GET \/subscriptions\/<strong>&lt;SubID&gt;<\/strong>\/providers\/Microsoft.ResourceHealth\/availabilityStatuses?api-version=2015-01-01\r\n\r\n<\/pre>\n<p><b>Results:\n<img decoding=\"async\" class=\"alignnone size-full wp-image-35818\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health3.jpg\" alt=\"\" width=\"644\" height=\"290\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health3.jpg 644w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health3-300x135.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/>\n<\/b>\u00a0<span style=\"font-weight: bold;\">GET Health of all the resources in a resource group:<\/span><\/p>\n<p><b>Example:\n<\/b><\/p>\n<pre>ARMClient GET \/subscriptions\/<strong>&lt;SubID&gt;\/<\/strong>resourceGroups\/<strong>&lt;ResourceGroupName&gt;<\/strong>\/providers\/Microsoft.ResourceHealth\/availabilityStatuses?api-version=2015-01-01<\/pre>\n<p><b>Results:<\/b>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-35819\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health4.jpg\" alt=\"\" width=\"644\" height=\"329\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health4.jpg 644w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health4-300x153.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/p>\n<h3><span style=\"font-weight: bold;\">GET Health of a single resource<\/span><\/h3>\n<p>The following example checks the health of a VM deployed as a classic VM.\u00a0 If you have a VM deployed under ARM, you would use the Microsoft.Compute provider.\u00a0 For more details on the various providers you can read the following <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-resource-manager\/resource-manager-supported-services\">post<\/a> or you can click <a href=\"https:\/\/portal.azure.com?flight=1#blade\/HubsExtension\/ResourceMenuBlade\/resourceproviders\/id\/%2Fsubscriptions%2F0f10767b-d7c8-47a5-8287-b26227ccad2a\/referrerInfo\/%2Fsubscriptions%2F0f10767b-d7c8-47a5-8287-b26227ccad2a\">here<\/a> to open resource provider blade in the portal.\n<b>Example:\n<\/b><\/p>\n<pre>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<\/pre>\n<p><b>Result:\n<\/b><img decoding=\"async\" class=\"alignnone size-full wp-image-35820\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health5.jpg\" alt=\"\" width=\"644\" height=\"324\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health5.jpg 644w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2017\/04\/health5-300x151.jpg 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/31\/2019\/04\/clip_image010.jpg\">\n<\/a><\/p>\n<p>That does it for this post.\u00a0 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.<\/p>\n<hr \/>\n<p><strong><a href=\"https:\/\/devblogs.microsoft.com\/premier-developer\/welcome-to-premier-developer\/\">Premier Support for Developers<\/a><\/strong> provides strategic technology guidance, critical support coverage, and a range of essential services to help teams optimize development lifecycles and improve software quality.\u00a0 Contact your Application Development Manager (ADM) or <a href=\"https:\/\/blogs.msdn.microsoft.com\/premier_developer\/contact-us\/\">email us<\/a> to learn more about what we can do for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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!\u00a0 I [&hellip;]<\/p>\n","protected":false},"author":582,"featured_media":37840,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25],"tags":[24,3],"class_list":["post-7595","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","tag-azure","tag-team"],"acf":[],"blog_post_summary":"<p>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!\u00a0 I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/7595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=7595"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/7595\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/37840"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=7595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=7595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=7595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}