From a8f69cd7cc98d9b3de5a3e2649f371b27f3f3157 Mon Sep 17 00:00:00 2001 From: Axodouble Date: Fri, 15 May 2026 00:34:53 +0000 Subject: [PATCH] Added VerbLower to have lowercase verbs --- internal/alerts/help.go | 3 ++- internal/alerts/message.go | 17 ++++++++++------- internal/config/cluster.go | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/alerts/help.go b/internal/alerts/help.go index 81901bf..8204396 100644 --- a/internal/alerts/help.go +++ b/internal/alerts/help.go @@ -9,7 +9,7 @@ package alerts func TemplateVarsHint() string { return "Go text/template — leave empty to use the built-in format.\n" + " Vars: {{.Check.Name}}, {{.Check.Target}}, {{.Check.Type}}, {{.Check.ID}},\n" + - " {{.Verb}} (UP|DOWN|RECOVERED), {{.From}}, {{.To}}, {{.NodeID}}, {{.When}},\n" + + " {{.Verb}} (UP|DOWN|RECOVERED), {{.VerbLower}}, {{.From}}, {{.To}}, {{.NodeID}}, {{.When}},\n" + " {{.Snapshot.Detail}}, {{.Snapshot.Reports}}, {{.Snapshot.OKCount}}, {{.Snapshot.NotOK}}" } @@ -29,6 +29,7 @@ Available variables: {{.Check.Type}} http | tcp | icmp {{.Check.ID}} stable check UUID {{.Verb}} UP | DOWN | RECOVERED + {{.VerbLower}} lowercase form of Verb (up | down | recovered) {{.From}} previous state name {{.To}} new state name {{.NodeID}} master node that rendered the message diff --git a/internal/alerts/message.go b/internal/alerts/message.go index d6fdc8d..a62f366 100644 --- a/internal/alerts/message.go +++ b/internal/alerts/message.go @@ -22,6 +22,7 @@ type TemplateContext struct { From string // previous state name To string // new state name Verb string // "UP" | "DOWN" | "RECOVERED" + VerbLower string // lowercase form of Verb ("up" | "down" | "recovered") Snapshot checks.Snapshot // aggregate counts and detail NodeID string // master that rendered the message When string // RFC3339 timestamp @@ -88,14 +89,16 @@ func RenderFor(alert *config.Alert, nodeID string, check *config.Check, from, to } func newContext(nodeID string, check *config.Check, from, to checks.State, snap checks.Snapshot) TemplateContext { + verb := transitionVerb(from, to) return TemplateContext{ - Check: check, - From: string(from), - To: string(to), - Verb: transitionVerb(from, to), - Snapshot: snap, - NodeID: nodeID, - When: time.Now().UTC().Format(time.RFC3339), + Check: check, + From: string(from), + To: string(to), + Verb: verb, + VerbLower: strings.ToLower(verb), + Snapshot: snap, + NodeID: nodeID, + When: time.Now().UTC().Format(time.RFC3339), } } diff --git a/internal/config/cluster.go b/internal/config/cluster.go index 940519e..925bc35 100644 --- a/internal/config/cluster.go +++ b/internal/config/cluster.go @@ -91,7 +91,7 @@ type Alert struct { // format. Discord ignores SubjectTemplate (it has no subject line); // SMTP uses both. Available variables: {{.Check.Name}}, // {{.Check.Type}}, {{.Check.Target}}, {{.Check.ID}}, {{.From}}, - // {{.To}}, {{.Verb}}, {{.Snapshot.Reports}}, {{.Snapshot.OKCount}}, + // {{.To}}, {{.Verb}}, {{.VerbLower}}, {{.Snapshot.Reports}}, {{.Snapshot.OKCount}}, // {{.Snapshot.NotOK}}, {{.Snapshot.Detail}}, {{.NodeID}}, {{.When}}. SubjectTemplate string `yaml:"subject_template,omitempty"` BodyTemplate string `yaml:"body_template,omitempty"`