From 239605ef891d57fa3629d1f284f421481fb419e2 Mon Sep 17 00:00:00 2001 From: Iain Learmonth Date: Mon, 27 Jun 2022 14:58:38 +0100 Subject: [PATCH] alarms: more friendly notifications --- app/models/alarms.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/models/alarms.py b/app/models/alarms.py index e43583c..8acdde8 100644 --- a/app/models/alarms.py +++ b/app/models/alarms.py @@ -12,6 +12,16 @@ class AlarmState(enum.Enum): WARNING = 2 CRITICAL = 3 + @property + def emoji(self) -> str: + if self.name == "OK": + return "😅" + if self.name == "WARNING": + return "😟" + if self.name == "CRITICAL": + return "🚨" + return "❓" + class Alarm(db.Model): # type: ignore id = db.Column(db.Integer, primary_key=True) @@ -36,12 +46,12 @@ class Alarm(db.Model): # type: ignore if self.alarm_state != state or self.state_changed is None: self.state_changed = datetime.utcnow() activity = Activity(activity_type="alarm_state", - text=f"{self.alarm_state.name}->{state.name}! State changed for " - f"{self.aspect} on {self.target}: {text}") + text=f"[{self.aspect}] {self.state.emoji} Alarm state changed from " + f"{self.alarm_state.name} to {state.name} on {self.target}: {text}.") if (self.alarm_state.name in ["WARNING", "CRITICAL"] - or state.name in ["WARNING", "CRITICAL", "UNKNOWN"]): + or state.name in ["WARNING", "CRITICAL"]): # Notifications are only sent on recovery from warning/critical state or on entry - # to warning/critical/unknown states. This should reduce alert fatigue. + # to warning/critical states. This should reduce alert fatigue. activity.notify() db.session.add(activity) self.alarm_state = state