From 388d3d3714a3d0ba0665bef9a49e5fcca3715abe Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Thu, 5 Sep 2019 18:54:27 +0300 Subject: [PATCH] Notification is sent when state changes from no_data to ok (#18920) --- pkg/services/alerting/notifiers/base.go | 5 ++--- pkg/services/alerting/notifiers/base_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/services/alerting/notifiers/base.go b/pkg/services/alerting/notifiers/base.go index f31c8b36d9c..7c0afa56750 100644 --- a/pkg/services/alerting/notifiers/base.go +++ b/pkg/services/alerting/notifiers/base.go @@ -71,11 +71,10 @@ func (n *NotifierBase) ShouldNotify(ctx context.Context, context *alerting.EvalC } } - unknownOrNoData := prevState == models.AlertStateUnknown || prevState == models.AlertStateNoData okOrPending := newState == models.AlertStatePending || newState == models.AlertStateOK - // Do not notify when new state is ok/pending when previous is unknown or no_data - if unknownOrNoData && okOrPending { + // Do not notify when new state is ok/pending when previous is unknown + if prevState == models.AlertStateUnknown && okOrPending { return false } diff --git a/pkg/services/alerting/notifiers/base_test.go b/pkg/services/alerting/notifiers/base_test.go index 799a843de2d..bf412518666 100644 --- a/pkg/services/alerting/notifiers/base_test.go +++ b/pkg/services/alerting/notifiers/base_test.go @@ -157,6 +157,13 @@ func TestShouldSendAlertNotification(t *testing.T) { expect: false, }, + { + name: "no_data -> ok", + prevState: models.AlertStateNoData, + newState: models.AlertStateOK, + + expect: true, + }, } for _, tc := range tcs {