Documentation
¶
Overview ¶
Package notify delivers knell's transition notifications to a Discord webhook. It is the app's only outbound-network package and retries transient delivery failures via httpx.
Wording lives here, not in the state machine: internal/watch decides WHICH transition happened and hands over its own types (watch.Transition for a live incident, watch.Outage for one that is already over), and this package decides how an operator reads it. Every duration a notice reports comes from those types' DownFor, so the live and past-tense notices cannot measure the same span differently.
Index ¶
- Constants
- type Discord
- func (d *Discord) BeatMissing(ctx context.Context, id string, live watch.Transition) error
- func (d *Discord) BeatOutageHistory(ctx context.Context, id string, outages []watch.Outage) error
- func (d *Discord) BeatRecovered(ctx context.Context, id string, live watch.Transition) error
- func (d *Discord) Close()
Constants ¶
const MaxNodeNameBytes = 256
MaxNodeNameBytes is the maximum UTF-8 byte length of NODE_NAME. internal/config enforces this cap so every rendered notification remains within Discord's content limit.
The node name is interpolated into EVERY notice (missing, recovered, history), so an unbounded value makes Discord reject all of them: knell would start, accept beats and detect outages while no notice is ever delivered — a dead-man switch that delivers nothing. Counting BYTES is conservative against Discord's character limit: UTF-8 bytes are always >= the character count and >= the UTF-16 code-unit count. TestEveryNoticeStaysInsideDiscordsContentLimit owns the derivation: it renders every notice shape at its worst case and fails when a wording change eats the budget.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Discord ¶
type Discord struct {
// contains filtered or unexported fields
}
Discord posts plain-content messages to one Discord-compatible webhook.
func New ¶
New builds a Discord notifier for the given webhook URL. node names this observer instance in every message so multi-node deployments read as distinct reports.
func (*Discord) BeatMissing ¶
BeatMissing announces that a beat's deadline of silence has passed.
The wording names what to check without presuming the beat ever pinged: a beat configured in BEATS but never wired to a sender (a typo, a wrong id) fires this very notice one deadline after start, and notify cannot tell that case from a sender that pinged for weeks and stopped — watch.Transition carries only Started and Observed, and Started deliberately collapses "last accepted ping" and the process-start baseline into one field. So the sentence must fit both, and "never pinged at all" is one of the causes it names.
func (*Discord) BeatOutageHistory ¶ added in v1.1.0
BeatOutageHistory announces outages that were already over by the time this observer could send anything about them, in one past-tense message so a resolved incident never reads as a new live failure. One outage is reported on its own; several are summarized, because the point of the message is that they are over, not to replay each of them.
The batch's shape is the caller's contract: watch builds a history notice only from a non-empty run (collectDue collapses one only under `len(run) > 0`, and assertSealedRun iterates the run, so it would pass an empty one vacuously) and asserts the rest record by record before calling (every record ended, every record has a start, recovery points ascend), so nothing here re-checks it: a refusal returns to watch's sendHistory as an ordinary delivery error, which keeps the records queued and re-offered every sweep and holds the beat's live notices behind them, so a producer bug would present as a webhook problem forever.
func (*Discord) BeatRecovered ¶
BeatRecovered announces the first ping after a missing alert.