mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-27 16:43:41 +00:00
Use proper build function to create new notifiers
This commit is contained in:
parent
304be15fdb
commit
8799d647b3
9
main.go
9
main.go
@ -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
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user