-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Microsoft Teams Webhook alert destination #5691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
35e3589
c19f910
5c22129
5529bcb
10bb655
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import logging | ||
| import requests | ||
|
|
||
| from redash.destinations import * | ||
| from redash.utils import json_dumps | ||
| from redash.serializers import serialize_alert | ||
|
|
||
|
|
||
| class MicrosoftTeamsWebhook(BaseDestination): | ||
| @classmethod | ||
| def name(cls): | ||
| return "Microsoft Teams Webhook" | ||
|
|
||
| @classmethod | ||
| def type(cls): | ||
| return "microsoft_teams_webhook" | ||
|
|
||
| @classmethod | ||
| def configuration_schema(cls): | ||
| return { | ||
| "type": "object", | ||
| "properties": { | ||
| "url": {"type": "string"}, | ||
| }, | ||
| "required": ["url"], | ||
| } | ||
|
|
||
| @classmethod | ||
| def icon(cls): | ||
| return "fa-bolt" | ||
|
|
||
| def notify(self, alert, query, user, new_state, app, host, options): | ||
| """ | ||
| :type app: redash.Redash | ||
| """ | ||
| try: | ||
| data = { | ||
|
||
| "@type": "MessageCard", | ||
| "@context": "http://schema.org/extensions", | ||
| "themeColor": "0076D7", | ||
| "summary": "A Redash Alert was Triggered", | ||
| "sections": [{ | ||
| "activityTitle": "A Redash Alert was Triggered", | ||
| "facts": [{ | ||
| "name": "Alert Name", | ||
| "value": alert.name | ||
| }, { | ||
| "name": "Alert Author", | ||
| "value": user.name | ||
| }, { | ||
| "name": "Query", | ||
| "value": query.query_text | ||
| }, { | ||
| "name": "Query URL", | ||
| "value": "%s/queries/%s" % (host, query.id) | ||
| }], | ||
| "markdown": True | ||
| }] | ||
| } | ||
|
|
||
| headers = {"Content-Type": "application/json"} | ||
|
|
||
| resp = requests.post( | ||
| options.get("url"), | ||
| data=json_dumps(data), | ||
| headers=headers, | ||
| timeout=5.0, | ||
| ) | ||
| if resp.status_code != 200: | ||
| logging.error( | ||
| "MS Teams Webhook send ERROR. status_code => {status}".format( | ||
| status=resp.status_code | ||
| ) | ||
| ) | ||
| except Exception: | ||
| logging.exception("MS Teams Webhook send ERROR.") | ||
|
|
||
|
|
||
| register(MicrosoftTeamsWebhook) | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to add a
titlehere to indicate this is a webhook URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.