Code: Notifications and alerting with Jennifer
Alerting with Gotify, Telegram, Slack and Discord: the code
The programs behind the slides. They use the @deckyard/gotify, @deckyard/telegram, @deckyard/slack and @deckyard/discord decks, listed in deck.toml, so run jvc install once in this folder to fill vendor/. Run everything from this folder with Jennifer 0.27.0.
Nothing here talks to the real services: mock.j stands in for all four on 127.0.0.1:28790, and .env.test points every channel at it. The tokens and webhook URLs in the .env.* files are placeholders.
deck.toml: the jvc manifest with the four decks ("Set up").alerts.j: the module behind most slides. OneAlert, routed to every configured channel; priority, chat id and parse mode, Block Kit, embeds; retries on 429 withRetry-Afterand Telegram'sretry_after; anAlertErrorwhen a channel gives up ("Gotify: the priority is the urgency", "Telegram: chat ids and parse modes", "Slack: an Incoming Webhook and Block Kit", "Discord: webhooks and embeds", "One alert, routed by severity", "Fan out: one broken channel must not stop the rest", "Rate limits: 429 and Retry-After", "Telegram's flood control, in the same loop"). It is a module;once.janddiskcheck.jimport it.mock.j: the fake Gotify, Telegram, Slack and Discord on one port. It logs every request and, withMOCK_LIMIT=slack(ordiscord,telegram,gotify), answers the first request to that service with a 429 ("Testing alerts against a mock server", "What Slack and Discord received"). Run:jennifer run mock.j 28790 &once.j: sends one critical alert to every configured channel, with the settings from.envfiles ("Keep the secrets out of the code"). Run, with the mock running:JENNIFER_ENV=test MOCK_LIMIT=slack jennifer run once.j.env.test: every channel pointed at the mock..env.broken: every channel broken in a different way, for "What each deck throws". Run:JENNIFER_ENV=broken jennifer run once.j(with the mock running).run.sh: starts the mock, runs one program, stops the mock and prints its log. Example:JENNIFER_ENV=test ./run.sh once.jdiskcheck.j: alerts once when a filesystem crosses a threshold and once when it recovers, keeping the last state indiskcheck.state("A disk check that alerts once", "Four runs"). Needsdf(theexeccapability). Run, with the mock running:JENNIFER_ENV=test jennifer run diskcheck.j / 80 90alerts_test.j: unit tests with an in-process fake server on a free port ("The same idea as unit tests"). Run:jennifer test alerts_test.j
| File | Size | |
|---|---|---|
| .env.broken | 365 B | in the zip |
| .env.test | 383 B | in the zip |
| LICENSE | 899 B | raw |
| README.md | 2.5 KiB | raw |
| alerts.j | 6.7 KiB | raw |
| alerts_test.j | 2.4 KiB | raw |
| deck.toml | 332 B | raw |
| diskcheck.j | 3.1 KiB | raw |
| mock.j | 3.5 KiB | raw |
| once.j | 579 B | raw |
| run.sh | 312 B | raw |