forked from alerta/alerta-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alerta_op5.py
50 lines (36 loc) · 1.63 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
import datetime
import logging
import os
from op5 import OP5
try:
from alerta.plugins import app # alerta >= 5.0
except ImportError:
from alerta.app import app # alerta < 5.0
from alerta.app import db
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.op5')
DEFAULT_OP5_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)