2017-09-01 22:22:59 +00:00
|
|
|
import logging
|
|
|
|
|
2018-09-15 22:07:50 +00:00
|
|
|
from alerta.exceptions import BlackoutPeriod
|
2019-04-23 20:58:14 +00:00
|
|
|
from alerta.plugins import PluginBase
|
2017-09-01 22:22:59 +00:00
|
|
|
|
2019-02-16 20:09:18 +00:00
|
|
|
LOG = logging.getLogger('alerta.plugins')
|
2017-09-01 22:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlackoutHandler(PluginBase):
|
|
|
|
"""
|
2018-04-01 15:30:24 +00:00
|
|
|
Default suppression blackout handler will drop alerts that match a blackout
|
|
|
|
period and will return a 202 Accept HTTP status code.
|
2017-09-01 22:22:59 +00:00
|
|
|
|
2018-04-01 15:30:24 +00:00
|
|
|
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.
|
2017-09-01 22:22:59 +00:00
|
|
|
"""
|
2018-09-15 22:07:50 +00:00
|
|
|
|
2019-04-23 20:58:14 +00:00
|
|
|
def pre_receive(self, alert, **kwargs):
|
|
|
|
NOTIFICATION_BLACKOUT = self.get_config('NOTIFICATION_BLACKOUT', default=True, type=bool, **kwargs)
|
2017-12-23 23:59:16 +00:00
|
|
|
|
2019-04-23 20:58:14 +00:00
|
|
|
if self.get_config('ALARM_MODEL', **kwargs) == 'ALERTA':
|
2019-03-03 22:44:52 +00:00
|
|
|
status = 'blackout'
|
|
|
|
else:
|
|
|
|
status = 'OOSRV' # ISA_18_2
|
|
|
|
|
2018-04-01 15:30:24 +00:00
|
|
|
if alert.is_blackout():
|
2019-02-11 18:51:06 +00:00
|
|
|
if NOTIFICATION_BLACKOUT:
|
2019-03-03 22:44:52 +00:00
|
|
|
LOG.debug('Set status to "{}" during blackout period (id={})'.format(status, alert.id))
|
|
|
|
alert.status = status
|
2018-04-01 15:30:24 +00:00
|
|
|
else:
|
2019-03-03 22:44:52 +00:00
|
|
|
LOG.debug('Suppressed alert during blackout period (id={})'.format(alert.id))
|
2018-09-15 22:20:53 +00:00
|
|
|
raise BlackoutPeriod('Suppressed alert during blackout period')
|
2017-09-01 22:22:59 +00:00
|
|
|
return alert
|
|
|
|
|
2019-04-23 20:58:14 +00:00
|
|
|
def post_receive(self, alert, **kwargs):
|
2017-09-01 22:22:59 +00:00
|
|
|
return
|
|
|
|
|
2019-04-23 20:58:14 +00:00
|
|
|
def status_change(self, alert, status, text, **kwargs):
|
2017-09-01 22:22:59 +00:00
|
|
|
return
|
2019-02-11 18:51:06 +00:00
|
|
|
|
|
|
|
def take_action(self, alert, action, text, **kwargs):
|
|
|
|
raise NotImplementedError
|
2020-02-25 19:45:51 +00:00
|
|
|
|
|
|
|
def delete(self, alert, **kwargs) -> bool:
|
|
|
|
raise NotImplementedError
|