Added VerbLower to have lowercase verbs

This commit is contained in:
2026-05-15 00:34:53 +00:00
parent 1f1dd32741
commit a8f69cd7cc
3 changed files with 13 additions and 9 deletions
+2 -1
View File
@@ -9,7 +9,7 @@ package alerts
func TemplateVarsHint() string { func TemplateVarsHint() string {
return "Go text/template — leave empty to use the built-in format.\n" + return "Go text/template — leave empty to use the built-in format.\n" +
" Vars: {{.Check.Name}}, {{.Check.Target}}, {{.Check.Type}}, {{.Check.ID}},\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}}" " {{.Snapshot.Detail}}, {{.Snapshot.Reports}}, {{.Snapshot.OKCount}}, {{.Snapshot.NotOK}}"
} }
@@ -29,6 +29,7 @@ Available variables:
{{.Check.Type}} http | tcp | icmp {{.Check.Type}} http | tcp | icmp
{{.Check.ID}} stable check UUID {{.Check.ID}} stable check UUID
{{.Verb}} UP | DOWN | RECOVERED {{.Verb}} UP | DOWN | RECOVERED
{{.VerbLower}} lowercase form of Verb (up | down | recovered)
{{.From}} previous state name {{.From}} previous state name
{{.To}} new state name {{.To}} new state name
{{.NodeID}} master node that rendered the message {{.NodeID}} master node that rendered the message
+10 -7
View File
@@ -22,6 +22,7 @@ type TemplateContext struct {
From string // previous state name From string // previous state name
To string // new state name To string // new state name
Verb string // "UP" | "DOWN" | "RECOVERED" Verb string // "UP" | "DOWN" | "RECOVERED"
VerbLower string // lowercase form of Verb ("up" | "down" | "recovered")
Snapshot checks.Snapshot // aggregate counts and detail Snapshot checks.Snapshot // aggregate counts and detail
NodeID string // master that rendered the message NodeID string // master that rendered the message
When string // RFC3339 timestamp 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 { func newContext(nodeID string, check *config.Check, from, to checks.State, snap checks.Snapshot) TemplateContext {
verb := transitionVerb(from, to)
return TemplateContext{ return TemplateContext{
Check: check, Check: check,
From: string(from), From: string(from),
To: string(to), To: string(to),
Verb: transitionVerb(from, to), Verb: verb,
Snapshot: snap, VerbLower: strings.ToLower(verb),
NodeID: nodeID, Snapshot: snap,
When: time.Now().UTC().Format(time.RFC3339), NodeID: nodeID,
When: time.Now().UTC().Format(time.RFC3339),
} }
} }
+1 -1
View File
@@ -91,7 +91,7 @@ type Alert struct {
// format. Discord ignores SubjectTemplate (it has no subject line); // format. Discord ignores SubjectTemplate (it has no subject line);
// SMTP uses both. Available variables: {{.Check.Name}}, // SMTP uses both. Available variables: {{.Check.Name}},
// {{.Check.Type}}, {{.Check.Target}}, {{.Check.ID}}, {{.From}}, // {{.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}}. // {{.Snapshot.NotOK}}, {{.Snapshot.Detail}}, {{.NodeID}}, {{.When}}.
SubjectTemplate string `yaml:"subject_template,omitempty"` SubjectTemplate string `yaml:"subject_template,omitempty"`
BodyTemplate string `yaml:"body_template,omitempty"` BodyTemplate string `yaml:"body_template,omitempty"`