def sensu_event_resolve(message):
API_URL = settings.SENSU_API_URL + '/resolve'
userAndPass = base64.b64encode(str.encode("%s:%s" % (settings.SENSU_API_USER, settings.SENSU_API_PASSWORD))).decode("ascii")
headers = { 'X_REQUESTED_WITH' :'XMLHttpRequest',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Authorization' : 'Basic %s' % userAndPass }
try:
client_name, check_name = message['entity'].split(':')
post_params = {"client": client_name, "check": check_name}
request = http.request('POST', API_URL, body=json.dumps(post_params), headers=headers)
response = request.status
if response == 202:
#reader = codecs.getreader('utf-8')
#data = json.load(reader(request))
request.release_conn()
else:
logger.error('response: %s' % str(response))
except:
logger.error("sensu_event_resolve failed resolving entity: %s" % message['entity'])
raise
评论列表
文章目录