Send SMS alerts with customizable WebHooks and Twilio

Send SMS alerts with customizable WebHooks and Twilio

/ / /
Published: July 31, 2014

When a metric alert is triggered, you want your team to know as quickly as possible. One common way to do this is to use SMS; it is ubiquitous and will get your team’s attention quickly. Datadog already supports alerting using third party services such as PagerDuty, OpsGenie and VictorOps, or HipChat chat room notifications. Sometimes, though, you just want to send an SMS directly and we have made it very easy to integrate with services such as Twilio to do just that.

We’re pleased to announce our new customizable WebHooks, which now allow you to send custom payloads to third party web services via HTTP Post.

In this blog post, we’ll show how to add SMS as a Datadog alert notification. Importantly, this new functionality can be used in a variety of other circumstances to push messages out of Datadog. Don’t hesitate to reach out to our support team with any questions about a WebHook setup.

Twilio WebHooks in Datadog

In order to send a Datadog alert as an SMS directly to a person’s phone, we’re going to use Twilio’s API to programmatically send text messages. First, let’s sign up for a Twilio account. We’ll need the Account SID and Auth Token (available on the Account page) as well as the phone number we get assigned from Twilio (see Incoming Phone Numbers).

Send Datadog alerts by Twilio SMS with WebHooks
Account credentials (anonymized)

Then, we’ll take a look at Twilio’s API to see what fields are required and to what URL we need to send the information. We will use this information in the Datadog WebHooks configuration page, where we will create a WebHook for this. Using the custom payload option, we’ll specify a custom payload adapted to Twilio’s format.

Because authentication is needed for Twilio to accept our payload, we will place our Account SID and Auth Token in this HTTPS endpoint, https://{Account-SID}:{Auth-Token}@api.twilio.com/2010-04-01/Accounts/{Account-SID}/Messages.json. In Twilio’s case, their endpoint does not accept a raw JSON payload. Therefore, we will encode the payload as a form and have the data sent in the same parameter=value format a form would send. This sample Datadog WebHooks configuration page shows how to set up the above steps.

Send Datadog alerts by Twilio SMS with WebHooks
WebHooks configuration page

Let’s try our Datadog-Twilio integration by mentioning our WebHook in a simple event triggered from our event stream by typing @webhook-name.

Send Datadog alerts by Twilio SMS with WebHooks
webhook-mention sends an SMS

Adding graphs to an SMS

We can see that it works. Let’s make the SMS more informative by refining the payload. There is much more information associated with a Datadog alert, such as a graph snapshot, description, and timestamp. By customizing the payload to include the path to a graph snapshot, you can send, via text message, a quick link to a snapshot providing a much more actionable alert.

And here is the result.

Send Datadog alerts by Twilio SMS with WebHooks
Link to graph in SMS

Sending Twilio SMS alerts is just an example of what is possible to do with the WebHooks. Other possibilities may be starting a Jenkins job or creating an issue on Jira bug tracker when a certain Datadog alert is triggered.

If you want to add more notification capabilities to Datadog such as sending alerts via text message, and use our WebHooks integration, available here. And, if you build something cool with our templated WebHooks integration, let us know on our Twitter account @datadoghq.


Want to write articles like this one? Our team is hiring!