How can I query “Azure Status” using powershell

99封情书 提交于 2019-12-11 03:38:19

问题


How can I query "Azure Status" using PowerShell?

https://azure.microsoft.com/en-in/status/

We have a automation logic in place, and we want to improvise by having a check that checks if the Azure service is having an outage. If there is no outage, then continue with the automation.


回答1:


AFAIK, there is no PowerShell or Rest API to get the Azure status. The closest I can find is to get the Resource Health.

As this link said,

The information provided by Resource Health is more specific than what is provided by Azure status or the Service Health dashboard.

Whereas Azure status and the Service Health dashboard inform you about service issues that affect a broad set of customers (for example an Azure region), Resource Health exposes more granular events that are relevant only to the specific resource. For example, if a host unexpectedly reboots, Resource Health alerts only those customers whose virtual machines were running on that host.

Also, there is also no built-in powershell to get the Resource Health. If you want to get it via powershell, you could try to call the rest api Availability Statuses - List By Subscription Id via Invoke-RestMethod.

Sample:

$url = "https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2015-01-01"
$accesstoken = "eyJ0eXAixxxxxxxxxxxxx4qPcZfMJNLGRLOMeIncWnFnKWA"
$header = @{
    'Authorization' = 'Bearer ' + $accesstoken
}

Invoke-RestMethod –Uri $url –Headers $header –Method GET | ConvertTo-Json

To get the $accesstoken in the command above, the easiest way is to click the Try it button in the doc, login and copy the token.

If you don't want this way, you can also use azure ad client credential flow to generate the access token. Here is a sample, you could refer to it. Don't forget to change the $ARMResource to https://management.azure.com/.




回答2:


We have a requirement to check VPN gateway status and trigger an email, that i am able to do with powershell using runbook and now they asked me to check azure region status if region is up and running then trigger the runbook is there any way to do with logic app, some one suggested to use logic app.

Thanks vasudeva reddy




回答3:


In JavaScript (easily PowerShellable):

const feedUrl = 'https://azure.microsoft.com/en-us/status/feed/';

async function isAzureDown() {
    // This is an OPTIONS call
    let response = await fetch(url, { 
        headers: { 'x-requested-with': 'xhr' }
    });
    // This is the GET
    let data = await response.text();
    ready = true;

    return data.search(/<item>/i) != -1 ? true : false;
}

This will return true if any child nodes called <item> are found in the response. Just foreach across <item> and return title and description if you need that. If there's no <item>, all services are up, the function returns false.

Here's a capture from that feed during an incident -

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:az="http://azure.com/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Azure Status</title>
    <link>https://status.azure.com</link>
    <atom:link href="https://status.azure.com" rel="self" type="application/rss+xml" />
    <description>Azure Status</description>
    <pubDate>Wed, 20 Jul 2016 23:48:45 GMT</pubDate>
    <item>
      <title>SQL Database -  East US - Advisory</title>
      <description>Starting at approximately 21:30 UTC on 20 Jul 2016 customers using SQL Database in East US may experience issues accessing services. New connections to existing databases in this region may result in an error or timeout, and existing connections may have been terminated. Engineers are currently investigating and the next update will be provided in 60 minutes or as events warrant.</description>
      <pubDate>Wed, 20 Jul 2016 23:02:32 GMT</pubDate>
      <link>http://status.azure.com</link>
      <category>SQL Database</category>
      <az:tags>
        <az:tag>East US</az:tag>
      </az:tags>
    </item>
  </channel>
</rss>

And here's an everything is awesome one -

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom"
  version="2.0">
  <channel xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <title>Azure Status</title>
    <link>https://azure.microsoft.com/en-us/status/</link>
    <description>Azure Status</description>
    <language>en-US</language>
    <lastBuildDate>Fri, 03 May 2019 08:55:00 Z</lastBuildDate>
  </channel>
</rss>

Yes this is horrible, yes there should be an easier way to do this, there's also no CORS support for that feed endpoint so you can't do it from a single page app. PowerShell should be fine.

Sample implementation (while it lasts, .wtf domains cost a small fortune, who knew) -

http://isazuredown.wtf/

A Python implementation here -
https://github.com/snobu/azure-ticker



来源:https://stackoverflow.com/questions/55953041/how-can-i-query-azure-status-using-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!