VictoriaMetrics/app/vmalert/notifier/notifier_blackhole.go
venkatbvc d4ac4b7813
vmalert: allow to blackhole alerting notifications (#4639)
vmalert: support option to blackhole alerting notifications

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4122

---------

Co-authored-by: Rao, B V Chalapathi <b_v_chalapathi.rao@nokia.com>
2023-07-18 15:06:19 +02:00

36 lines
880 B
Go

package notifier
import "context"
// BlackHoleNotifier is used when no notifications needs to be sent
type BlackHoleNotifier struct {
addr string
metrics *metrics
}
// Send will not send any notifications. Only increase the alerts sent number.
func (bh *BlackHoleNotifier) Send(_ context.Context, alerts []Alert, _ map[string]string) error { //nolint:revive
bh.metrics.alertsSent.Add(len(alerts))
return nil
}
// Addr of black hole notifier
func (bh BlackHoleNotifier) Addr() string {
return bh.addr
}
// Close unregister the metrics
func (bh *BlackHoleNotifier) Close() {
bh.metrics.alertsSent.Unregister()
bh.metrics.alertsSendErrors.Unregister()
}
// NewBlackHoleNotifier Create a new BlackHoleNotifier
func NewBlackHoleNotifier() *BlackHoleNotifier {
address := "blackhole"
return &BlackHoleNotifier{
addr: address,
metrics: newMetrics(address),
}
}