Skip to content

Instantly share code, notes, and snippets.

@ohlol
Created December 11, 2012 00:31
Show Gist options
  • Save ohlol/4254660 to your computer and use it in GitHub Desktop.
Save ohlol/4254660 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# This handler creates and resolves PagerDuty incidents, refreshing
# stale incident details every 30 minutes
#
# Copyright 2011 Sonian, Inc <[email protected]>
#
# 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 'socket'
class IRCat < Sensu::Handler
def incident_key
@event['client']['name'] + '/' + @event['check']['name']
end
def handle
status = @event['check']['status'] == 0 ? 'RECOVERY' : 'PROBLEM'
description = status + ' alert: ' + incident_key + ' - ' + @event['check']['output'].split("\n").delete_if(&:empty?).join('!')
if @event['check']['status'] > 0 and @event['check'].key?('graph')
description += ' - ' + @event['check']['graph']
end
begin
timeout(3) do
s = TCPSocket.new settings['irccat']['hostname'], settings['irccat']['port']
s.puts description
s.close
end
rescue Timeout::Error
puts 'irccat -- timed out while writing'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment