Skip to content
This repository has been archived by the owner on Nov 20, 2019. It is now read-only.

handler must fire resolve if it fired for create #106

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions files/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ def filter_repeated
initial_failing_occurrences = interval > 0 ? (alert_after / interval) : 0
number_of_failed_attempts = @event['occurrences'] - initial_failing_occurrences

# sensu 0.26+ only, else never make occurrences_watermark actionable
# https://github.com/Yelp/sensu_handlers/issues/103
# this hack takes care of scenario
# when event has triggered at action == create
# but did not resolve the corresponding event when action == resolve.
# occurrences_watermark > initial_failing_occurrences prove enough occurrences
# of the event that triggered create and hence it is safe to filter the event to resolve handler action.
if (@event.key?('occurrences_watermark') &&
@event['occurrences_watermark'] > initial_failing_occurrences &&
@event['action'] == 'resolve')
return
end

# Don't bother acting if we haven't hit the
# alert_after threshold
if number_of_failed_attempts < 1
Expand Down
37 changes: 37 additions & 0 deletions spec/functions/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,43 @@ class BaseHandler
expect(subject).not_to receive(:bail)
expect(subject.filter_repeated).to eql(nil)
end
end
context "when action == resolve" do
context "when occurrences_watermark > initial_failing_occurrences" do
it "it should fire" do
subject.event['occurrences'] = 2
subject.event['occurrences_watermark'] = 8
subject.event['check']['interval'] = 20
subject.event['check']['realert_every'] = "-1"
subject.event['check']['alert_after'] = 60
subject.event['action'] = 'resolve'
expect(subject).not_to receive(:bail)
expect(subject.filter_repeated).to eql(nil)
end
end
context "when occurrences_watermark <= initial_failing_occurrences" do
it "it should not fire" do
subject.event['occurrences'] = 3
subject.event['occurrences_watermark'] = 3
subject.event['check']['interval'] = 20
subject.event['check']['realert_every'] = "-1"
subject.event['check']['alert_after'] = 60
subject.event['action'] = 'resolve'
expect(subject).to receive(:bail)
expect(subject.filter_repeated).to eql(nil)
end
end
context "when no occurrences_watermark" do
it "it should not fire" do
subject.event['occurrences'] = 3
subject.event['check']['interval'] = 20
subject.event['check']['realert_every'] = "-1"
subject.event['check']['alert_after'] = 60
subject.event['action'] = 'resolve'
expect(subject).to receive(:bail)
expect(subject.filter_repeated).to eql(nil)
end
end
end
end #End filter repeated

Expand Down