如何使用Powershell查询“ Azure状态”

时间:2019-05-02 12:58:59

标签: azure azure-powershell

如何使用PowerShell查询“ Azure状态”?

Chrome's stop sharing button

我们有一个自动化逻辑,我们想通过检查Azure服务是否出现中断来进行即兴发挥。如果没有中断,请继续自动化。

3 个答案:

答案 0 :(得分:1)

AFAIK,没有PowerShell或Rest API可以获取Azure状态。我能找到的最接近的是获得资源运行状况。

正如link所说,

  

Resource Health提供的信息比Azure状态或Service Health仪表板提供的信息更具体。

     

Azure状态和服务运行状况仪表板会通知您有关影响广泛客户(例如Azure区域)的服务问题,而资源运行状况会公开仅与特定资源相关的更详细的事件。例如,如果主机意外重启,则资源运行状况仅警报那些虚拟机正在该主机上运行的客户。

此外,也没有内置的Powershell来获取资源运行状况。如果您想通过powershell来获取它,可以尝试通过Availability Statuses - List By Subscription Id调用其余的api Invoke-RestMethod

示例

$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

enter image description here

要在上面的命令中获得$accesstoken,最简单的方法是单击doc中的Try it按钮,登录并复制令牌。

enter image description here

如果您不希望这样做,还可以使用Azure广告client credential flow生成访问令牌。这是sample,您可以参考它。不要忘记将$ARMResource更改为https://management.azure.com/

enter image description here

答案 1 :(得分:0)

我们有一个要求检查VPN网关状态并触发电子邮件,我能够使用Runbook使用Powershell进行操作,现在他们要求我检查Azure区域状态(如果区域已启动并正在运行),然后触发Runbook是否存在使用逻辑应用程序的一种方法,有人建议使用逻辑应用程序。

谢谢 vasudeva reddy

答案 2 :(得分:0)

在JavaScript中(易于PowerShell):

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;
}

如果在响应中找到任何名为<item>的子节点,则返回true。只需遍历<item>,然后返回titledescription(如果需要)。如果没有<item>,则所有服务都已启动,该函数返回false。

这是一次事件发生时从该提要中捕获的内容-

<?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>

这是一个一切都很棒一个-

<?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>

是的,这太可怕了,是的,应该有一种更简单的方法来执行此操作,并且该Feed终结点也没有CORS支持,因此您不能从单个页面应用程序中执行此操作。 PowerShell应该没问题。

示例实现(虽然持续了,但.wtf域花了一笔小钱,谁知道)-

http://isazuredown.wtf/

此处是Python实现-
https://github.com/snobu/azure-ticker

相关问题