【问题标题】:How can I query "Azure Status" using powershell如何使用 powershell 查询“Azure 状态”
【发布时间】:2019-05-02 12:58:58
【问题描述】:

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

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

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

【问题讨论】:

    标签: azure azure-powershell


    【解决方案1】:

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

    正如link 所说,

    资源运行状况提供的信息比 Azure 状态或服务运行状况仪表板提供的信息更具体。

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

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

    示例

    $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
    

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

    如果你不想要这种方式,你也可以使用 azure ad client credential flow 来生成访问令牌。这是sample,你可以参考一下。不要忘记将$ARMResource 更改为https://management.azure.com/

    【讨论】:

      【解决方案2】:

      我们需要检查 VPN 网关状态并触发电子邮件,我可以使用 runbook 来处理 powershell,现在他们要求我检查 azure 区域状态,如果区域已启动并正在运行,然后触发 runbook 是否有使用逻辑应用的方法,有人建议使用逻辑应用。

      谢谢 瓦苏瓦雷迪

      【讨论】:

        【解决方案3】:

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

        如果在响应中找到任何名为 &lt;item&gt; 的子节点,这将返回 true。如果需要,只需遍历&lt;item&gt; 并返回titledescription。如果没有&lt;item&gt;,则所有服务都已启动,函数返回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>
        

        是的,这太可怕了,是的,应该有一种更简单的方法来做到这一点,该提要端点也没有 CORS 支持,因此您无法从单页应用程序中执行此操作。 PowerShell 应该没问题。

        示例实现(虽然它持续存在,但 .wtf 域花费不菲,谁知道)-

        http://isazuredown.wtf/

        这里有一个 Python 实现 -
        https://github.com/snobu/azure-ticker

        【讨论】:

          猜你喜欢
          • 2019-02-02
          • 1970-01-01
          • 2014-07-14
          • 1970-01-01
          • 1970-01-01
          • 2018-03-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多