Last active
April 8, 2016 13:28
-
-
Save roobert/2cd85ce2bbbeaad1748c7149ba1fd2a1 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
#!/usr/bin/env ruby | |
# | |
# Released under the same terms as Sensu (the MIT license); see LICENSE | |
# for details | |
# | |
require 'rubygems' if RUBY_VERSION < '1.9.0' | |
require 'sensu-handler' | |
require 'rest-client' | |
class TTLExpiry < Sensu::Handler | |
def host | |
settings['ttlexpiry']['server'] || 'localhost' | |
rescue | |
'localhost' | |
end | |
def port | |
settings['ttlexpiry']['port'] || 4567 | |
rescue | |
4567 | |
end | |
def resurl | |
"http://#{host}:#{port}/results/#{@event['client']['name']}/#{@event['check']['name']}" | |
rescue => e | |
puts "failed to expand result URL for deletion: #{e}" | |
end | |
def evturl | |
"http://#{host}:#{port}/events/#{@event['client']['name']}/#{@event['check']['name']}" | |
rescue => e | |
puts "failed to expand event URL for deletion: #{e}" | |
end | |
def filter | |
# we always want to run our check below... | |
end | |
def handle | |
if @event['check']['output'] =~ /^Last check execution was / | |
# deleting the event "resolves" the alert, and generates a result of | |
# "Resolved by the API", which we subsequently delete. | |
RestClient.delete evturl | |
sleep 5 | |
RestClient.get resurl | |
RestClient.delete resurl | |
end | |
rescue => e | |
puts "Something went wrong in deleting event: #{e}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment