Add native Slack notification module#3
Conversation
Mirrors the existing email module so Slack delivery is wired into the same four call sites (cleanup_on_exit, handle_sigterm, replicate-only end, normal session end). This means failure-path notifications fire even when a run aborts before the normal end-of-main code path. The two notifiers are independent: SLACK_ENABLED, SLACK_ON_SUCCESS, and SLACK_ON_FAILURE let operators run Slack-only, email-only, or both. Session totals (VMs ok/failed/skipped/excluded, total bytes, duration) are pulled from the same sessions row the email module uses via sqlite_query_session_summary. curl is the only new dependency.
|
Thanks for this, @hostarts — really clean work, and mirroring the email module's shape (same call sites, same data row, default-off, no new deps beyond Heads-up on how it's landing: A couple of small adaptations on the way in: the four notification hooks now route through the current I'm going to close this PR since it can't be merged against the mirror — that's purely a workflow artefact, not a rejection; the feature is in. Thanks again for contributing it. |
Summary
Adds first-class Slack delivery alongside the existing email path. Until now, posting backup results to Slack required wrapping
vmbackup.shinExecStopPostor a cron post-hook, which only sees the systemd$SERVICE_RESULT/$EXIT_STATUSand has to re-derive session totals from the DB out-of-band. With this PR, Slack posts use the samesqlite_query_session_summaryrow the email module uses, fire from the same four call sites (so failure-path notifications still go out when a run aborts before normal end-of-main), and stay enabled/disabled independently of email.What changed
modules/slack_notification_module.sh(new):load_slack_config()+send_slack_notification()mirroringload_email_config()/send_backup_report(). Posts a coloured attachment with VM totals (ok / failed / skipped / excluded), total bytes, duration, and instance name. JSON is built inline; only runtime dependency iscurl.config/template/slack.conf(new):SLACK_ENABLED,SLACK_WEBHOOK_URL,SLACK_HOSTNAME,SLACK_TITLE_PREFIX,SLACK_ON_SUCCESS,SLACK_ON_FAILURE,SLACK_TIMEOUT. Independent flags so Slack-only / email-only / both are all valid combinations.vmbackup.sh: wired Slack into the same four sites as email —cleanup_on_exit(pre-flight aborts),handle_sigterm(systemd timeout / manual stop), the replicate-only mode end, and the normal session end inmain._SLACK_SENTguard prevents duplicate posts the same way_EMAIL_SENTdoes.CHANGELOG.md:[Unreleased]entry under### Added.Design notes
*_ON_SUCCESS/*_ON_FAILURE), same call sites, same data source. Operators who already understand the email config don't have to learn a new mental model.curl. Nojq. JSON is escaped with a small in-module helper (_slack_json_escape) so the module can drop into an existing AlmaLinux/Debian install with no extra packages.SLACK_ENABLED=\"no\"in the template; no behaviour change for existing installs.Test plan
bash -n vmbackup.sh+bash -n modules/slack_notification_module.shpass.load_slack_configround-trips a minimalslack.conf(smoke-tested locally)._slack_format_bytesproduces TiB/GiB/MiB/KiB/B with correct boundaries.vmbackup.shintegration sites match the four corresponding email sites (grep confirms 4×send_slack_notificationnext to 4×send_backup_report).🤖 Generated with Claude Code