Wrap all notifiers with logging

This commit is contained in:
Fabian Reinartz 2015-09-30 14:54:13 +02:00
parent 2b6d40c926
commit a377004d90
3 changed files with 27 additions and 8 deletions

18
main.go
View File

@ -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] = &notify.LogNotifier{
Log: log.With("notifier", "dedup"),
Notifier: notify.NewDedupingNotifier(notifies, n),
}
}
return res
})
var notifier notify.Notifier
notifier = routedNotifier
notifier = &notify.LogNotifier{
Log: log.With("notifier", "routed"),
Notifier: routedNotifier,
}
notifier = &notify.MutingNotifier{
Notifier: notifier,
Muter: inhibitor,
}
notifier = &notify.LogNotifier{
Log: log.With("notifier", "inhibit"),
Notifier: notifier,
}
notifier = &notify.MutingNotifier{
Notifier: notifier,
Muter: silences,
}
notifier = &notify.LogNotifier{
Log: log.With("notifier", "silencer"),
Notifier: notifier,
}
disp := NewDispatcher(alerts, notifier)

View File

@ -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

View File

@ -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
}