From ba644039437ba1f38a046cf832e9c7e9554d67ab Mon Sep 17 00:00:00 2001 From: Kota Tomoyasu Date: Sat, 13 Apr 2019 11:24:04 +0900 Subject: [PATCH] add alert custom message. pagerduty, mattermost, hangoutschat --- redash/destinations/hangoutschat.py | 18 +++++++++++++++++- redash/destinations/mattermost.py | 9 +++++++++ redash/destinations/pagerduty.py | 7 ++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/redash/destinations/hangoutschat.py b/redash/destinations/hangoutschat.py index 28951b6193..5db48e9cf7 100644 --- a/redash/destinations/hangoutschat.py +++ b/redash/destinations/hangoutschat.py @@ -44,11 +44,16 @@ def notify(self, alert, query, user, new_state, app, host, options): else: message = "Unable to determine status. Check Query and Alert configuration." + if alert.custom_subject: + title = alert.custom_subject + else: + title = alert.name + data = { "cards": [ { "header": { - "title": alert.name + "title": title }, "sections": [ { @@ -65,6 +70,17 @@ def notify(self, alert, query, user, new_state, app, host, options): ] } + if alert.template: + data["cards"][0]["sections"].append({ + "widgets": [ + { + "textParagraph": { + "text": alert.render_template() + } + } + ] + }) + if options.get("icon_url"): data["cards"][0]["header"]["imageUrl"] = options.get("icon_url") diff --git a/redash/destinations/mattermost.py b/redash/destinations/mattermost.py index ea0280954d..ca9e4ea161 100644 --- a/redash/destinations/mattermost.py +++ b/redash/destinations/mattermost.py @@ -40,7 +40,16 @@ def notify(self, alert, query, user, new_state, app, host, options): else: text = "####" + alert.name + " went back to normal" + if alert.custom_subject: + text += '\n' + alert.custom_subject payload = {'text': text} + + if alert.template: + payload['attachments'] = [{'fields': [{ + "title": "Description", + "value": alert.render_template() + }]}] + if options.get('username'): payload['username'] = options.get('username') if options.get('icon_url'): payload['icon_url'] = options.get('icon_url') if options.get('channel'): payload['channel'] = options.get('channel') diff --git a/redash/destinations/pagerduty.py b/redash/destinations/pagerduty.py index c0411a04ff..737d801e57 100644 --- a/redash/destinations/pagerduty.py +++ b/redash/destinations/pagerduty.py @@ -43,7 +43,9 @@ def notify(self, alert, query, user, new_state, app, host, options): default_desc = self.DESCRIPTION_STR.format(query_id=query.id, query_name=query.name) - if options.get('description'): + if alert.custom_subject: + default_desc = alert.custom_subject + elif options.get('description'): default_desc = options.get('description') incident_key = self.KEY_STRING.format(alert_id=alert.id, query_id=query.id) @@ -58,6 +60,9 @@ def notify(self, alert, query, user, new_state, app, host, options): } } + if alert.template: + data['payload']['custom_details'] = alert.render_template() + if new_state == 'triggered': data['event_action'] = 'trigger' elif new_state == "unknown":