Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions alerta/database/backends/postgres/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,13 @@ def get_blackouts_count(self, query=None):
"""
return self._fetchone(select, query.vars).count

def is_shelved(self, alert):
select = """
select true from alerts where status='shelved' AND resource=%(resource)s AND event=%(event)s AND environment=%(environment)s
"""
test = self._fetchone(select, vars(alert))
return test is not None

def is_blackout_period(self, alert):
select = """
SELECT *
Expand Down
3 changes: 3 additions & 0 deletions alerta/database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def set_alerts(self, alerts):
def get_alert(self, id, customers=None):
raise NotImplementedError

def is_shelved(self, alert):
raise NotImplementedError

# STATUS, TAGS, ATTRIBUTES

def set_status(self, id, status, timeout, update_time, history=None):
Expand Down
21 changes: 1 addition & 20 deletions alerta/models/alarms/alerta_isa_18_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@
'text': 'black'
}

F_DSUPR = 'DSUPR'
G_OOSRV = 'OOSRV'

STATUS_MAP = {
Status.Closed: 'A',
Status.Open: 'B',
Status.Ack: 'C',
Status.Unack: 'D',
Status.Shelved: 'E',
F_DSUPR: 'F',
G_OOSRV: 'G'
}

MORE_SEVERE = 'moreSevere'
Expand Down Expand Up @@ -174,22 +169,8 @@ def next_state(rule, severity, status):
if current_severity == StateMachine.DEFAULT_NORMAL_SEVERITY:
return next_state('Open -> Unack', current_severity, Status.Unack)

# Return from Suppressed-by-design (F) -> Normal (A) or Unack (B)
if state == F_DSUPR:
if current_severity == StateMachine.DEFAULT_NORMAL_SEVERITY:
return next_state('Return from Suppressed-by-design, Suppressed-by-design (G) -> Normal (A)', current_severity, Status.Closed)
else:
return next_state('Return from Suppressed-by-design, Suppressed-by-design (G) -> Unack (B)', current_severity, Status.Open)

# Return from Out-of-service (G) -> Normal (A) or Unack (B)
if state == G_OOSRV:
if current_severity == StateMachine.DEFAULT_NORMAL_SEVERITY:
return next_state('Return from Out-of-service, Out-of-service (G) -> Normal (A)', current_severity, Status.Closed)
else:
return next_state('Return from Out-of-service, Out-of-service (G) -> Unack (B)', current_severity, Status.Open)

return next_state('NOOP', current_severity, state)

@staticmethod
def is_suppressed(alert):
return alert.status in [F_DSUPR, G_OOSRV]
return alert.status == Status.Shelved
4 changes: 4 additions & 0 deletions alerta/models/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ def is_blackout(self) -> bool:
return False
return db.is_blackout_period(self)

@property
def is_shelved(self) -> bool:
return db.is_shelved(self)

@property
def is_suppressed(self) -> bool:
"""Is the alert status 'blackout'?"""
Expand Down
2 changes: 1 addition & 1 deletion alerta/plugins/notification_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def pre_receive(self, alert, **kwargs):
return alert

def post_receive(self, alert: 'Alert', **kwargs):
if not alert:
if not alert or alert.is_shelved:
return
NotificationDelay.delete_alert(alert.id)
config = kwargs.get('config')
Expand Down