Skip to content

Commit

Permalink
handler must fire resolve if it fired for create
Browse files Browse the repository at this point in the history
Yelp#103
handler should now fire a resolve if the event was triggered
for create action earlier.
handler should not fire a resolve if the event was not triggered
for create action earlier.
  • Loading branch information
Vijaykumar Jain committed Mar 15, 2017
1 parent e690376 commit 96bbb6f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions files/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ 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
occurrences_watermark = @event.key?('occurrences_watermark') ? event['occurrences_watermark'] : -1

# 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 occurrences_watermark > initial_failing_occurrences and @event['action'] == 'resolve'
return nil
end

# Don't bother acting if we haven't hit the
# alert_after threshold
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

0 comments on commit 96bbb6f

Please sign in to comment.