Alerts: prevent crash on unknown severity level

This commit is contained in:
Théophile Bastian 2024-11-06 09:49:40 +01:00
parent 313795d050
commit a9748f409d

View file

@ -37,7 +37,7 @@ class Alert:
self.description = annotations["description"] self.description = annotations["description"]
if self.firing: if self.firing:
self.status = self.labels["severity"] self.status = self.labels.get("severity", "unknown_alert")
else: else:
self.status = "resolved" self.status = "resolved"
@ -55,11 +55,11 @@ class Alert:
@property @property
def emoji(self) -> str: def emoji(self) -> str:
return self.EMOJIS[self.status] return self.EMOJIS.get(self.status, "❓️")
@property @property
def color(self) -> str: def color(self) -> str:
return self.COLORS[self.status] return self.COLORS.get(self.status, "ffff0c")
def match_label(self, label_name: str, pattern: re.Pattern[str]) -> bool: def match_label(self, label_name: str, pattern: re.Pattern[str]) -> bool:
if label_name not in self.labels: if label_name not in self.labels: