A Python script that crawls RSS in Azure Status and posts it to Hipchat

Overview

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.

Tried to make it

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.

azure.png

Summary

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

A Python script that crawls RSS in Azure Status and posts it to Hipchat
A memorandum to run a python script in a bat file
What's in that variable (when running a Python script)
A module that makes it easier to write Perl-like filter programs in Python fileinput
Script to count and stop up to 5 seconds in Python in Blender
Try to make it using GUI and PyQt in Python
Temporarily save a Python object and reuse it in another Python
A Python script that saves a clipboard (GTK) image to a file.
Let's create a script that registers with Ideone.com in Python.
A standard way to develop and distribute packages in Python
Create code that outputs "A and pretending B" in python
Object-oriented in C: Refactored "○ ✕ game" and ported it to Python
How to write a metaclass that supports both python2 and python3
A set of script files that do wordcloud in Python3
Just try to receive a webhook in ngrok and python
A python script that converts Oracle Database data to csv
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
A story that makes it easy to estimate the living area using Elasticsearch and Python
Recursively get the Excel list in a specific folder with python and write it to Excel.
A Python script that allows you to check the status of the server from your browser
An easy way to view the time taken in Python and a smarter way to improve it
processing to use notMNIST data in Python (and tried to classify it)
How to install OpenCV on Cloud9 and run it in Python
Write a script in Shell and Python to notify you in Slack when the process is finished
How to pass arguments to a Python script in SPSS Modeler Batch
Regular expressions that are easy and solid to learn in Python
Read big endian binary in Python and convert it to ndarray
I wrote a function to load a Git extension script in Python
I wrote a script to extract a web page link in Python
I want to create a pipfile and reflect it in docker
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
A script that returns 0, 1 attached to the first Python prime number
A quick guide to PyFlink that combines Apache Flink and Python
A python script that deletes ._DS_Store and ._ * files created on Mac
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
I made a POST script to create an issue on Github and register it in the Project
A script that retrieves tweets with Python, saves them in an external file, and performs morphological analysis.
[Python] How to save the installed package and install it in a new environment at once Mac environment
How to input a character string in Python and output it as it is or in the opposite direction.
I made a web application in Python that converts Markdown to HTML
I made a Discord bot in Python that translates when it reacts
How to put a half-width space before letters and numbers in Python.
Connect to postgreSQL from Python and use stored procedures in a loop.
How to make a container name a subdomain and make it accessible in Docker
I tried to develop a Formatter that outputs Python logs in JSON
A python program that resizes a video and turns it into an image
I made a script in python to convert .md files to Scrapbox format
How to stop a program in python until a specific date and time
Pin current directory to script directory in Python
Sample script to trap signals in Python
Run the Python interpreter in a script
How to get a stacktrace in python
How to use is and == in Python
How to run a Maya Python script
How to generate a QR code and barcode in Python and read it normally or in real time with OpenCV
A Python program that checks if any content has been updated and git commits & pushes it to GitLab if it has been updated.
Note that cibuildwheel builds python bwheel (including C ++ module) in bulk with CI and uploads it to PyPI
I made a system that automatically decides whether to run tomorrow with Python and adds it to Google Calendar.
[Python] I made a script that automatically cuts and pastes files on a local PC to an external SSD.
Reinforcement learning 35 python Local development, paste a link to myModule and import it.
A solution to the problem that the Python version in Conda cannot be changed