Skip to content

Instantly share code, notes, and snippets.

@marianogg9
Created February 12, 2014 14:43
Show Gist options
  • Save marianogg9/8956736 to your computer and use it in GitHub Desktop.
Save marianogg9/8956736 to your computer and use it in GitHub Desktop.
#!/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 <[email protected]>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
# export SSL_CERT_FILE=/etc/sensu/handlers/cacert.pem
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'twitter'
require 'timeout'
class TwitterHandler < Sensu::Handler
def hola
@event['check']['output'].split(' |').first
end
def event_name
@event['client']['name'] + '/' + @event['check']['name']
end
def handle
puts settings['twitter']
puts hola
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()}" )
foo.create_direct_message("@user_account", "#{event_name}: #{hola}")
else
#foo.update("Test")
foo.create_direct_message("@user_account", "#{event_name}: #{hola}")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment