-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathalerta_ding.py
51 lines (36 loc) · 1.29 KB
/
alerta_ding.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
import logging
import os
from alerta.plugins import PluginBase
from dingtalkchatbot.chatbot import DingtalkChatbot
try:
from alerta.plugins import app # alerta >= 5.0
except ImportError:
from alerta.app import app # alerta < 5.0
LOG = logging.getLogger('alerta.plugins.ding')
DING_WEBHOOK_URL = os.environ.get(
'DING_WEBHOOK_URL') or app.config.get('DING_WEBHOOK_URL')
DASHBOARD_URL = os.environ.get(
'DASHBOARD_URL') or app.config.get('DASHBOARD_URL', '')
class ServiceIntegration(PluginBase):
def __init__(self, name=None):
super().__init__(name)
def pre_receive(self, alert):
return alert
def _prepare_payload(self, alert):
return '{}** **{}**\n`{}` ```{}```'.format(
alert.severity,
alert.environment,
alert.event,
alert.value,
)
LOG.debug('DingTalk: %s', alert)
def post_receive(self, alert):
if alert.repeat:
return
ding = DingtalkChatbot(DING_WEBHOOK_URL)
message = self._prepare_payload(alert)
LOG.debug('DingTalk: %s', message)
ding.send_text(msg='Received Alert {}'.format(message))
# xiaoding.send_text(msg='next alert {}'.format(service_name_str))
def status_change(self, alert, status, text):
return