Last active
December 17, 2015 10:29
-
-
Save jayzeng/5595368 to your computer and use it in GitHub Desktop.
health check
This file contains hidden or 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
import urllib2 | |
import json | |
import argparse | |
import sys | |
class HealthCheck(object): | |
""" | |
Parse command line argument | |
""" | |
def parse_arg_options(self): | |
usage = 'Usage: %prog [options]' | |
parser = argparse.ArgumentParser(description=usage) | |
parser.add_argument('-H', '--host', help='health check host', dest='host',required=True) | |
return parser.parse_args() | |
""" | |
Send health check http request | |
@param host host name | |
@return dict | |
""" | |
def send_request(self, hostname): | |
url = 'http://%s/v3/Internal_HealthCheck.json?Method=full&NetworkId=demo' % hostname | |
response = urllib2.urlopen(url) | |
data = json.load(response) | |
return data['response'] | |
""" | |
health check passed? | |
@return boolean | |
""" | |
def isPass(self, data): | |
return data['data'] == 'STELLAR' | |
""" | |
Main() | |
""" | |
if __name__ == "__main__": | |
h = HealthCheck() | |
args = h.parse_arg_options() | |
if args.host: | |
print h.isPass(h.send_request(args.host)) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
:!python2.7 healthcheck.py -H api.dev.dh-jay01-dev.sea1.office.priv
True