-
-
Save cabecada/3bd548a3cb5e3415a8fed30b276d2409 to your computer and use it in GitHub Desktop.
extension simulating yelp/filter_repeated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sensu | |
module Extension | |
class Yelp < Filter | |
def name | |
"yelp" | |
end | |
def description | |
"filter events using event occurrences" | |
end | |
def power_of_two?(x) | |
while ( x % 2) == 0 and x > 1 | |
x /= 2 | |
end | |
x==1 | |
end | |
def event_filtered?(event) | |
@event = event | |
if @event[:check][:name] == 'keepalive' | |
interval = 20 | |
else | |
interval = @event[:check][:interval].to_i || 0 | |
end | |
alert_after = @event[:check][:alert_after].to_i || 0 | |
realert_every = ( @event[:check][:realert_every] || 1 ).to_i | |
initial_failing_occurrences = interval > 0 ? (alert_after / interval) : 0 | |
number_of_failed_attempts = @event[:occurrences] - initial_failing_occurrences | |
puts "#{@event}" | |
puts "interval=#{interval}, alert_after=#{alert_after}, alert_after=#{alert_after}, initial_failing_occurrences=#{initial_failing_occurrences}, number_of_failed_attempts=#{number_of_failed_attempts}" | |
if (@event.key?(:occurrences_watermark) && | |
@event[:occurrences_watermark] > initial_failing_occurrences && | |
@event[:action] == :resolve) | |
return ["enough occurrences", 1] | |
end | |
if number_of_failed_attempts < 1 | |
return ["not enough occurrences", 0] | |
elsif interval > 0 and @event[:action] == :create | |
if realert_every == -1 | |
if power_of_two?(number_of_failed_attempts) | |
return ["enough occurrences", 1] | |
else | |
return ["not enough occurrences", 0] | |
end | |
elsif (number_of_failed_attempts - 1) % realert_every != 0 | |
return ["not enough occurrences", 0] | |
end | |
end | |
return ["not enough occurrences", 0] | |
end | |
def run(event) | |
yield event_filtered?(event) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test:
expectation:
handler should trigger when
action == create and
handler should trigger when
yelp/filter_repeated should not be called at all.
observation:
works as expected.