In this article, we'll describe the configuration of alerts to use classic webhooks (henceforth, simply "webhooks"). Additionally, for those unfamiliar with webhooks or who will benefit from constructing a quick example, we provide information to set up a test web service using Heroku. For reference, we've also included example POST body data at the end of this article.
Configuring Webhook Notifications
To configure notifications to a webhook server, you'll need to define a webhook in Alerts > Alert Rules. Expand an alert rule and select the Notifications tab. Under the Webhooks section, click the Configure Webhooks link. If you already have configured webhooks, click the Edit webhooks link:
Click Add New Webhook, then complete the New Webhook dialog:
Enter the Name of your Webhook, and the target URL (note that HTTP redirects are not accepted, so be sure to provide the final URL). Configure required authentication if required, and click Test to check your configuration:
NOTE: Encoded HTML URLs are currently not supported for webhook configuration. Enter the URL in decoded form. If the test succeeds, a Webhook test completed successfully message displays:
Once you have tested your webhook server successfully, click Add New Webhook, and select your webhook from the list of configured webhooks. You can add any number of custom, static key-value pairs to the webhook payload. These custom payloads can be used on any Cloud or Enterprise Agent alert type and are specific to the selected alert rule.
To add these elements, navigate to an individual alert rule, select a webhook, and click Add Custom Payload (1). A key-value pair (2) field appears that allows you to enter any static key-value pair. You can add or remove these payloads using the - and + buttons (3).
Additionally, this change adds two new fields to the webhook payload: testLabels, which includes test label name and ID, as well as testTargetsDescription, which includes the description of the test target as defined in the test configuration.
Webhook Authentication
The webhook interface supports the use of a token, OAuth, and basic HTTP authentication. This is an optional configuration step and can be configured for a webhook service if the target server requires authentication.
Basic
A Username and corresponding Password are necessary to configure Basic HTTP Authentication:
Token
The Token Auth Type uses a Bearer Token to authenticate with the webhook server:
OAuth
Webhook Server-Side Configuration
Create a new OAuth endpoint for ThousandEyes Alerts with https://app.thousandeyes.com/webhooks-oauth-callback as redirect/call back URL. Grab the newly created Client ID and Authorization Endpoint URL (Auth URL) for the webhook server to configure ThousandEyes-side authentication.
NOTICE: Ensure that the token has a sufficient lifespan to avoid manual regeneration on timeout.
ThousandEyes-Side Configuration
Configure the webhook Name and URL as explained in the Configuring Webhook Notifications section. Click OAuth in Auth Type. Fill out the Auth URL and Client ID according to the Webhook Server-Side Configuration section above. Click Get Token:
A new tab opens, requesting consent to authorize ThousandEyes. Below is a snippet from ServiceNow application that we are using in this guide as an example:
Once the authorization is complete, a Token retrieved successfully message is displayed, as shown in the following figure:
Now click Test to verify the operability of your new webhook:
Setting Up a Webhook Server
If you visit Heroku, you can deploy a free web application. If you're new to Heroku, it's worth running through their instructional tutorials to understand how the deployment process works. Follow these instructions to deploy a simple version of your web service.
$ git clone https://github.com/my-organization/my-webhook-server.git
Then, move to the directory created.
```text
$ cd my-webhook-server
Create a Heroku remote in your git repository.
$ heroku create
Push your content to the Heroku remote. This will build the application.
$ git push heroku master
Open the site to confirm the target location. This opens a web browser in the context of your Heroku application.
$ heroku open
Open a console to review the logs of the target server. In this window, you'll see POST requests hitting your server.
$ heroku logs --tail
2014-11-11T20:33:42.767724+00:00 heroku[api]: Deploy e5d1a07 by dave@thousandeyes.com
2014-11-11T20:33:42.767753+00:00 heroku[api]: Release v15 created by dave@thousandeyes.com
2014-11-11T20:33:43.724332+00:00 heroku[web.1]: State changed from up to starting
2014-11-11T20:33:46.814245+00:00 heroku[web.1]: Starting process with command `node webhook-server.js`
2014-11-11T20:33:50.439787+00:00 heroku[web.1]: State changed from starting to up
2014-11-11T20:33:50.347118+00:00 app[web.1]: Webhook Server started... port: 30490
2014-11-11T20:33:59.586785+00:00 heroku[router]: at=info method=GET path="/" host=sleepy-mesa-2108.herokuapp.com request_id=228650f8-d810-477e-858b-b61235766260 fwd="54.90.223.146" dyno=web.1 connect=2ms service=10ms status=200 bytes=266
Webhook POST Content
Webhooks use events to signify activity. Our system is configured today to support the following types of events:
WEBHOOK_TEST - sent when a user clicks the Test Webhook link in ThousandEyes webhook configuration.
ALERT_NOTIFICATION_TRIGGER - sent when an alert is triggered
ALERT_NOTIFICATION_CLEAR - sent when an alert is cleared, the alert rule is deleted, or the alert rule is removed from a test while in an active alerting status.
Note: All eventIds are unique. To correlate two events (for example, an alert trigger and clear) reference the alertId, which is unique per generated alert.
Agent Webhook Notifications
Notifications sent by agents use the same eventType as regular notifications. See the payload examples for agent notifications in the Sample Webhook Event Payloads section below.
ALERT_NOTIFICATION_TRIGGER - sent when an agent notification triggers - may be related to clock offset, version number, or agent online status
ALERT_NOTIFICATION_CLEAR - sent when the agent notification clears
Note: All eventIds are unique. To correlate two events (for example, an alert trigger and clear) reference the alertId, which is unique per generated alert.
Sample Webhook Event Payloads
Each event type shown below contains a sample JSON payload, which is posted to the target server. The Alert notification data corresponds to alerting data from the ThousandEyes API, wrapped in an event wrapper. See the ThousandEyes Developer site for more information on data returned via the API.
If your web server only allows requests from allowlisted senders, you will need to allow requests from ThousandEyes web servers. You can find the list of allowed IP addresses at Firewall Exception Requirements.