forked from alerta/alerta-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerta_forward.py
43 lines (34 loc) · 1.2 KB
/
alerta_forward.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
import os
import logging
from alerta.plugins import PluginBase
from alertaclient.api import Client
try:
from alerta.plugins import app # alerta >= 5.0
except ImportError:
from alerta.app import app # alerta < 5.0
LOG = logging.getLogger('alerta.plugins.forward')
FORWARD_URL = os.environ.get(
'FORWARD_URL') or app.config.get('FORWARD_URL')
FORWARD_API_KEY = os.environ.get(
'FORWARD_API_KEY') or app.config.get('FORWARD_API_KEY')
FORWARD_MAX_LENGTH = os.environ.get(
'FORWARD_MAX_LENGTH') or app.config.get('FORWARD_MAX_LENGTH') or 3
class ForwardAlert(PluginBase):
def pre_receive(self, alert):
return alert
def post_receive(self, alert):
if not FORWARD_URL or not FORWARD_API_KEY:
return
client = Client(endpoint=FORWARD_URL, key=FORWARD_API_KEY)
fw_count = alert.attributes.get('fw_count') or 0
fw_count = fw_count+1
if fw_count >= FORWARD_MAX_LENGTH:
LOG.debug('alert discarded by cycle overflow')
return
alert.attributes['fw_count'] = fw_count
client.send_alert(
**alert.serialize
)
return
def status_change(self, alert, status, text):
return