It is possible to publish Notifications from Workbench to an outgoing webhook. It can be a webhook configured in Seeq (Data Lab) or external (any POST endpoint). This article outlines how users can receive notifications on the presence of Seeq capsules via something other than email, such as in Slack.
This feature requires an additional software license. Please contact your Seeq sales representative for more information.
When posting to Data Lab the URL set in the Seeq configuration should be in relative form (details in the next section), for outside of Seeq sources - use a full URL.
Below is a sample project that includes the full path from Seeq to Slack:
Steps to implement the sample project:
Enable Notifications configuration -Features/Notifications/ConditionMonitors/Enabled
on the Seeq server (Administrator access required).
Create a notification on a condition.
In Data Lab make a new project.
Add an API endpoint that will be receiving the notifications and sending them out to slack (Like the script provided below). The code below can be copy-pasted and used right after replacing the URL on line 68.
Depending on how many notifications are configured on the system, you may want to adjust this script to filter to a subset of the notifications for the webhook integration.
Sample data lab API that receives condition monitor results and sends them out in slack in a readable format.
PY
# POST /condition_monitors_template
import traceback
import requests
import json
from datetime import datetime
"""
Request to the webhook will get a response with the results from a condition monitor search along with some metadata
in the following format.
=================== ===================================================
Property Description
=================== ===================================================
WebhookNotificationResult
notificationConfiguration
notificationTriggerId UUID Id of a condition monitor that triggered the notification
contextualText A string with additional information configured on a notification like a
link to a workbook
timezone A string timezone for the condition monitor
capsuleGrouping CONDITION - One notification per one condition results
CAPSULE - One notification per one capsule found
ALL - All results in one notification
capsuleProperties A list of capsule properties selected to be sent with a notification
conditionMonitorName A string name of the condition monitor
results
ConditionResultForWebhook
capsuleEvents
conditionGuid UUID id for condition that the capsule event belongs to
source
capsule
start
value Start of the event
end
value End of the event
properties A map of properties
conditionName A string name of the condition that the capsules are part of
======================================================================
"""
text = ""
try:
data = REQUEST['body']
conditionResults = data['results']
conditionMonitorName = data['conditionMonitorName']
notificationConfiguration = data['notificationConfiguration']
text = f":scream: *{conditionMonitorName}:*\n\t"
for conditionResult in conditionResults:
conditionName = conditionResult['conditionName']
capsuleEvents = conditionResult['capsuleEvents']
for capsule in capsuleEvents:
source = capsule['source']
start = '' if 'start' not in source else 'Start: {0}\n\t'.format(datetime.utcfromtimestamp(int(source['start']['value'] / 1e9)).strftime('%Y-%m-%d %H:%M:%S'))
end = '' if 'end' not in source else 'End: {0}\n\t'.format(datetime.utcfromtimestamp(int(source['end']['value'] / 1e9)).strftime('%Y-%m-%d %H:%M:%S'))
duration = '' if 'Duration' not in source else 'Duration: {0}\n\t'.format(source['duration']['value'])
text += f"Condition: {conditionName}\n\t"
text += (start + end + duration)
properties = source['properties']
for capsuleProperty in notificationConfiguration['capsuleProperties']:
if capsuleProperty in properties:
text += f"{capsuleProperty}: {properties[capsuleProperty]['value']}\n\t"
text += "\n"
except Exception as e:
text += f"{str(e)}\n"
text += traceback.format_exc()
body = {'text': text}
url = 'https://hooks.slack.com/services/xxxxxxxxx/yyyyyyyyyyy/zzzzzzzzzzzzzzzzzzzzzzzz'
response = requests.post(url, json.dumps(body))
5. Once this script is placed in a data lab notebook, the user will be able to construct a relative URL of the following format:
/data-lab/{project_uuid}/sdl/api/notebooks/{notebook_name}/endpoints/{endpoint_path}?{query_string}
Once variables in this URL are replaced with real values from the data lab notebook, the URL will need to be set in the following configuration setting: Features/Notifications/ConditionMonitors/OutgoingWebhookUrl
. Only one webhook URL is currently supported.
6. Finally, to make the script work, the user needs to create a new Slack App that will post messages to a selected channel. For this step Slack has thorough documentation and guided tutorials. Some helpful resources are:
https://api.slack.com/,
https://api.slack.com/apps,
https://api.slack.com/messaging/sending,
https://slack.dev/python-slack-sdk/webhook/index.html,
https://api.slack.com/reference/block-kit/block-elements.
Once a user has created and configured the Slack App, Slack will provide a webhook URL that will replace the URL on line 68 in the data lab script provided above.
An example Slack message received after implementing the sample project:
😱 SaaS Application Alerts:
Condition: Chocolate is lacking some sugar
Start: 2021-03-12 11:05:05
Customer: ChocolateFactory
Domain: MagicLand
Server: MagicServer1
Also see this youtube video where a Microsoft Teams integration was deployed: https://www.youtube.com/watch?v=ksghY0bWGHc