Discord-compatible webhooks
Many tools can post their notifications to a Discord webhook. Give them Skirl's address in its place, and each post arrives in a topic as a message, with no Discord involved.
Setting it up#
In the app the address is under Connect a system → Discord-compatible, or a topic's Send to this topic tab, with your address, the topic and a token filled in; New token makes the token.
For anything that posts to a Discord webhook, such as Alertmanager's discord_configs: use this as the webhook URL. It answers 204, as Discord does. It cannot send a token header, so the token is in the URL: keep the URL as secret as the token.
- Webhook URL:
https://notify.example.com/chat?template=discord&auth=QmVhcmVyIHRrX3JlcGxhY2Vfd2l0aF95b3VyX3Rva2Vu
Paste it where the tool asks for a Discord webhook URL. It is the topic's address with ?template=discord, which reads the post in Discord's format, and &auth= with the token: these tools cannot send a token any other way, so keep the whole address as secret as the token. Skirl never writes it in its log, and answers 204 with nothing in it, as Discord does. Skirl's tests point Alertmanager 0.35.1's Discord receiver (discord_configs, the address as its webhook_url) at it, and check that firing and resolved alerts arrive readable.
- The post must be JSON. A post with files attached, which Discord takes as a form with the JSON in
payload_json, is refused (400). - Each post is a new message. Nothing is replaced when a problem clears. For Alertmanager, its own sender does that: Alertmanager.
- A tool that takes only addresses on discord.com cannot be pointed here. If it can post JSON to any address, Any webhook may suit it better.
What a message looks like#
What Skirl reads from a post:
| In the post | In the message |
|---|---|
content |
the text, first |
the first embed's title, else its author's name, else the post's username |
the title |
the first embed's description |
the text, next |
the first embed's fields, the first 10 |
a line each, Name: value |
the first embed's footer text |
the text's last line |
the first embed's url |
the address the title opens |
the first embed's color |
the priority |
The colour is the number Discord uses for it. Red ones are priority 4: 16711680 (#FF0000), 15158332 (#E74C3C), 15548997 (#ED4245), 13632027 (#D0021B) and 10038562 (#992D22). Green ones are priority 2: 65280 (#00FF00), 3066993 (#2ECC71), 5763719 (#57F287) and 32768 (#008000). Any other colour, or none, is 3.
Each part is shortened to a length (the title to 250 characters, content and the description to 1500, a field's value and the footer to 200), and the whole message to 4096 bytes: a long post arrives shortened, never refused. Each cut ends with "…" and never splits an accented letter or an emoji. Discord's own formatting, such as **bold**, shows as it is written. A post with none of these parts arrives as the word "triggered".
Alertmanager's Discord receiver, firing, as Skirl's tests record it:
[FIRING:1] DiskAlmostFull discord (nas01:9100 node critical) Alerts Firing: Labels:
- alertname = DiskAlmostFull
- instance = nas01:9100
- job = node
- severity = critical
- via = discord Annotations:
- description = /volume2 on nas01 has 412 GB free of 4.6 TB.
- summary = Volume 2 is at 91% Source: http://prometheus.example:9090/graph?g0.expr=node_filesystem_avail_bytes
Priority 4
Resolved, the title starts [RESOLVED], the text Alerts Resolved:, and the priority is 2. (discord and via = discord are a label the test gives its alerts.)
When nothing arrives#
The tool's log or its test button shows Skirl's answer:
- 401
unauthorized: the token in the address is wrong, revoked or expired. Make a new one with New token, or Rotate, and copy the whole address again: theauth=part changes with the token. - 403
forbidden: the token may not send to this topic, or the address lost its&auth=part when it was pasted. - 400
message body must be JSON if templating is enabled: the tool posts a form, as it does with files (see above). - 413
JSON body too large: the post itself is over 128 KB. - 429: too many posts too fast, or too many failed sign-ins from the tool's address: Rate limits. A tool that keeps posting with a wrong token causes the second.
- No answer at all, or a timeout: the tool cannot reach your server from where it runs.
To tell Skirl from the tool, post a Discord-style message yourself from the machine the tool runs on, here with the token in a header rather than in the address. It prints the status, 204:
curl -w "%{http_code}\n" -H "Authorization: Bearer tk_replace_with_your_token" -H "Content-Type: application/json" -d '{"content":"Hello from curl"}' "https://notify.example.com/chat?template=discord"204The general checks: A sender gets no message through. Every error code: Error messages.