Skip to content

Instantly share code, notes, and snippets.

@tbaschak
Last active January 13, 2018 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbaschak/3f98a390b60ea938c86a730ab8ab369f to your computer and use it in GitHub Desktop.
Save tbaschak/3f98a390b60ea938c86a730ab8ab369f to your computer and use it in GitHub Desktop.
a simple python script to check/warn on Github's status via their API.
#!/usr/bin/env python2.7
from urllib2 import Request, urlopen, URLError
# for Python3 use the following:
# from urllib.request import Request, urlopen
# from urllib.error import URLError
import sys
import json
STATUS_URL = "https://status.github.com/api/status.json"
MESSAGE_URL = "https://status.github.com/api/last-message.json"
req = Request(STATUS_URL)
try:
response = urlopen(req)
except URLError as e:
if hasattr(e, 'reason'):
print('Github check is WARNING: ', e.reason)
sys.exit(3)
elif hasattr(e, 'code'):
print('Github check is WARNING: ', e.code)
sys.exit(3)
else:
# everything is fine
data = json.load(response)
status = data['status']
last_updated = data['last_updated']
req = Request(MESSAGE_URL)
try:
response = urlopen(req)
except URLError as e:
if hasattr(e, 'reason'):
print('Github check is WARNING: ', e.reason)
sys.exit(1)
elif hasattr(e, 'code'):
print('Github check is WARNING: ', e.code)
sys.exit(1)
else:
# everything is fine
data = json.load(response)
body = data['body']
#Determine state to pass to Nagios
#CRITICAL = 2
#WARNING = 1
#OK = 0
if status == 'major':
print("Github is CRITICAL (%s): %s (%s)" % (status, body, last_updated))
sys.exit(2)
elif status == 'minor':
print("Github is WARNING (%s): %s (%s)" % (status, body, last_updated))
sys.exit(1)
elif status == 'good':
print("Github is OK (%s): %s (%s)" % (status, status, last_updated))
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment