forked from alerta/alerta-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerta_enhance.py
34 lines (21 loc) · 922 Bytes
/
alerta_enhance.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
import logging
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.enhance')
RUNBOOK_URL = 'http://www.example.com/wiki/RunBook' # example only
class EnhanceAlert(PluginBase):
def pre_receive(self, alert):
LOG.info("Enhancing alert...")
# Set "isOutOfHours" flag for later use by notification plugins
dayOfWeek = alert.create_time.strftime('%a')
hourOfDay = alert.create_time.hour
if dayOfWeek in ['Sat', 'Sun'] or 8 > hourOfDay > 18:
alert.attributes['isOutOfHours'] = True
else:
alert.attributes['isOutOfHours'] = False
# Add link to Run Book based on event name
alert.attributes['runBookUrl'] = '%s/%s' % (RUNBOOK_URL, alert.event.replace(' ', '-'))
return alert
def post_receive(self, alert):
return
def status_change(self, alert, status, text):
return