diff --git a/main.go b/main.go index dacfe8e4..18a5f086 100644 --- a/main.go +++ b/main.go @@ -47,21 +47,35 @@ func main() { routedNotifier := notify.NewRoutedNotifier(func(confs []*config.NotificationConfig) map[string]notify.Notifier { res := notify.Build(confs) for name, n := range res { - res[name] = notify.NewDedupingNotifier(notifies, n) + res[name] = ¬ify.LogNotifier{ + Log: log.With("notifier", "dedup"), + Notifier: notify.NewDedupingNotifier(notifies, n), + } } return res }) var notifier notify.Notifier - notifier = routedNotifier + notifier = ¬ify.LogNotifier{ + Log: log.With("notifier", "routed"), + Notifier: routedNotifier, + } notifier = ¬ify.MutingNotifier{ Notifier: notifier, Muter: inhibitor, } + notifier = ¬ify.LogNotifier{ + Log: log.With("notifier", "inhibit"), + Notifier: notifier, + } notifier = ¬ify.MutingNotifier{ Notifier: notifier, Muter: silences, } + notifier = ¬ify.LogNotifier{ + Log: log.With("notifier", "silencer"), + Notifier: notifier, + } disp := NewDispatcher(alerts, notifier) diff --git a/notify/impl.go b/notify/impl.go index 2e5a90fe..6775b881 100644 --- a/notify/impl.go +++ b/notify/impl.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" + "github.com/prometheus/common/log" "golang.org/x/net/context" "golang.org/x/net/context/ctxhttp" @@ -21,10 +22,13 @@ func Build(confs []*config.NotificationConfig) map[string]Notifier { var all Notifiers for _, wc := range nc.WebhookConfigs { - all = append(all, NewWebhook(wc)) + all = append(all, &LogNotifier{ + Log: log.With("notifier", "webhook"), + Notifier: NewWebhook(wc), + }) } for range nc.EmailConfigs { - all = append(all, &LogNotifier{name: nc.Name}) + all = append(all, &LogNotifier{Log: log.With("name", nc.Name)}) } res[nc.Name] = all diff --git a/notify/notify.go b/notify/notify.go index aea3328b..3ccc2252 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -209,14 +209,15 @@ func (n *MutingNotifier) Notify(ctx context.Context, alerts ...*types.Alert) err } type LogNotifier struct { - name string + Log log.Logger + Notifier Notifier } func (ln *LogNotifier) Notify(ctx context.Context, alerts ...*types.Alert) error { - log.Infof("notify %q", ln.name) + ln.Log.Debugf("notify %v", alerts) - for _, a := range alerts { - log.Infof("- %v", a) + if ln.Notifier != nil { + return ln.Notifier.Notify(ctx, alerts...) } return nil }