CsvPath Framework
  • CsvPath
  • DATA PREBOARDING
  • Getting Started
    • Quickstart
    • Organizing Inbound Data
      • Dataflow Diagram
      • The Three Data Spaces
        • Source Staging
        • Validation Assets
        • Trusted Publishing
      • How Data Progresses Through CsvPath Framework
        • Staging
          • Data Identity
          • Handling Variability
            • Templates
            • Named-file Reference Queries
          • Registration API and CLI
            • Loading
            • Going CLI-only
        • Validation and Upgrading
          • Templates
          • Run Using the API
          • Running In the CLI
          • Named-paths Reference Queries
        • Publishing
          • Inspect Run Results
            • Result API
            • More Templates and References
          • Export Data and Metadata
    • Csv and Excel Validation
      • Your First Validation, The Lazy Way
      • Your First Validation, The Easy Way
      • Your First Validation, The Hard Way
    • DataOps Integrations
      • Getting Started with CsvPath + OpenTelemetry
      • Getting Started With CsvPath + OpenLineage
      • Getting Started with CsvPath + SFTPPlus
        • SFTPPlus Implementation Checklist
      • Getting Started with CsvPath + CKAN
    • How-tos
      • How-to videos
      • Storage backend how-tos
        • Store source data and/or named-paths and/or the archive in AWS S3
        • Loading files from S3, SFTP, or Azure
        • Add a file by https
        • Store source data and/or named-paths and/or the archive in Azure
        • Store source data and/or named-paths and/or the archive in Google Cloud Storage
      • CsvPath in AWS Lambda
      • Call a webhook at the end of a run
      • Setup notifications to Slack
      • Send run events to Sqlite
      • Execute a script at the end of a run
      • Send events to MySQL or Postgres
      • Sending results by SFTP
      • Another (longer) Example
        • Another Example, Part 1
        • Another Example, Part 2
      • Working with error messages
      • Sending results to CKAN
      • Transfer a file out of CsvPath
      • File references and rewind/replay how-tos
        • Replay Using References
        • Doing rewind / replay, part 1
        • Doing rewind / replay, part 2
        • Referring to named-file versions
      • Config Setup
      • Debugging Your CsvPaths
      • Creating a derived file
      • Run CsvPath on Jenkins
    • A Helping Hand
  • Topics
    • The CLI
    • High-level Topics
      • Why CsvPath?
      • CsvPath Use Cases
      • Paths To Production
      • Solution Storming
    • Validation
      • Schemas Or Rules?
      • Well-formed, Valid, Canonical, and Correct
      • Validation Strategies
    • Python
      • Python vs. CsvPath
      • Python Starters
    • Product Comparisons
      • The Data Preboarding Comparison Worksheet
    • Data, Validation Files, and Storage
      • Named Files and Paths
      • Where Do I Find Results?
      • Storage Backends
      • File Management
    • Language Basics
    • A CsvPath Cheatsheet
    • The Collect, Store, Validate Pattern
    • The Modes
    • The Reference Data Types
    • Manifests and Metadata
    • Serial Or Breadth-first Runs?
    • Namespacing With the Archive
    • Glossary
  • Privacy Policy
Powered by GitBook
On this page
  • Event Types
  • Configuring Listeners
  • Using Csvpath-by-csvpath Webhooks
  • A Reminder About Validity
  1. Getting Started
  2. How-tos

Setup notifications to Slack

Send yourself notifications about CsvPath runs via Slack webhooks

PreviousCall a webhook at the end of a runNextSend run events to Sqlite

Last updated 5 months ago

CsvPath can send alerts to Slack as run events happen. It looks basically like this:

Event Types

To recap, there are five event types. Each event goes to listeners. CsvPath has its own listener that creates new or updated manifests. The types are:

  • Named-file staging: a file event is fired at the time you add a file to the file inputs directory using the file manager.

  • Named-paths loading: a paths event is fired when you load a named-paths group into the inputs directory using the paths manager.

  • Run start: when a run starts a run notification indicates at the highest-level the inputs and start time. It tells you that an activity is happening in the archive.

  • Results available: results events are fired when at the beginning and end of a named-paths group run. It is summary-level information about the group's progress.

  • Result available: a result event is fired when an instance of a csvpath in a named-paths group starts or completes. This is the most detailed event.

Configuring Listeners

All of these events are received by all listeners configured in config/config.ini to listen for events of a type. For example, the Marquez OpenLineage listeners are configured like this:

marquez.file = from csvpath.managers.files.file_listener_ol import OpenLineageFileListener
marquez.paths = from csvpath.managers.paths.paths_listener_ol import OpenLineagePathsListener
marquez.result = from csvpath.managers.results.result_listener_ol import OpenLineageResultListener
marquez.results = from csvpath.managers.results.results_listener_ol import OpenLineageResultsListener

There is a Slack listener that can receive any of those same four events. (Neither Marquez or Slack support the very general run event). To configure Slack you simple add any or all of these lines to your config.ini file:

slack.file = from csvpath.managers.integrations.slack.sender import SlackSender
slack.paths = from csvpath.managers.integrations.slack.sender import SlackSender
slack.result = from csvpath.managers.integrations.slack.sender import SlackSender
slack.results = from csvpath.managers.integrations.slack.sender import SlackSender

You will also need to add or update a [slack] section to say what webhook you want the events to go to. That looks like this:

[slack]
# add your main webhook here. to set webhooks on a csvpath-by-csvpath basis add
# on-valid-slack: webhook-minus-'https://' and/or
# on-invalid-slack: webhook-minus-'https://'
webhook_url =

Obviously you need to add your webhook URL.

And finally you need to tell CsvPath that you want the slack group of event listeners to receive events. Do that by adding slack to the groups key in the [listeners] section of config.ini.

[listeners]
groups = slack, marquez

Using Csvpath-by-csvpath Webhooks

As the comments in your config file say, you can also configure the result Slack events on a csvpath-by-csvpath basis. Only the result events can be configured by a csvpath. That is because a result event is tied to a single csvpath; whereas, the other events apply to named-paths groups of csvpaths or to input files.

Within your csvpath you need an external comment. An external comment is one that is above or below the csvpath, not within the match part of the csvpath. In the external comment you may use one or both of the custom metadata fields that the Slack integration knows to look for:

  • on-valid-slack:

  • on-invalid-slack:

The value of the field is a webhook URL. When you add these fields remember to only give the URL starting with the subdomain and domain. So rather than:

https://hooks.slack.com/services/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

You just use:

~
id: Slack example
on-valid-slack: hooks.slack.com/services/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
~
$[*][print("hello world!")]

The reason to use the shorter form is because a full URL has a protocol signifier that includes a colon. Since CsvPath metadata fields are defined as names followed by a colon, https://... looks to CsvPath like a metadata field named https.

If neither of these metadata fields is present, your event will go to the default URL in config/config.ini. As you would guess, if your csvpath is valid — per the valid field in the metadata collected during the run — the on-valid-slack webhook is called. If not valid the on-invalid-slack webhook gets the call.

A Reminder About Validity

And in case you don't remember, you set the valid value using the fail() function.

A csvpath is considered valid by default. Under certain circumstances it may have indications that something is wrong (e.g. the expected files not generated and stopped early indicators) which generally you see in the metadata and/or as errors in errors.json. But unless you explicitly say a file is invalid, it is valid.

That said, bear in mind that built-in validations, when tripped, can mark a file as invalid. For example, if you try to add("five", none()) you will raise an error and depending on your , your file may be marked invalid without you having to do anything. In that case, if you had on-invalid-slack configured with a webhook, you would get an alert.

mode settings