Skip to content

Instantly share code, notes, and snippets.

@jayzeng
Last active December 17, 2015 10:29
Show Gist options
  • Save jayzeng/5595368 to your computer and use it in GitHub Desktop.
Save jayzeng/5595368 to your computer and use it in GitHub Desktop.
health check
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)
@jayzeng
Copy link
Author

jayzeng commented May 16, 2013

Usage:

:!python2.7 healthcheck.py -H api.dev.dh-jay01-dev.sea1.office.priv
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment