SMS alert notifications

Alert notifications can be delivered from Seq via SMS by using a third-party SMS service and the new Seq.App.HttpRequest Seq app.

The following query shows the amount of product added per hour:

Seq events screen with query "select sum(Product.SizeInGrams) / 1000 as kg from stream group by time(1h)"

When this amount exceeds 1,600kgs I want to be notified on my phone ๐Ÿ’ฅ.

Configuring an SMS provider

SMS can be sent by calling the API of one of the SMS providers. I've setup a free account with Twilio. Once setup, Twilio provides an API endpoint to call like:

https://api.twilio.com/2010-04-01/Accounts/Axxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Messages.json

and a secret AuthToken.

Configuring an App to make API requests

To integrate with Twilio I will use the Seq.App.HttpRequest Seq app. Install the app in the usual way, then add an instance to the app. The URL setting should be the URL from Twilio.

To authenticate with Twilio set the HTTP Authorization header using basic authentication. ย Basic authentication requires a header called Authorization with a value that is the word Basic followed
by username:password base64 encoded. The JavaScript function btoa base64 encodes a string, so building an Authorization header could look like this (not my real password):

let username = "bob";
let password = "P@ssw0rd";

`Authorization: Basic ${btoa(`${username}:${password}`)}`

Which produces the value Authorization: Basic Ym9iOlBAc3N3MHJk. Once you have constructed your header string enter it into the Authentication Header setting.

The content of the text message that is sent is determined by the Body setting. Body can be literal text, or it can be built from a template (if the Body is a template checkbox is checked).

The template language is similar to the one used by Serilog. Variables available include the CLEF reified properties such as @m (message), @t (timestamp), @x (exception) and @p (properties) of the event that caused the alert. There is also Alert.Query (the query that drives the alert) and Source.ResultsUrl - a URL to the query and its results.

Twilio expects a form encoded request body, with the variables:

  • To - The URI encoded number to send the SMS to
  • MessagingServiceSid - The Twilio messaging service identifier
  • Body - The message to send

I'm including the event message, exception and URI encoded Source.ResultsUrl:

Configuring a Seq app to make HTTP requests

Creating the Alert

From my query for the amount of product added per hour, clicking the "magical" bell button creates a new alert.

Creating an Alert that sends SMS messages

Give the alert a name, set any other setting you wish and set the Output app instance setting to your Seq.App.HttpRequest app instance. Now when the alert condition is triggered it will pass the event to the Seq.App.HttpRequest app, which will post to Twilio, which will send an SMS message.

SMS triggered from Seq alert and sent via HttpRequest app

Further possibilities

Seq.App.HttpRequest is not limited to sending text messages. It is a general purpose utility that connects Seq to the web. It can add cards to Trello, add GitHub issues, create calendar requests, insert data into Google Sheets and generally connect Seq to anything with an API. I even tried, unsuccessfully, to use it to order donuts:

If anyone finds a way to order snacks with an API please let me know.

We'd love to hear your questions and comments on Seq.App.HttpRequest. What will you build with it? ๐Ÿ˜Ž

Liam McLennan

Read more posts by this author.