Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion keep/providers/prometheus_provider/prometheus_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dataclasses
import datetime
import os
import uuid as uuid_module

import pydantic
import requests
Expand Down Expand Up @@ -179,7 +180,16 @@ def _format_alert(
alerts = event.get("alerts", [event])

for alert in alerts:
alert_id = alert.get("id", alert.get("labels", {}).get("alertname"))
raw_id = alert.get("id")
if raw_id:
try:
uuid_module.UUID(str(raw_id))
alert_id = raw_id
except (ValueError, AttributeError):
alert_id = str(uuid_module.uuid4())
else:
alert_name = alert.get("labels", {}).get("alertname")
alert_id = alert_name if alert_name else str(uuid_module.uuid4())
description = alert.get("annotations", {}).pop(
"description", None
) or alert.get("annotations", {}).get("summary", alert_id)
Expand Down
Loading