2015-07-02 16:38:05 +00:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/log"
|
2015-09-24 22:14:41 +00:00
|
|
|
"golang.org/x/net/context"
|
2015-07-02 16:38:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Notifier interface {
|
2015-09-24 22:14:41 +00:00
|
|
|
Notify(context.Context, *Alert) error
|
2015-07-02 16:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LogNotifier struct {
|
2015-07-04 12:41:10 +00:00
|
|
|
name string
|
2015-07-02 16:38:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 22:14:41 +00:00
|
|
|
func (ln *LogNotifier) Notify(ctx context.Context, a *Alert) error {
|
2015-07-04 12:41:10 +00:00
|
|
|
log.Infof("notify %q", ln.name)
|
|
|
|
|
|
|
|
for _, a := range alerts {
|
|
|
|
log.Infof(" - %v", a)
|
|
|
|
}
|
|
|
|
return nil
|
2015-07-02 16:38:05 +00:00
|
|
|
}
|
2015-09-24 22:14:41 +00:00
|
|
|
|
|
|
|
// routedNotifier forwards alerts to notifiers matching the alert in
|
|
|
|
// a routing tree.
|
|
|
|
type routedNotifier struct {
|
|
|
|
notifiers map[string]Notifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *routedNotifier) Notify(alert *Alert) error {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// A Silencer determines whether a given label set is muted.
|
|
|
|
type Silencer interface {
|
|
|
|
Mutes(model.LabelSet) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// A Silence determines whether a given label set is muted
|
|
|
|
// at the current time.
|
|
|
|
type Silence struct {
|
|
|
|
ID model.Fingerprint
|
|
|
|
|
|
|
|
// A set of matchers determining if an alert is
|
|
|
|
Matchers Matchers
|
|
|
|
// Name/email of the silence creator.
|
|
|
|
CreatedBy string
|
|
|
|
// When the silence was first created (Unix timestamp).
|
|
|
|
CreatedAt, EndsAt time.Time
|
|
|
|
|
|
|
|
// Additional comment about the silence.
|
|
|
|
Comment string
|
|
|
|
|
|
|
|
// timeFunc provides the time against which to evaluate
|
|
|
|
// the silence.
|
|
|
|
timeFunc func() time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sil *Silence) Mutes(lset model.LabelSet) bool {
|
|
|
|
t := sil.timeFunc()
|
|
|
|
|
|
|
|
if t.Before(sil.CreatedAt) || t.After(sil.EndsAt) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return sil.Matchers.Match(lset)
|
|
|
|
}
|
|
|
|
|
|
|
|
// silencedNotifier wraps a notifier and applies a Silencer
|
|
|
|
// before sending out an alert.
|
|
|
|
type silencedNotifier struct {
|
|
|
|
Notifier
|
|
|
|
|
|
|
|
silencer Silencer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *silencedNotifier) Notify(alert *Alert) error {
|
|
|
|
// TODO(fabxc): increment total alerts counter.
|
|
|
|
// Do not send the alert if the silencer mutes it.
|
|
|
|
if n.silencer.Mutes(alert.Labels) {
|
|
|
|
// TODO(fabxc): increment muted alerts counter.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.Notifier.Send(alert)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Inhibitor interface {
|
|
|
|
Inhibits(model.LabelSet) bool
|
|
|
|
}
|