mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Merge pull request #1130 from AntoineAugusti/patch-1
Improve Slack notification style
This commit is contained in:
@@ -23,9 +23,27 @@ class Slack(BaseDestination):
|
|||||||
return 'fa-slack'
|
return 'fa-slack'
|
||||||
|
|
||||||
def notify(self, alert, query, user, new_state, app, host, options):
|
def notify(self, alert, query, user, new_state, app, host, options):
|
||||||
msg = "Check <{host}/alerts/{alert_id}|alert> / check <{host}/queries/{query_id}|query>".format(
|
# Documentation: https://api.slack.com/docs/attachments
|
||||||
host=host, alert_id=alert.id, query_id=query.id)
|
fields = [
|
||||||
payload = {'text': msg}
|
{
|
||||||
|
"title": "Query",
|
||||||
|
"value": "{host}/queries/{query_id}".format(host=host, query_id=query.id),
|
||||||
|
"short": True
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Alert",
|
||||||
|
"value": "{host}/alerts/{alert_id}".format(host=host, alert_id=alert.id),
|
||||||
|
"short": True
|
||||||
|
}
|
||||||
|
]
|
||||||
|
if new_state == "triggered":
|
||||||
|
text = alert.name + " just triggered"
|
||||||
|
color = "#c0392b"
|
||||||
|
else:
|
||||||
|
text = alert.name + " went back to normal"
|
||||||
|
color = "#27ae60"
|
||||||
|
|
||||||
|
payload = {'attachments': [{'text': text, 'color': color, 'fields': fields}]}
|
||||||
try:
|
try:
|
||||||
resp = requests.post(options.get('url'), data=json.dumps(payload))
|
resp = requests.post(options.get('url'), data=json.dumps(payload))
|
||||||
logging.warning(resp.text)
|
logging.warning(resp.text)
|
||||||
@@ -34,5 +52,4 @@ class Slack(BaseDestination):
|
|||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Slack send ERROR.")
|
logging.exception("Slack send ERROR.")
|
||||||
|
|
||||||
|
|
||||||
register(Slack)
|
register(Slack)
|
||||||
|
|||||||
Reference in New Issue
Block a user