fix: grafana timestamp parsing

This commit is contained in:
Dominik Rimpf 2023-09-17 04:44:50 +02:00
parent 35ed320213
commit 99fe4f68ab
3 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import datetime
import json
import dateutil.parser
from aiohttp.web import Request, Response, json_response
from maubot import Plugin, MessageEvent
from maubot.handlers import web, command
@ -75,7 +75,7 @@ def get_alert_type(data):
# Grafana
try:
data["alerts"][0]["labels"]["grafana_folder"]
if data["alerts"][0]["labels"]["grafana_folder"]:
if data['status'] == "firing":
return "grafana-alert"
else:
@ -186,7 +186,6 @@ def grafana_alert_to_markdown(alert_data: dict) -> list:
"""
messages = []
for alert in alert_data["alerts"]:
datetime_format = "%Y-%m-%dT%H:%M:%S%z"
if alert['status'] == "firing":
message = (
f"""**Firing 🔥**: {alert['labels']['alertname']}
@ -198,8 +197,8 @@ def grafana_alert_to_markdown(alert_data: dict) -> list:
"""
)
if alert['status'] == "resolved":
end_at = datetime.datetime.strptime(alert['endsAt'], datetime_format)
start_at = datetime.datetime.strptime(alert['startsAt'], datetime_format)
end_at = dateutil.parser.isoparse(alert['endsAt'])
start_at = dateutil.parser.isoparse(alert['startsAt'])
message = (
f"""**Resolved 🥳**: {alert['labels']['alertname']}

View File

@ -5,4 +5,6 @@ license: AGPL-3.0-or-later
modules:
- alertbot
main_class: AlertBot
dependencies:
- python-dateutil>=2.8.2,<3.0.0
webapp: true

View File

@ -1,3 +1,3 @@
maubot
aiohttp
datetime
python-dateutil