Skip to content

Instantly share code, notes, and snippets.

@marianogg9
Created January 27, 2014 13:19
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/8648455 to your computer and use it in GitHub Desktop.
Save marianogg9/8648455 to your computer and use it in GitHub Desktop.
/etc/sensu/handler/twitter.rb
#!/usr/bin/env /opt/sensu/embedded/bin/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"])
Twitter.configure do |t|
t.consumer_key = account[1]["consumer_key"]
t.consumer_secret = account[1]["consumer_secret"]
t.oauth_token = account[1]["oauth_token"]
t.oauth_token_secret = account[1]["oauth_token_secret"]
end
if @event['action'].eql?("resolve")
Twitter.update("RESOLVED - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()} ")
else
Twitter.update("ALERT - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()} ")
end
end
end
end
end
@josephcrim
Copy link

!/usr/bin/env /opt/sensu/embedded/bin/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"])
Twitter.configure do |t|
t.consumer_key = account[1]["consumer_key"]
t.consumer_secret = account[1]["consumer_secret"]
t.oauth_token = account[1]["oauth_token"]
t.oauth_token_secret = account[1]["oauth_token_secret"]
end
if @event['action'].eql?("resolve")
call = Twitter.update("RESOLVED - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()} ")
puts call
else
call = Twitter.update("ALERT - #{event_name}: #{@event['check']['notification']} Time: #{Time.now()} ")
puts call
end
end
end
end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment