-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalerta_op5.py
56 lines (40 loc) · 1.94 KB
/
alerta_op5.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
44
45
46
47
48
49
50
51
52
53
54
55
import os
import datetime
from op5 import OP5
import logging
from alerta.app import app
from alerta.app import db
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.op5')
DEFAULT_ALERTMANAGER_API_URL = 'https://demo.op5.com/api'
OP5_API_URL = os.environ.get('OP5_API_URL') or app.config.get('OP5_API_URL', None)
OP5_API_USERNAME = os.environ.get('OP5_API_USERNAME') or app.config.get('OP5_API_USERNAME', '')
OP5_API_PASSWORD = os.environ.get('OP5_API_PASSWORD') or app.config.get('OP5_API_PASSWORD', '')
class OP5Acknowledge(PluginBase):
def pre_receive(self, alert):
return alert
def post_receive(self, alert):
return
def status_change(self, alert, status, text):
if alert.event_type not in ('op5ServiceAlert', 'op5HostAlert'):
return
if alert.status == status:
return
if status == 'ack':
json_data = {"sticky":"1","notify":"0","persistent":"1","comment": text}
if alert.event_type == 'op5ServiceAlert':
command_type = 'ACKNOWLEDGE_SVC_PROBLEM'
json_data["host_name"] = alert.resource
json_data["service_description"] = alert.event
if alert.event_type == 'op5HostAlert':
command_type = 'ACKNOWLEDGE_HOST_PROBLEM'
json_data["host_name"] = alert.resource
op5 = OP5(OP5_API_URL, OP5_API_USERNAME, OP5_API_PASSWORD, dryrun=False, debug=False, logtofile=False, interactive=False)
op5.command(command_type, json_data)
# example r={"status":"success","data":{"silenceId":8}}
#try:
# silenceId = r.json()['data']['silenceId']
# db.update_attributes(alert.id, {'silenceId': silenceId})
#except Exception as e:
# raise RuntimeError("Alertmanager: ERROR - %s", e)
#LOG.debug('Alertmanager: Added silenceId %s to attributes', silenceId)