0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-02-11 16:28:51 +00:00
alerta_alerta/examples/plugins/transient/alerta_transient.py
2018-09-16 00:20:53 +02:00

25 lines
700 B
Python

import logging
from alerta.exceptions import RateLimit
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.transient')
FLAPPING_WINDOW = 120 # seconds
FLAPPING_COUNT = 2 # threshold
class TransientAlert(PluginBase):
def pre_receive(self, alert):
LOG.info('Detecting transient alerts...')
if alert.is_flapping(window=FLAPPING_WINDOW, count=FLAPPING_COUNT):
raise RateLimit('Flapping alert received more than %s times in %s seconds' %
(FLAPPING_COUNT, FLAPPING_WINDOW))
return alert
def post_receive(self, alert):
return
def status_change(self, alert, status, text):
return