2015-09-25 16:14:46 +00:00
|
|
|
package main
|
2015-07-02 16:38:05 +00:00
|
|
|
|
|
|
|
import (
|
2015-09-25 16:14:46 +00:00
|
|
|
"github.com/prometheus/common/model"
|
2015-07-02 16:38:05 +00:00
|
|
|
"github.com/prometheus/log"
|
2015-09-24 22:14:41 +00:00
|
|
|
"golang.org/x/net/context"
|
2015-09-25 16:14:46 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/alertmanager/types"
|
2015-07-02 16:38:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Notifier interface {
|
2015-09-26 12:12:55 +00:00
|
|
|
Notify(context.Context, ...*types.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-26 12:12:55 +00:00
|
|
|
func (ln *LogNotifier) Notify(ctx context.Context, alerts ...*types.Alert) error {
|
2015-07-04 12:41:10 +00:00
|
|
|
log.Infof("notify %q", ln.name)
|
|
|
|
|
2015-09-26 12:12:55 +00:00
|
|
|
for _, a := range alerts {
|
2015-09-26 15:54:49 +00:00
|
|
|
log.Infof("- %v", a)
|
2015-09-26 12:12:55 +00:00
|
|
|
}
|
2015-07-04 12:41:10 +00:00
|
|
|
return nil
|
2015-07-02 16:38:05 +00:00
|
|
|
}
|
2015-09-24 22:14:41 +00:00
|
|
|
|
2015-09-25 16:14:46 +00:00
|
|
|
// An InhibitRule specifies that a class of (source) alerts should inhibit
|
|
|
|
// notifications for another class of (target) alerts if all specified matching
|
|
|
|
// labels are equal between the two alerts. This may be used to inhibit alerts
|
|
|
|
// from sending notifications if their meaning is logically a subset of a
|
|
|
|
// higher-level alert.
|
|
|
|
type InhibitRule struct {
|
|
|
|
// The set of Filters which define the group of source alerts (which inhibit
|
|
|
|
// the target alerts).
|
|
|
|
SourceMatchers types.Matchers
|
|
|
|
// The set of Filters which define the group of target alerts (which are
|
|
|
|
// inhibited by the source alerts).
|
|
|
|
TargetMatchers types.Matchers
|
|
|
|
// A set of label names whose label values need to be identical in source and
|
|
|
|
// target alerts in order for the inhibition to take effect.
|
|
|
|
Equal model.LabelNames
|
2015-09-24 22:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// silencedNotifier wraps a notifier and applies a Silencer
|
|
|
|
// before sending out an alert.
|
|
|
|
type silencedNotifier struct {
|
|
|
|
Notifier
|
|
|
|
|
2015-09-25 16:14:46 +00:00
|
|
|
silencer types.Silencer
|
2015-09-24 22:14:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 12:12:55 +00:00
|
|
|
func (n *silencedNotifier) Notify(ctx context.Context, alerts ...*types.Alert) error {
|
|
|
|
var filtered []*types.Alert
|
|
|
|
for _, a := range alerts {
|
|
|
|
// TODO(fabxc): increment total alerts counter.
|
|
|
|
// Do not send the alert if the silencer mutes it.
|
|
|
|
if !n.silencer.Mutes(a.Labels) {
|
|
|
|
// TODO(fabxc): increment muted alerts counter.
|
|
|
|
filtered = append(filtered, a)
|
|
|
|
}
|
2015-09-24 22:14:41 +00:00
|
|
|
}
|
|
|
|
|
2015-09-26 12:12:55 +00:00
|
|
|
return n.Notifier.Notify(ctx, filtered...)
|
2015-09-24 22:14:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Inhibitor interface {
|
|
|
|
Inhibits(model.LabelSet) bool
|
|
|
|
}
|