fix error handling
This commit is contained in:
parent
b99410f135
commit
05063e0077
1 changed files with 12 additions and 6 deletions
|
|
@ -24,6 +24,9 @@ api = RocketChat(botUser, botPass, server_url=botChatURL, session=api_session)
|
||||||
def postAlertmanager(chatName):
|
def postAlertmanager(chatName):
|
||||||
try:
|
try:
|
||||||
content = json.loads(request.get_data())
|
content = json.loads(request.get_data())
|
||||||
|
|
||||||
|
res = True
|
||||||
|
|
||||||
for alert in content['alerts']:
|
for alert in content['alerts']:
|
||||||
message = ""
|
message = ""
|
||||||
if alert['status'] == "firing":
|
if alert['status'] == "firing":
|
||||||
|
|
@ -56,12 +59,15 @@ def postAlertmanager(chatName):
|
||||||
for l in alert['labels']:
|
for l in alert['labels']:
|
||||||
labels += l + " : "+alert['labels'][l] + "\n"
|
labels += l + " : "+alert['labels'][l] + "\n"
|
||||||
message += labels + "```\n"
|
message += labels + "```\n"
|
||||||
if api.chat_post_message(message, channel=chatName, alias='Alertmanager').ok:
|
|
||||||
return "Alert OK", 200
|
res &= api.chat_post_message(message, channel=chatName, alias='Alertmanager').ok
|
||||||
else:
|
|
||||||
return "Alert fail", 200
|
if res:
|
||||||
|
return "Alert OK", 200
|
||||||
|
else:
|
||||||
|
return "Alert fail", 200
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
bot.sendMessage(chat_id=chatID, text="Error to read json: "+str(error))
|
api.chat_post_message("Error to read json: "+str(error), channel=chatName, alias='Alertmanager')
|
||||||
app.logger.info("\t%s",error)
|
app.logger.info("\t%s",error)
|
||||||
return "Alert fail", 200
|
return "Alert fail", 200
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue