Skip to content
Snippets Groups Projects
Verified Commit 05063e00 authored by psy's avatar psy
Browse files

fix error handling

parent b99410f1
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,9 @@ api = RocketChat(botUser, botPass, server_url=botChatURL, session=api_session)
def postAlertmanager(chatName):
try:
content = json.loads(request.get_data())
res = True
for alert in content['alerts']:
message = ""
if alert['status'] == "firing":
......@@ -56,12 +59,15 @@ def postAlertmanager(chatName):
for l in alert['labels']:
labels += l + " : "+alert['labels'][l] + "\n"
message += labels + "```\n"
if api.chat_post_message(message, channel=chatName, alias='Alertmanager').ok:
return "Alert OK", 200
else:
return "Alert fail", 200
except Exception as error:
bot.sendMessage(chat_id=chatID, text="Error to read json: "+str(error))
res &= api.chat_post_message(message, channel=chatName, alias='Alertmanager').ok
if res:
return "Alert OK", 200
else:
return "Alert fail", 200
except Exception as error:
api.chat_post_message("Error to read json: "+str(error), channel=chatName, alias='Alertmanager')
app.logger.info("\t%s",error)
return "Alert fail", 200
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment