mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-13 17:43:26 +00:00
Wrap all notifiers with logging
This commit is contained in:
parent
2b6d40c926
commit
a377004d90
18
main.go
18
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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user