Alerts
An alert watches one query's result and tells you when it crosses a line.
How it works
An alert is checked after its query runs, not on a timer of its own. An alert on a query that is not scheduled only fires when somebody runs the query — which is the single most common surprise, and the fix is to give the query a schedule.
It reads one column — its value in the first row, or its minimum or maximum across rows — compares it, and is then either triggered or ok. Notifications are sent on the change between those states, not on every check, so a metric sitting above its threshold for a day is one message rather than a hundred.
Setting one up
- Write a query returning the number you care about. One row is easiest.
- New Alert, choose the query, the column, the comparison and the value.
- Add destinations — email, Slack, a webhook, and others.
- Optionally write a custom template for the message.
Rearm
How long before a still-triggered alert notifies again. Zero means it tells you once and stays quiet until it recovers and trips a second time.
Muting
Mute stops the messages without stopping the watching. The alert still runs after its query, still moves between triggered and ok, and its page still says which it is — nobody is sent anything while it is muted. That is the difference between muting a noisy alert and deleting it: unmute, and it tells you about now rather than replaying what it missed.
It is for the alert everybody already knows about — the migration running this afternoon, the backfill that will hold revenue flat until Tuesday. An alert nobody ever wants unmuted is an alert to delete.
Who else gets told
Anybody who can see the alert can subscribe themselves to it, and being the owner does not subscribe you — somebody can build an alert for a team and stay off it. A subscription names a destination: the Slack channel, webhook or address an administrator added under Settings → Alert Destinations.
A new alert’s destinations are empty, and say that nobody is told: no address is filled in or shown for anyone. The subscriptions are listed on the alert itself, which is where one is removed. A destination belongs to the organization rather than to the alert, so taking it off one alert leaves every other alert using it alone.
Post to a Slack channel, under the list, is the quicker way where Slack is connected: pick a channel from the ones the app is in and the alert posts there. It uses that channel’s Slack (app) destination if there is one — twenty alerts to #ops share one — and makes it if there is not, so nobody has to ask an administrator first. An administrator making a Slack (app) destination by hand picks the channel from the same list.
Changed in 0.8. Subscribing used to mean being emailed: a subscription
with no destination quietly sent mail to the subscriber's own address, whether or not anybody wanted
mail and whether or not the install had a mail server. Email is now a destination like any other
— add one and pick it. An install that was relying on the old behaviour can set
SQLDESK_ALERT_EMAIL_FALLBACK=true while its alerts are given destinations; a subscription
skipped for want of one says so in the log.
What a Slack message says
A message reading "Orders just triggered" tells you the one thing you already knew from the fact that it arrived. Since 0.8 the first line carries the number:
Orders: 87, below 100
Fired 3 times in the last 24 hours · the alert · the query
The reading and the line it crossed, so the message can be acted on without opening a browser. The 24-hour count appears only when the alert has gone off more than once, because four fires and four recoveries in an afternoon is a different problem from one fire that stayed — and a single message cannot tell them apart. A muted alert says it is muted, so nobody assumes the team was told.
A custom subject replaces that first line entirely: somebody who wrote one has said what they want it to read.
Two Slack destinations exist, and both say the same thing:
| Destination | Needs | Carries pictures |
|---|---|---|
| Slack | An incoming webhook URL | No — a webhook cannot upload a file. Where a picture was drawn, the message says so rather than dropping it silently. |
| Slack (app) | The app installed under Settings → Slack | Yes |
Attachments
An alert can carry pictures of up to five dashboards or queries, rendered by a headless browser. It is off unless a renderer is configured, and the published image does not include one — it runs in its own optional container.
Any dashboard can be pictured; it does not have to be shared first. The renderer is let in with a pass good for that one dashboard, for five minutes, read-only, and spent as soon as the picture is taken. Access is checked against the alert’s owner each time, so an attachment stops arriving if they lose sight of it.
Email and Slack (app) carry the pictures; the Slack webhook cannot. An incoming webhook has no way to upload a file, so an alert sent through it says a threshold was crossed and shows nothing — which for an alert on a chart is most of the information missing. The Slack (app) destination posts as the app an administrator connected under Settings → Slack and uploads them. Both destinations exist: the webhook needs nothing but a URL, and this needs the app.
A picture that will not upload never stops the alert — the threshold was still crossed and somebody still needs to know — but the message says which one is missing, because an alert about a chart arriving with no chart and no explanation reads as the alert being broken.
Writing the message
An alert sends a default message unless you give it one. Under Notification template
on the alert, a subject and a body, both Mustache
— {{ VARIABLE }} is filled in, everything else is sent as you typed it.
What you can put in it
| Variable | What it is |
|---|---|
{{ALERT_NAME}} | The alert’s name. |
{{ALERT_URL}} | A link to the alert. |
{{ALERT_STATUS}} | TRIGGERED, OK or UNKNOWN. |
{{ALERT_CONDITION}} | The operator: >, <, ==… |
{{ALERT_THRESHOLD}} | The number it is compared against. |
{{ALERT_SELECTOR}} | Which row is read: first, min or max. |
{{QUERY_NAME}} | The query behind it. |
{{QUERY_URL}} | A link to that query. |
{{QUERY_RESULT_VALUE}} | The value that was tested — usually the one you want. |
{{QUERY_RESULT_ROWS}} | Every row, for looping over. |
{{QUERY_RESULT_COLS}} | The column definitions. |
{{QUERY_RESULT_TABLE}} | The rows as an array of arrays, for building a table. |
Formatting for Slack
Slack does not use Markdown. It uses its own mrkdwn, and the differences are the ones that bite:
| You want | Slack wants | Not |
|---|---|---|
| A link | <https://example.com|the dashboard> | [the dashboard](https://example.com) |
| Bold | *bold* | **bold** |
| Italic | _italic_ | *italic* |
| Strikethrough | ~struck~ | ~~struck~~ |
| Code | `code` | — the same |
| Mention a person | <@U024BE7LH> | @name |
| Mention a channel | <!channel> | @channel |
A link is the thing worth getting right. It is the way to put a dashboard in an alert without a picture, and it works on every Slack destination including the webhook:
{{ALERT_NAME}} is at {{QUERY_RESULT_VALUE}}, past {{ALERT_THRESHOLD}}.
<{{QUERY_URL}}|Open the query> · <https://sqldesk.example.com/dashboards/12-orders|The orders board>
The query’s own link comes from a variable. A dashboard’s does not — an alert belongs to a query, and does not know which dashboards you consider related — so paste the dashboard URL from your browser.
A table of the rows
Mustache loops, so a short result can be sent in full. Slack has no table, but a code block keeps columns under each other:
```
{{#QUERY_RESULT_TABLE}}{{.}}
{{/QUERY_RESULT_TABLE}}
```
Keep it short. Slack truncates a message block at 3000 characters, and a hundred rows in a notification is a report somebody has to scroll rather than an alert they can act on.
What is escaped, and where
Values are escaped for where they are going; the words you type are never touched. In an HTML email a
result containing & or < is escaped, because it is text rather than
markup. For Slack it is sent as it is — otherwise a value with an & in it would
arrive reading &.
So a <url|label> you type works on Slack, and the same template sent by email shows
the angle brackets. A template written for Slack is written for Slack; if an alert goes
to both, write it for the one that matters and accept the other reads plainly.