mirror of
https://github.com/moan0s/alertbot.git
synced 2024-10-01 06:25:35 -04:00
Handle unexpected format
This commit is contained in:
parent
be2800b3f9
commit
7addc34fa3
24
alertbot.py
24
alertbot.py
@ -70,16 +70,20 @@ def get_alert_messages(alert_data: dict, raw_mode=False) -> list:
|
||||
if raw_mode or alert_type == "not-found":
|
||||
return ["**Data received**\n```\n" + str(alert_data).strip("\n").strip() + "\n```"]
|
||||
else:
|
||||
if alert_type == "grafana-alert":
|
||||
messages = grafana_alert_to_markdown(alert_data)
|
||||
elif alert_type == "grafana-resolved":
|
||||
messages = grafana_alert_to_markdown(alert_data)
|
||||
elif alert_type == "prometheus-alert":
|
||||
messages = prometheus_alert_to_markdown(alert_data)
|
||||
elif alert_type == "uptime-kuma-alert":
|
||||
messages = uptime_kuma_alert_to_markdown(alert_data)
|
||||
elif alert_type == "uptime-kuma-resolved":
|
||||
messages = uptime_kuma_resolved_to_markdown(alert_data)
|
||||
try:
|
||||
if alert_type == "grafana-alert":
|
||||
messages = grafana_alert_to_markdown(alert_data)
|
||||
elif alert_type == "grafana-resolved":
|
||||
messages = grafana_alert_to_markdown(alert_data)
|
||||
elif alert_type == "prometheus-alert":
|
||||
messages = prometheus_alert_to_markdown(alert_data)
|
||||
elif alert_type == "uptime-kuma-alert":
|
||||
messages = uptime_kuma_alert_to_markdown(alert_data)
|
||||
elif alert_type == "uptime-kuma-resolved":
|
||||
messages = uptime_kuma_resolved_to_markdown(alert_data)
|
||||
except KeyError as e:
|
||||
messages = ["**Data received**\n```\n" + str(alert_data).strip(
|
||||
"\n").strip() + f"\n```\nThe data was detected as {alert_type} but was not in an expected format. If you want to help the development of this bot, file a bug report [here](https://github.com/moan0s/alertbot/issues)\n{e.with_traceback()}"]
|
||||
return messages
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user