0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-02-10 07:52:26 +00:00
alerta_alerta/alerta/plugins/heartbeat.py
Nick Satterly 69bebd3ded
Push app config to plugin methods for per-alert config (#944)
* 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
2019-04-23 22:58:14 +02:00

37 lines
1,020 B
Python

import logging
from alerta.exceptions import HeartbeatReceived
from alerta.models.heartbeat import Heartbeat
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins')
class HeartbeatReceiver(PluginBase):
"""
Default heartbeat receiver intercepts alerts with event='Heartbeat', converts
them into heartbeats and will return a 202 Accept HTTP status code.
"""
def pre_receive(self, alert, **kwargs):
if alert.event == 'Heartbeat':
hb = Heartbeat(
origin=alert.origin,
tags=alert.tags,
timeout=alert.timeout,
customer=alert.customer
)
hb.create()
raise HeartbeatReceived('Alert converted to heartbeat')
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