Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.