Reputation: 1511
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.
Upvotes: 3
Views: 6766
Reputation: 26414
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) -
A Python implementation here -
https://github.com/snobu/azure-ticker
Upvotes: 1
Reputation: 42133
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/
.
Upvotes: 1