I want to check the health status of Azure itself from Azure status to monitor services in Azure. However, push notifications don't tell me, so I made a request to crawl RSS and notify Hipchat.
I heard that feed parser is good for reading RSS with python, so I will use it. hipchat just hits rest api using token in room. For various reasons, access is via proxy, so I set it up a bit.
azure_status_notificator.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import urllib2
import feedparser
proxies = {
"http": "hoge:8080",
"https": "hoge:8080",
}
def hipchat_post_to_room(room_id, auth_token, msg):
global proxies
data = {
"color": "red",
"message_format": "text",
"message": msg,
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
request_url = "https://api.hipchat.com/v2/room/" + room_id + "/notification?auth_token=" + auth_token
return requests.post(request_url, proxies=proxies, data=json.dumps(data), headers=headers)
def get_azure_status():
global proxies
proxy = urllib2.ProxyHandler(proxies)
data = feedparser.parse("http://azure.microsoft.com/ja-jp/status/feed/", handlers = [proxy])
res = ""
for e in data["entries"]:
if e:
res += e.summary_detail.value
return res
if __name__ == "__main__":
status = get_azure_status()
room_id = "XXXXXX"
auth_token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
if status:
msg = "@all %s" % status
hipchat_post_to_room(room_id, auth_token, msg)
If there is nothing, make an if statement so that you will not be notified.
By the way, hipchat can also be posted in html format, but be aware that @all and mentions will not work if that is the case.
When I notified Hipchat, I thought it would be convenient to open it as soon as there is a link in Azure status, but if I do that, the format is different So I need to post it twice.
After that, cron the created script every hour.
00 * * * * python /home/hoge/azure_status_notificator.py
did it.
Since RSS is usually viewed only from feedly or readers, it was a good opportunity to know what kind of data n structure the feed actually flows. It's hard to verify if the feed isn't actually flowing because it's like an RSS schema.
Also, when using the cloud, did I accidentally drop only my own instance? Or it is a failure of Azure itself, it is necessary to isolate and consider it.
By the way, Azure support plan is appropriate, so there is talk of "pay money", but Expecting full support, the price is reasonable.
I wondered if I should limit it to the services I use or AZ.
Recommended Posts