Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@whatvn
Created May 8, 2012 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatvn/2632507 to your computer and use it in GitHub Desktop.
Save whatvn/2632507 to your computer and use it in GitHub Desktop.
This is what I think my application will use to perform heathcheck for http server
def heart_check(target):
global last_check
if int(time() - last_check) > 5:
logger(ctime() + ": Perform heart check")
p = re.compile("[a-z0-9-.]*?\.[a-z0-9]+$")
domain_tld = p.findall(target)[0]
conn = HTTPConnection(domain_tld, timeout = 5)
try:
accepted_responses = (404, 302, 304, 301, 200)
conn.request('HEAD', '/')
response = conn.getresponse()
if response.status in accepted_responses: return 1
else:
logger(target + ' is down')
return 0
except Exception, e:
logger(target + ' ' + str(e) )
return 0
finally:
conn.close()
last_check += 5
else:
return 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment