Created
August 26, 2013 06:02
-
-
Save hatak/6338442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import json | |
import urllib2 | |
import sys | |
EXIT_CODE = ('OK', 'WARNING', 'CRITICAL', 'UNKNOWN') | |
GH_API_ROOT='https://status.github.com/api.json' | |
GH_STATUS = ('good', 'minor', 'major') | |
def main(args): | |
msg = _get_message() | |
if msg['status'] is None: | |
print 'UNKNOWN: %s' % msg['body'] | |
sys.exit(EXIT_CODE.index('UNKNOWN')) | |
code = GH_STATUS.index(msg['status']) | |
print '%s: %s (%s)' % (EXIT_CODE[code], msg['body'], msg['created_on']) | |
sys.exit(code) | |
def _get_message(): | |
message = {} | |
api_json = urllib2.urlopen(GH_API_ROOT) | |
api = json.load(api_json) | |
if api['last_message_url']: | |
last_message_json = urllib2.urlopen(api['last_message_url']) | |
message = json.load(last_message_json) | |
return message | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='check status of github.com') | |
args = parser.parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment