Skip to content

Commit

Permalink
add alert custom message. pagerduty, mattermost, hangoutschat
Browse files Browse the repository at this point in the history
  • Loading branch information
Kota Tomoyasu committed Apr 13, 2019
1 parent 9623286 commit ba64403
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion redash/destinations/hangoutschat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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")

Expand Down
9 changes: 9 additions & 0 deletions redash/destinations/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 6 additions & 1 deletion redash/destinations/pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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":
Expand Down

0 comments on commit ba64403

Please sign in to comment.