Trigger Slack notifications as an Action
This guide will help you trigger Slack notifications as an ActionA Python class with a run method that takes a Validation Result and does something with it. It will allow you to send a Slack message including information about a Validation ResultGenerated when data is Validated against an Expectation or Expectation Suite., including whether or not the ValidationThe act of applying an Expectation Suite to a Batch. succeeded.
Great Expectations is able to use a Slack webhook or Slack app to send notifications.
Prerequisites
- For Webhook
- For App
- Completion of the Quickstart guide.
- A working installation of Great Expectations.
- A Slack app with the Webhook function enabled. See Sending messages using Incoming Webhooks.
- A Webhook address for your Slack app.
- A Slack channel to send messages to.
- A Checkpoint configured to send the notification.
- Completion of the Quickstart guide.
- A working installation of Great Expectations.
- A Slack app with a Bot Token. See Sending messages using Incoming Webhooks.
- A Bot Token for your Slack app.
- A Slack channel to send messages to.
- A Checkpoint configured to send the notification.
Edit your configuration variables to include the Slack webhook
Open
uncommitted/config_variables.yml
file and
add
validation_notification_slack_webhook
variable by adding the following line:
validation_notification_slack_webhook: [address to web hook]
Include the
send_slack_notification_on_validation_result
Action in your Checkpoint configuration
Open the .yml
configuration file in
great_expectations/checkpoints
that
corresponds to the
CheckpointThe primary means for validating data in a
production deployment of Great Expectations.
you want to add Slack notifications to.
Add the
send_slack_notification_on_validation_result
Action to the action_list
section of the
configuration. Make sure the following section exists
in the Checkpoint configuration.
- For Webhook
- For App
Webhook config
action_list:
#--------------------------------
# here is what you will be adding
#--------------------------------
- name: send_slack_notification_on_validation_result # name can be set to any value
action:
class_name: SlackNotificationAction
# put the actual webhook URL in the uncommitted/config_variables.yml file
slack_webhook: ${validation_notification_slack_webhook}
notify_on: all # possible values: "all", "failure", "success"
notify_with: # optional list containing the DataDocs sites to include in the notification. Defaults to including links to all configured sites.
renderer:
module_name: great_expectations.render.renderer.slack_renderer
class_name: SlackRenderer
Slack bot config
action_list:
#--------------------------------
# here is what you will be adding
#--------------------------------
- name: send_slack_notification_on_validation_result # name can be set to any value
action:
class_name: SlackNotificationAction
# put the actual bot token in the uncommitted/config_variables.yml file
slack_token: {bot_token}
slack_channel: <channel-name>
notify_on: all # possible values: "all", "failure", "success"
notify_with: # optional list containing the DataDocs sites to include in the notification. Defaults to including links to all configured sites.
renderer:
module_name: great_expectations.render.renderer.slack_renderer
class_name: SlackRenderer
Test your Slack notifications
Run your Checkpoint to Validate a BatchA selection of records from a Data Asset. of data and receive Slack notification on the success or failure of the Expectation Suite'sA collection of verifiable assertions about data. Validation. See Run your Checkpoint.
If successful, you should receive a Slack message that looks like this:
Additional notes
-
If your
great_expectations.yml
contains multiple configurations for Data DocsHuman readable documentation generated from Great Expectations metadata detailing Expectations, Validation Results, etc. sites, all of them will be included in the Slack notification by default. If you would like to be more specific, you can configure thenotify_with
variable in your Checkpoint configuration. -
The following example will configure the Slack
message to include links Data Docs at
local_site
ands3_site
.
# Example data_docs_sites configuration
data_docs_sites:
local_site:
class_name: SiteBuilder
show_how_to_buttons: true
store_backend:
class_name: TupleFilesystemStoreBackend
base_directory: uncommitted/data_docs/local_site/
site_index_builder:
class_name: DefaultSiteIndexBuilder
s3_site: # this is a user-selected name - you may select your own
class_name: SiteBuilder
store_backend:
class_name: TupleS3StoreBackend
bucket: data-docs.my_org # UPDATE the bucket name here to match the bucket you configured above.
site_index_builder:
class_name: DefaultSiteIndexBuilder
show_cta_footer: true
# Example action_list in Checkpoint configuration
action_list:
- name: send_slack_notification_on_validation_result # name can be set to any value
action:
class_name: SlackNotificationAction
# put the actual webhook URL in the uncommitted/config_variables.yml file
slack_webhook: ${validation_notification_slack_webhook}
notify_on: all # possible values: "all", "failure", "success"
#--------------------------------
# This is what was configured
#--------------------------------
notify_with:
- local_site
- s3_site
renderer:
module_name: great_expectations.render.renderer.slack_renderer
class_name: SlackRenderer