Examples
Let's look at a few subscription examples. The first example sends a message to a Slack channel when an event occurs. The second example calls an external API when an event occurs. The third example sends an email when an event occurs.
Send a Message to a Slack Channel
Your operations team needs to quickly respond to data SLA alerts. You want to create a subscription to send messages to an Operations Slack channel each time a data SLA alert triggers.
- Configure Slack for incoming webhooks for the channel you want to use.
At the time of writing, you can enable webhooks in Slack starting from this page. When you enable webhooks, Slack generates a URL for you to use. If you have already enabled webhooks, check your account information for the Slack URL.
- Copy the URL that Slack generates.The URL looks something like this:
https://hooks.slack.com/services/<random string>/<random string>/<random string>
- Create a subscription in Control Hub, selecting the data SLA triggered event.
- Under Actions, make the following configurations:
- Select the Webhook action.
- Select the POST HTTP method.
- Enter the generated Slack URL.
- Enter application/json for the content type.
- Enter the payload text, using the Slack instructions for how to configure the payload.
For Slack, you can accept the defaults for everything else.
Here's how the configured Slack webhook action might look:
Call an External API
You can configure a subscription to call an external API when an event occurs. For example, you could call an API that you have designed that generates a weekly summary report of all job status changes. The API requires the job name, time that the job status change occurred, and the changed status sent in JSON format. You simply use parameters to configure the payload to send those values to the API.
The API requires basic authentication, so you'll need to enter an authorized user name and password when you configure the subscription.
- Create a subscription in Control Hub, selecting the job status change event.
- Under Actions, select the Webhook action and the POST HTTP method.
- Enter the URI to call the external API, for
example:
http://api.my.server/rest/v2/trackControlHubJobStatus
- Enter application/json for the content type.
- In the payload, enter the data that the API expects in JSON format, for
example:
{ "data": { "job":"{{JOB_NAME}}", "datetime":"{{TRIGGERED_ON}}", "status":"{{TO_STATUS}}" } }
- Select Basic for the authentication type and enter an
authorized user name and password.
Here's how the configured API webhook action might look:
Sending an Email
You can configure a subscription to send an email when an event occurs. For example, you can send an email to the organization administrator when someone commits a pipeline.
- Create a subscription in Control Hub, selecting the pipeline committed event.
- Under Actions, select the Email action.
- Enter the email subject line and the email recipients.
- In the body, enter the message to send, for example:
{{PIPELINE_COMMITTER}} committed the {{PIPELINE_NAME}} pipeline on {{PIPELINE_COMMIT_TIME}}.
Here's how the configured email action might look: