diff --git a/plugin/notification.go b/plugin/notification.go index ab601a6..1b95e87 100644 --- a/plugin/notification.go +++ b/plugin/notification.go @@ -233,17 +233,13 @@ func (no *NotifyOneshot) ShouldNotify(params ShouldNotifyParams) bool { log.Log.Info("NotifyOneshot: StateChange is zero") return false } - if params.Current.State == params.Last.State { - if log.LogDetails { - log.Log.Info("NotifyOneshot: no change in state") - } - return false - } + // already triggered for the current state if params.Last.Time.After(params.StateChange) { if log.LogDetails { log.Log.Info("NotifyOneshot: already notified") } return false } + // check that the current state is present for at least delay time return time.Since(params.StateChange) >= no.Delay } diff --git a/plugin/notification_test.go b/plugin/notification_test.go index d301d71..795e171 100644 --- a/plugin/notification_test.go +++ b/plugin/notification_test.go @@ -343,24 +343,6 @@ var _ = Describe("NotifyOneshot", func() { Expect(result).To(BeFalse()) }) - It("does not trigger when the did not state change and the delay passes", func() { - schedule := NotifyOneshot{Delay: -5 * time.Minute} - now := time.Now() - result := schedule.ShouldNotify(ShouldNotifyParams{ - Current: NotificationData{ - State: "operational", - Time: now, - }, - Last: NotificationData{ - State: "operational", - Time: now, - }, - Log: SchedLog, - StateChange: now, - }) - Expect(result).To(BeFalse()) - }) - It("does not trigger when StateChange is zero", func() { schedule := NotifyOneshot{Delay: -5 * time.Minute} now := time.Now()