mirror of
https://github.com/moan0s/alertbot.git
synced 2024-10-01 06:25:35 -04:00
fix: grafana timestamp parsing
This commit is contained in:
parent
35ed320213
commit
99fe4f68ab
17
alertbot.py
17
alertbot.py
@ -1,6 +1,6 @@
|
|||||||
import datetime
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import dateutil.parser
|
||||||
from aiohttp.web import Request, Response, json_response
|
from aiohttp.web import Request, Response, json_response
|
||||||
from maubot import Plugin, MessageEvent
|
from maubot import Plugin, MessageEvent
|
||||||
from maubot.handlers import web, command
|
from maubot.handlers import web, command
|
||||||
@ -75,11 +75,11 @@ def get_alert_type(data):
|
|||||||
|
|
||||||
# Grafana
|
# Grafana
|
||||||
try:
|
try:
|
||||||
data["alerts"][0]["labels"]["grafana_folder"]
|
if data["alerts"][0]["labels"]["grafana_folder"]:
|
||||||
if data['status'] == "firing":
|
if data['status'] == "firing":
|
||||||
return "grafana-alert"
|
return "grafana-alert"
|
||||||
else:
|
else:
|
||||||
return "grafana-resolved"
|
return "grafana-resolved"
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -186,7 +186,6 @@ def grafana_alert_to_markdown(alert_data: dict) -> list:
|
|||||||
"""
|
"""
|
||||||
messages = []
|
messages = []
|
||||||
for alert in alert_data["alerts"]:
|
for alert in alert_data["alerts"]:
|
||||||
datetime_format = "%Y-%m-%dT%H:%M:%S%z"
|
|
||||||
if alert['status'] == "firing":
|
if alert['status'] == "firing":
|
||||||
message = (
|
message = (
|
||||||
f"""**Firing 🔥**: {alert['labels']['alertname']}
|
f"""**Firing 🔥**: {alert['labels']['alertname']}
|
||||||
@ -198,8 +197,8 @@ def grafana_alert_to_markdown(alert_data: dict) -> list:
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
if alert['status'] == "resolved":
|
if alert['status'] == "resolved":
|
||||||
end_at = datetime.datetime.strptime(alert['endsAt'], datetime_format)
|
end_at = dateutil.parser.isoparse(alert['endsAt'])
|
||||||
start_at = datetime.datetime.strptime(alert['startsAt'], datetime_format)
|
start_at = dateutil.parser.isoparse(alert['startsAt'])
|
||||||
message = (
|
message = (
|
||||||
f"""**Resolved 🥳**: {alert['labels']['alertname']}
|
f"""**Resolved 🥳**: {alert['labels']['alertname']}
|
||||||
|
|
||||||
|
@ -5,4 +5,6 @@ license: AGPL-3.0-or-later
|
|||||||
modules:
|
modules:
|
||||||
- alertbot
|
- alertbot
|
||||||
main_class: AlertBot
|
main_class: AlertBot
|
||||||
|
dependencies:
|
||||||
|
- python-dateutil>=2.8.2,<3.0.0
|
||||||
webapp: true
|
webapp: true
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
maubot
|
maubot
|
||||||
aiohttp
|
aiohttp
|
||||||
datetime
|
python-dateutil
|
Loading…
Reference in New Issue
Block a user