Skip to content
Snippets Groups Projects
Verified Commit 21cb0f3e authored by nd's avatar nd
Browse files

added labels to telegram notifications

parent 069df8c5
Branches
Tags
No related merge requests found
...@@ -33,11 +33,15 @@ def postAlertmanager(chatID): ...@@ -33,11 +33,15 @@ def postAlertmanager(chatID):
message += "Description: "+alert['annotations']['description']+"\n" message += "Description: "+alert['annotations']['description']+"\n"
if alert['status'] == "resolved": if alert['status'] == "resolved":
correctDate = parser.parse(alert['endsAt']).strftime('%Y-%m-%d %H:%M:%S') correctDate = parser.parse(alert['endsAt']).strftime('%Y-%m-%d %H:%M:%S')
message += "Resolved: "+correctDate message += "Resolved: "+correctDate+"\n"
elif alert['status'] == "firing": elif alert['status'] == "firing":
correctDate = parser.parse(alert['startsAt']).strftime('%Y-%m-%d %H:%M:%S') correctDate = parser.parse(alert['startsAt']).strftime('%Y-%m-%d %H:%M:%S')
message += "Started: "+correctDate message += "Started: "+correctDate+"\n"
bot.sendMessage(chat_id=chatID, text=message) message = message.replace('-', '\-').replace('.', '\.') + "labels: \n```\n"
for l in alert['labels']:
message += l + " : "+alert['labels'][l] + "\n"
message += "```"
bot.sendMessage(chat_id=chatID, text=message, parse_mode=telegram.ParseMode.MARKDOWN_V2)
return "Alert OK", 200 return "Alert OK", 200
except Exception as error: except Exception as error:
bot.sendMessage(chat_id=chatID, text="Error to read json: "+str(error)) bot.sendMessage(chat_id=chatID, text="Error to read json: "+str(error))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment