Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ x-redash-service: &redash-service
build:
context: .
args:
skip_frontend_build: "true"
skip_frontend_build: "true" # set to empty string to build
volumes:
- .:/app
env_file:
Expand Down
79 changes: 79 additions & 0 deletions redash/destinations/microsoft_teams_webhook.py
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"},
Copy link
Member

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 title here to indicate this is a webhook URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Screen Shot 2022-01-26 at 3 23 28 PM

},
"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 = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about supporting custom templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to copy what the chatwork destination did for message templates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2022-01-27 at 10 19 36 AM

"@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)
1 change: 1 addition & 0 deletions redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def email_server_is_configured():
"redash.destinations.chatwork",
"redash.destinations.pagerduty",
"redash.destinations.hangoutschat",
"redash.destinations.microsoft_teams_webhook",
]

enabled_destinations = array_from_string(
Expand Down