Skip to content

Instantly share code, notes, and snippets.

@marianogg9
Created February 3, 2014 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marianogg9/8785604 to your computer and use it in GitHub Desktop.
Save marianogg9/8785604 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Sensu Twitter Handler
# ===
#
# This handler reports alerts to a configured twitter handler.
# Map a twitter handle to a sensusub value in the twitter.json to get going!
# sensusub == subscription in the client object, not check..
# see twitter.json for required values
#
# Copyright 2011 Joe Crim <josephcrim@gmail.com>
#
# 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 'twitter'
require 'timeout'
class TwitterHandler < Sensu::Handler
def event_name
@event['client']['name'] + '/' + @event['check']['name']
end
def handle
puts settings['twitter']
settings['twitter'].each do |account|
if @event['client']['subscriptions'].include?(account[1]["sensusub"])
foo = Twitter::REST::Client.new do |config|
config.consumer_key = account[1]["consumer_key"]
config.consumer_secret = account[1]["consumer_secret"]
config.access_token = account[1]["access_token"]
config.access_token_secret = account[1]["access_token_secret"]
end
if @event['action'].eql?("resolve")
foo.update("RESOLVED - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()}" )
else
foo.update("ALERT - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()}" )
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment