Replies: 2 comments
-
I'm not a go lang developer but here is what I'm trying to achieve: package main
import (
"html/template"
"log"
"github.com/prometheus/alertmanager/config"
)
func main() {
cfg, err := config.LoadFile("alertmanager.yml")
if err != nil {
log.Fatalln(err.Error())
}
tpl := template.New("test")
if len(cfg.Templates) > 0 {
tpl, err = tpl.ParseFiles(cfg.Templates...)
if err != nil {
log.Fatalln(err.Error())
}
}
for _, receiver := range cfg.Receivers {
for _, slack := range receiver.SlackConfigs {
_, err = tpl.Parse(slack.Title)
if err != nil {
log.Fatalf("%s.slack.title: %s", receiver.Name, err.Error())
}
_, err = tpl.Parse(slack.Text)
if err != nil {
log.Fatalf("%s.slack.text: %s", receiver.Name, err.Error())
}
}
}
} with mistake from above we will get (can not say that error is meaningful but still it is better than nothing):
|
Beta Was this translation helpful? Give feedback.
0 replies
-
This might help Line 303 in 9f683fc |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
will be so nice if
amtool
will not only check the correctness of the configuration file but also given templatesrepro:
alertmanager.yml
docker run --rm -v $PWD:/code -w /code --entrypoint=amtool prom/alertmanager check-config alertmanager.yml
will say that everything fine
but sooner or later you will realize that you are not receiving alerts not because everything is fine but because a silly typo in the template 🤷♂️
from golang perspective such template will raise an error
template: :1: unexpected EOF
:so theoretically
amtool
can perform such check on each field that can use templates and warn us, so we know about the problem before applying changes to alertmanagerBeta Was this translation helpful? Give feedback.
All reactions