alarms: more friendly notifications
This commit is contained in:
parent
6ddc82dfd8
commit
239605ef89
1 changed files with 14 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue