Use proper build function to create new notifiers

This commit is contained in:
Fabian Reinartz 2015-09-29 15:02:15 +02:00
parent 304be15fdb
commit 8799d647b3
2 changed files with 22 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import (
"github.com/prometheus/common/route"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/types"
)
@ -43,10 +44,10 @@ func main() {
inhibitor := &Inhibitor{alerts: alerts}
routedNotifier := newRoutedNotifier(func(conf *config.Config) map[string]Notifier {
res := map[string]Notifier{}
for _, cn := range conf.NotificationConfigs {
res[cn.Name] = newDedupingNotifier(notifies, &LogNotifier{name: cn.Name})
routedNotifier := newRoutedNotifier(func(confs []*config.NotificationConfig) map[string]Notifier {
res := notify.Build()
for name, n := range res {
res[name] = newDedupingNotifier(notifies, n)
}
return res
})

View File

@ -13,6 +13,23 @@ import (
"github.com/prometheus/alertmanager/types"
)
func Build(confs []*config.NotificationConfig) map[string]Notifier {
// Create new notifiers. If the type is not implemented yet, fallback
// to logging notifiers.
res := map[string]Notifier{}
for _, nc := range confs {
var all Notifiers
for _, wc := range nc.WebhookConfigs {
all = append(all, NewWebhook(wc))
}
for range nc.EmailConfigs {
all = append(&LogNotifier{name: cn.Name})
}
res[nc.Name] = all
}
return res
}
type Webhook struct {
URL string
}