Skip to content

Commit b962046

Browse files
committed
adds mattermost dest
1 parent 3c75c2b commit b962046

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

26.5 KB
Loading

redash/destinations/mattermost.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import json
2+
import logging
3+
import requests
4+
5+
from redash.destinations import *
6+
7+
8+
class Mattermost(BaseDestination):
9+
@classmethod
10+
def configuration_schema(cls):
11+
return {
12+
'type': 'object',
13+
'properties': {
14+
'url': {
15+
'type': 'string',
16+
'title': 'Mattermost Webhook URL'
17+
},
18+
'username': {
19+
'type': 'string',
20+
'title': 'Username'
21+
},
22+
'icon_url': {
23+
'type': 'string',
24+
'title': 'Icon (URL)'
25+
},
26+
'channel': {
27+
'type': 'string',
28+
'title': 'Channel'
29+
}
30+
}
31+
}
32+
33+
@classmethod
34+
def icon(cls):
35+
return 'fa-bolt'
36+
37+
def notify(self, alert, query, user, new_state, app, host, options):
38+
if new_state == "triggered":
39+
text = "####" + alert.name + " just triggered"
40+
else:
41+
text = "####" + alert.name + " went back to normal"
42+
43+
payload = {'text': text}
44+
if options.get('username'): payload['username'] = options.get('username')
45+
if options.get('icon_url'): payload['icon_url'] = options.get('icon_url')
46+
if options.get('channel'): payload['channel'] = options.get('channel')
47+
48+
try:
49+
resp = requests.post(options.get('url'), data=json.dumps(payload))
50+
logging.warning(resp.text)
51+
52+
if resp.status_code != 200:
53+
logging.error("Mattermost webhook send ERROR. status_code => {status}".format(status=resp.status_code))
54+
except Exception:
55+
logging.exception("Mattermost webhook send ERROR.")
56+
57+
58+
register(Mattermost)

redash/settings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def all_settings():
185185
'redash.destinations.slack',
186186
'redash.destinations.webhook',
187187
'redash.destinations.hipchat',
188+
'redash.destinations.mattermost',
188189
]
189190

190191
enabled_destinations = array_from_string(os.environ.get("REDASH_ENABLED_DESTINATIONS", ",".join(default_destinations)))

0 commit comments

Comments
 (0)