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.
(cherry picked from commit b54da68765)
Co-authored-by: Michał Zielonka <michal.zielonka.8001@gmail.com>
This commit is contained in:
co-authored by
Michał Zielonka
parent
314b932ab8
commit
f00f6e3375
@@ -2,11 +2,12 @@ package definitions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
tmplhtml "html/template"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/alertmanager/template"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@@ -64,7 +65,9 @@ func (t *MessageTemplate) Validate() error {
|
|||||||
return fmt.Errorf("template must have content")
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid template: %w", err)
|
return fmt.Errorf("invalid template: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user