Update Alerting module (#106272)

* set kind in TemplateDefinition
This commit is contained in:
Yuri Tseretyan
2025-06-04 16:05:05 -04:00
committed by GitHub
parent 184d0ef72f
commit 33298550b4
6 changed files with 13 additions and 38 deletions
@@ -31,18 +31,12 @@ func (t *NotificationTemplate) Validate() error {
content = fmt.Sprintf("{{ define \"%s\" }}\n%s\n{{ end }}", t.Name, content)
}
t.Template = content
// Validate template contents. We try to stick as close to what will actually happen when the templates are parsed
// by the alertmanager as possible.
tmpl, err := templates.NewTemplate()
if err != nil {
return fmt.Errorf("failed to create template: %w", err)
def := templates.TemplateDefinition{
Name: t.Name,
Template: t.Template,
Kind: templates.GrafanaKind,
}
if err := tmpl.Parse(strings.NewReader(t.Template)); err != nil {
return fmt.Errorf("invalid template: %w", err)
}
return nil
return def.Validate()
}
func (mt *MuteTimeInterval) Validate() error {