diff --git a/templates/rocketchat-bot.py.j2 b/templates/rocketchat-bot.py.j2 index 7f7860b..4e97260 100755 --- a/templates/rocketchat-bot.py.j2 +++ b/templates/rocketchat-bot.py.j2 @@ -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