mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: fix validation of alertmanager template. (#51538)
without setting function map from alertmanager we receive error: method=PUT path=/api/v1/provisioning/templates/slack.message status=400 level=error msg="invalid object specification: invalid template: template: :1: function \"toUpper\" not defined" So for validation we should use the same settings as alertmanager do for templates internally.
This commit is contained in:
parent
34d45977ca
commit
b54da68765
@ -2,11 +2,12 @@ package definitions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
tmplhtml "html/template"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/alertmanager/template"
|
||||
"github.com/prometheus/common/model"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -64,7 +65,9 @@ func (t *MessageTemplate) Validate() error {
|
||||
return fmt.Errorf("template must have content")
|
||||
}
|
||||
|
||||
_, err := template.New("").Parse(t.Template)
|
||||
tmpl := tmplhtml.New("").Option("missingkey=zero")
|
||||
tmpl.Funcs(tmplhtml.FuncMap(template.DefaultFuncs))
|
||||
_, err := tmpl.Parse(t.Template)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid template: %w", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user