Handle unexpected format

This commit is contained in:
Julian-Samuel Gebühr 2022-09-18 10:38:23 +02:00
parent be2800b3f9
commit 7addc34fa3

View File

@ -70,6 +70,7 @@ def get_alert_messages(alert_data: dict, raw_mode=False) -> list:
if raw_mode or alert_type == "not-found": if raw_mode or alert_type == "not-found":
return ["**Data received**\n```\n" + str(alert_data).strip("\n").strip() + "\n```"] return ["**Data received**\n```\n" + str(alert_data).strip("\n").strip() + "\n```"]
else: else:
try:
if alert_type == "grafana-alert": if alert_type == "grafana-alert":
messages = grafana_alert_to_markdown(alert_data) messages = grafana_alert_to_markdown(alert_data)
elif alert_type == "grafana-resolved": elif alert_type == "grafana-resolved":
@ -80,6 +81,9 @@ def get_alert_messages(alert_data: dict, raw_mode=False) -> list:
messages = uptime_kuma_alert_to_markdown(alert_data) messages = uptime_kuma_alert_to_markdown(alert_data)
elif alert_type == "uptime-kuma-resolved": elif alert_type == "uptime-kuma-resolved":
messages = uptime_kuma_resolved_to_markdown(alert_data) 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 return messages