Created
February 5, 2016 20:50
-
-
Save somic/6a62ea5e18bb087c2ce8 to your computer and use it in GitHub Desktop.
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
#!/opt/sensu/embedded/bin/ruby | |
# | |
# Check num_occurrences_filter logic | |
# | |
# Reads sensu-server log on stdin, looks for messages that are | |
# marked with 'event was filtered' and runs them through this tester handler | |
# to make sure it would filter them as well | |
# | |
# http://github.com/yelp/sensu_handlers | |
# | |
require '/etc/sensu/handlers/base' | |
class Bail < ::Exception; end | |
class TesterHandler < BaseHandler | |
attr_accessor :event | |
def bail(msg) | |
raise Bail, msg | |
end | |
def reset_api_settings!; end | |
def self.create_from_hash(h) | |
x = self.new | |
x.event = h | |
x | |
end | |
def run_test | |
begin | |
filter_repeated | |
rescue Bail | |
# good, this is the expected behavior | |
return true | |
end | |
# if we reached here, we have a problem | |
p event | |
return false | |
end | |
end | |
$failures = 0 | |
$stdin.readlines.each do |line| | |
line.chomp! | |
next unless line =~ /event was filtered/ | |
parsed = JSON.parse(line) | |
case parsed['handler']['command'] | |
when /jira/ | |
next unless parsed['event']['check']['ticket'] | |
when /pagerduty/ | |
next unless parsed['event']['check']['page'] | |
end | |
t = TesterHandler.create_from_hash(parsed['event']) | |
unless t.run_test | |
p parsed | |
$failures += 1 | |
end | |
$stderr.write('.') | |
end | |
puts "Found #{$failures} failures" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment