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):
|
||||
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:
|
||||
|
||||
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:
|
||||
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)
|
||||
return "Alert fail", 200
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue