Expand description
Webhooks: the server says what it noticed to where a manager already is.
Alerts made the server notice things on its own (ADR 0018), and then wait on a dashboard for somebody to open it. This module takes the same record outward - to a Slack or Mattermost channel, a Telegram chat, or a system of the operator’s own - without replacing it: delivery is added to the record, and the row an alert wrote is what gets sent.
Three decisions shape everything here (ADR 0019):
- Destinations live in the environment, not in the database. A hook URL
and a bot token are working credentials to post as somebody, and the
database is what
kasl-server backupwrites to a file. They sit next to the database password, inKASL_WEBHOOK_<NAME>, and everything else - the delivery log, the screen, the privacy manifest - knows a destination by its name alone. - An event is queued in the transaction that made it true. The alert row and the delivery row commit together, or neither does. An in-memory channel loses what was queued on every restart, and “the server restarted at the moment the agent died” is exactly the night nobody hears about.
- Delivery is at least once, in order, per destination. The dispatcher retries with growing gaps and gives up in writing after about a day; a destination that is failing holds its own later events back rather than letting “resolved” overtake “raised” in somebody’s channel. Every event carries an id a receiver can deduplicate on, because a request that timed out may still have arrived.
Structs§
- Alert
Payload - An alert as it fired. The figures are the ones it fired on, never re-derived: a message already read must not change under its reader (ADR 0018).
- DayPayload
- A day as it arrived finished.
- Delivery
View - One delivery, newest first on the screen.
- Destination
- One place events are sent.
- Destination
View - One destination, as the screen shows it.
- Dispatched
- What one tick did.
- Event
- One thing that happened, as every destination is told it.
- Overview
- The screen: where events go, and how the last ones went.
- Person
- The person an event is about.
- Webhooks
- Every destination this installation sends to, and where its screens live.
Enums§
Constants§
- PAYLOAD_
VERSION - The payload’s shape. A receiver of the
jsonkind reads this first; a change to what a field means is a new number, not a quiet edit. - PREFIX
- The prefix every destination’s variable starts with.
Functions§
- client
- The HTTP client every delivery goes through.
- dispatch_
due - Sends everything that is due, once.
- enqueue
- Queues an event for every destination that hears it and may hear about this person. Returns how many rows were written.
- hmac_
sha256 - HMAC-SHA256 of
messageunderkey(RFC 2104). - overview
- Answers the destinations and the recent deliveries. Administrators only: the log names people and the screen names where their alerts go.
- person
- Reads who an event is about.
- run_
dispatcher - Runs the dispatcher for as long as the server runs.
- send_
test - Queues a test message for one destination. Administrators only.
- signature
- The
X-Kasl-Signatureheader’s value for a body sent attimestamp(seconds since the epoch).