2023-07-18 15:06:19 +02:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
2023-07-18 15:53:37 +02:00
|
|
|
// blackHoleNotifier is a Notifier stub, used when no notifications need
|
|
|
|
// to be sent.
|
|
|
|
type blackHoleNotifier struct {
|
2023-07-18 15:06:19 +02:00
|
|
|
addr string
|
|
|
|
metrics *metrics
|
|
|
|
}
|
|
|
|
|
2023-07-18 15:53:37 +02:00
|
|
|
// Send will send no notifications, but increase the metric.
|
|
|
|
func (bh *blackHoleNotifier) Send(_ context.Context, alerts []Alert, _ map[string]string) error { //nolint:revive
|
2023-07-18 15:06:19 +02:00
|
|
|
bh.metrics.alertsSent.Add(len(alerts))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Addr of black hole notifier
|
2023-07-18 15:53:37 +02:00
|
|
|
func (bh blackHoleNotifier) Addr() string {
|
2023-07-18 15:06:19 +02:00
|
|
|
return bh.addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close unregister the metrics
|
2023-07-18 15:53:37 +02:00
|
|
|
func (bh *blackHoleNotifier) Close() {
|
2023-07-18 15:06:19 +02:00
|
|
|
bh.metrics.alertsSent.Unregister()
|
|
|
|
bh.metrics.alertsSendErrors.Unregister()
|
|
|
|
}
|
|
|
|
|
2023-07-18 15:53:37 +02:00
|
|
|
// newBlackHoleNotifier creates a new blackHoleNotifier
|
|
|
|
func newBlackHoleNotifier() *blackHoleNotifier {
|
2023-07-18 15:06:19 +02:00
|
|
|
address := "blackhole"
|
2023-07-18 15:53:37 +02:00
|
|
|
return &blackHoleNotifier{
|
2023-07-18 15:06:19 +02:00
|
|
|
addr: address,
|
|
|
|
metrics: newMetrics(address),
|
|
|
|
}
|
|
|
|
}
|