Skip to content

Instantly share code, notes, and snippets.

@reinaldons
Last active January 2, 2016 00:49
Show Gist options
  • Save reinaldons/8225919 to your computer and use it in GitHub Desktop.
Save reinaldons/8225919 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import cgi
import urllib
import urllib2
import sys
import cgitb
cgitb.enable()
AMQ_URL = 'http://amq:8161/api/message/healthcheck.xpto?type=queue&clientId=xpto'
PING_URL = 'http://localhost:8080/healthcheck/ping'
email_key = 'email'
# envia post para a fila do amq
def post_amq(email):
urllib2.urlopen(AMQ_URL, urllib.urlencode({"body": email}))
# verifica se o sistema esta fora mesmo antes de postar ao amq
def ping(email):
response = urllib2.urlopen(PING_URL)
xml = response.read()
if 'ERRO' in xml:
""" sistema fora via healthcheck """
sys.stderr.write(xml)
post_amq(email)
def healthcheck(email):
try:
ping(email=email)
message = 'Email enviado para %s com sucesso!' % email
except urllib2.HTTPError, e:
sys.stderr.write(str(e.code))
except urllib2.URLError, e:
sys.stderr.write(str(e.reason))
print 'Content-type: application/json;charset=utf-8'
print
print '{"result": "%s"}' % message if message else '{"result": "Tente novamente mais tarde"}'
# processa o POST do form503.html
arguments = cgi.FieldStorage()
healthcheck(email=arguments[email_key].value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment