bump reva and deps

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2026-01-07 17:15:23 +01:00
parent 6082e0c4df
commit 8e30e535b0
126 changed files with 8819 additions and 3109 deletions
+11
View File
@@ -217,3 +217,14 @@ Alerts Resolved:
{{ define "rocketchat.default.emoji" }}{{ end }}
{{ define "rocketchat.default.iconurl" }}{{ end }}
{{ define "rocketchat.default.text" }}{{ end }}
{{ define "mattermost.default.text" }}
{{ if gt (len .Alerts.Firing) 0 }}
# Alerts Firing:
{{ template "__text_alert_list_markdown" .Alerts.Firing }}
{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
# Alerts Resolved:
{{ template "__text_alert_list_markdown" .Alerts.Resolved }}
{{ end }}
{{ end }}
+77
View File
@@ -15,11 +15,13 @@ package template
import (
"bytes"
"encoding/json"
tmplhtml "html/template"
"io"
"net/url"
"path"
"path/filepath"
"reflect"
"regexp"
"sort"
"strings"
@@ -30,6 +32,7 @@ import (
"github.com/prometheus/common/model"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gopkg.in/yaml.v2"
"github.com/prometheus/alertmanager/asset"
"github.com/prometheus/alertmanager/types"
@@ -186,6 +189,10 @@ var DefaultFuncs = FuncMap{
"safeHtml": func(text string) tmplhtml.HTML {
return tmplhtml.HTML(text)
},
"safeUrl": func(text string) tmplhtml.URL {
return tmplhtml.URL(text)
},
"urlUnescape": url.QueryUnescape,
"reReplaceAll": func(pattern, repl, text string) string {
re := regexp.MustCompile(pattern)
return re.ReplaceAllString(text, repl)
@@ -207,6 +214,13 @@ var DefaultFuncs = FuncMap{
},
"since": time.Since,
"humanizeDuration": commonTemplates.HumanizeDuration,
"toJson": func(v any) (string, error) {
bytes, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(bytes), nil
},
}
// Pair is a key/value string pair.
@@ -423,3 +437,66 @@ func (t *Template) Data(recv string, groupLabels model.LabelSet, alerts ...*type
return data
}
type TemplateFunc func(string) (string, error)
// DeepCopyWithTemplate returns a deep copy of a map/slice/array/string/int/bool or combination thereof, executing the
// provided template (with the provided data) on all string keys or values. All maps are connverted to
// map[string]any, with all non-string keys discarded.
func DeepCopyWithTemplate(value any, tmplTextFunc TemplateFunc) (any, error) {
if value == nil {
return value, nil
}
valueMeta := reflect.ValueOf(value)
switch valueMeta.Kind() {
case reflect.String:
parsed, ok := tmplTextFunc(value.(string))
if ok == nil {
var inlineType any
err := yaml.Unmarshal([]byte(parsed), &inlineType)
if err != nil || (inlineType != nil && reflect.TypeOf(inlineType).Kind() == reflect.String) {
// ignore error, thus the string is not an interface
return parsed, ok
}
return DeepCopyWithTemplate(inlineType, tmplTextFunc)
}
return parsed, ok
case reflect.Array, reflect.Slice:
arrayLen := valueMeta.Len()
converted := make([]any, arrayLen)
for i := range arrayLen {
var err error
converted[i], err = DeepCopyWithTemplate(valueMeta.Index(i).Interface(), tmplTextFunc)
if err != nil {
return nil, err
}
}
return converted, nil
case reflect.Map:
keys := valueMeta.MapKeys()
converted := make(map[string]any, len(keys))
for _, keyMeta := range keys {
var err error
strKey, isString := keyMeta.Interface().(string)
if !isString {
continue
}
strKey, err = tmplTextFunc(strKey)
if err != nil {
return nil, err
}
converted[strKey], err = DeepCopyWithTemplate(valueMeta.MapIndex(keyMeta).Interface(), tmplTextFunc)
if err != nil {
return nil, err
}
}
return converted, nil
default:
return value, nil
}
}