feat(channels): include event verb in ntfy title + smtp subject
CI / Build (windows/amd64) (pull_request) Successful in 30s
CI / Build (linux/amd64) (pull_request) Successful in 23s
CI / Build (linux/arm64) (pull_request) Successful in 22s
CI / Lint (pull_request) Successful in 1m19s
CI / Test (linux/amd64) (pull_request) Successful in 1m42s

Raise / ack / resolve all rendered with the same title and body on
ntfy and SMTP, so a recovery looked identical to the original alert.
Webhook was already fine because the JSON envelope carries 'event'.

ntfy:
  Title  '[raised · warning] dev backup_failed' (was '[warning] …')
  Tags   'raised,warning,backup_failed' (was 'warning,backup_failed')
  Body   'Resolved · <message>' / 'Acknowledged · <message>' on those events
SMTP:
  Subject '[restic-manager] [raised · warning] dev: backup_failed'

Plus: cmd/_fake_alert now accepts the ref as a positional argument
(go run ./cmd/_fake_alert steve-001) instead of silently ignoring
unknown positional args. Refuses ambiguous '-ref X positional Y'.
This commit is contained in:
2026-05-04 23:17:42 +01:00
parent 84814b1386
commit 43e72b0d5b
4 changed files with 38 additions and 7 deletions
+12 -1
View File
@@ -117,9 +117,20 @@ func extractAddr(s string) string {
// Plain text only; subject hardcoded.
func buildEmailBody(cfg SMTPConfig, msgIDDomain string, p Payload) []byte {
var b strings.Builder
// Subject prefix tracks the event verb so raise vs ack vs resolve
// are visually distinct in the inbox (and threaded by Message-ID).
verb := "raised"
switch p.Event {
case EventAcknowledged:
verb = "ack"
case EventResolved:
verb = "resolved"
case EventTest:
verb = "test"
}
b.WriteString("From: " + cfg.From + "\r\n")
b.WriteString("To: " + cfg.To + "\r\n")
b.WriteString(fmt.Sprintf("Subject: [restic-manager] [%s] %s: %s\r\n", p.Severity, p.HostName, p.Kind))
b.WriteString(fmt.Sprintf("Subject: [restic-manager] [%s · %s] %s: %s\r\n", verb, p.Severity, p.HostName, p.Kind))
b.WriteString("Date: " + p.RaisedAt.UTC().Format(time.RFC1123Z) + "\r\n")
b.WriteString("Message-ID: <" + p.AlertID + "@" + msgIDDomain + ">\r\n")
b.WriteString("MIME-Version: 1.0\r\n")