diff --git a/templates/templates.go b/templates/templates.go index f4614fd754..4794274662 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -20,6 +20,7 @@ import ( "math" "regexp" "sort" + "strings" "text/template" clientmodel "github.com/prometheus/client_golang/model" @@ -92,6 +93,8 @@ func Expand(text string, name string, data interface{}, timestamp clientmodel.Ti re := regexp.MustCompile(pattern) return re.ReplaceAllString(text, repl) }, + "match": regexp.MatchString, + "title": strings.Title, "sortByLabel": func(label string, v queryResult) queryResult { sorter := queryResultByLabelSorter{v[:], label} sort.Stable(sorter) diff --git a/templates/templates_test.go b/templates/templates_test.go index eaf124bc21..1de164589e 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -89,6 +89,16 @@ func TestTemplateExpansion(t *testing.T) { text: "{{ 0.0 | humanize1024 }}:{{ 1.0 | humanize1024 }}:{{ 1048576.0 | humanize1024 }}:{{ .12 | humanize1024}}", output: "0 :1 :1 Mi:0.12 ", }, + { + // Title. + text: "{{ \"aa bb CC\" | title }}", + output: "Aa Bb CC", + }, + { + // Match. + text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}", + output: "true false", + }, } time := clientmodel.Timestamp(0)