-
-
Notifications
You must be signed in to change notification settings - Fork 365
/
Copy pathblackout.py
46 lines (34 loc) · 1.52 KB
/
blackout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import logging
from alerta.exceptions import BlackoutPeriod
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins')
class BlackoutHandler(PluginBase):
"""
Default suppression blackout handler will drop alerts that match a blackout
period and will return a 202 Accept HTTP status code.
If "NOTIFICATION_BLACKOUT" is set to ``True`` then the alert is processed
but alert status is set to "blackout" and the alert will not be passed to
any plugins for further notification.
"""
def pre_receive(self, alert, **kwargs):
NOTIFICATION_BLACKOUT = self.get_config('NOTIFICATION_BLACKOUT', default=True, type=bool, **kwargs)
if self.get_config('ALARM_MODEL', **kwargs) == 'ALERTA':
status = 'blackout'
else:
status = 'OOSRV' # ISA_18_2
if alert.is_blackout():
if NOTIFICATION_BLACKOUT:
LOG.debug(f'Set status to "{status}" during blackout period (id={alert.id})')
alert.status = status
else:
LOG.debug(f'Suppressed alert during blackout period (id={alert.id})')
raise BlackoutPeriod('Suppressed alert during blackout period')
return alert
def post_receive(self, alert, **kwargs):
return
def status_change(self, alert, status, text, **kwargs):
return
def take_action(self, alert, action, text, **kwargs):
raise NotImplementedError
def delete(self, alert, **kwargs) -> bool:
raise NotImplementedError