mirror of
https://github.com/alerta/alerta.git
synced 2025-01-24 17:29:39 +00:00
69bebd3ded
* Push app config to plugin methods for per-alert config * Add get_config() helper method to plugins * Explicitly pass kwargs to avoid race conditions using self * Test config variable precedence
25 lines
730 B
Python
25 lines
730 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, **kwargs):
|
|
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, **kwargs):
|
|
return
|
|
|
|
def status_change(self, alert, status, text, **kwargs):
|
|
return
|