Skip to content

Instantly share code, notes, and snippets.

@fifthecho
Last active January 11, 2020 22:57
Show Gist options
  • Save fifthecho/6675153 to your computer and use it in GitHub Desktop.
Save fifthecho/6675153 to your computer and use it in GitHub Desktop.
sensu handler
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-handler'
require 'sensu-plugin'
gem 'fog', '~> 1.15.0'
require 'fog'
class CloudStack < Sensu::Handler
def handle
server = connection
puts "Running connection #{connection}."
end
def connection
api_endpoint = settings["cloudstack"]["endpoint"]
api_key = settings["cloudstack"]["apikey"]
secret_key = settings["cloudstack"]["secretkey"]
cloudstack_uri = URI.parse(api_endpoint)
puts api_endpoint
@connection ||= begin
connection = Fog::Compute.new(
:provider => :cloudstack,
:cloudstack_api_key => @@api_key,
:cloudstack_secret_access_key => @@secret_key,
:cloudstack_host => @@cloudstack_uri.host,
:cloudstack_port => @@cloudstack_uri.port,
:cloudstack_path => @@cloudstack_uri.path,
:cloudstack_scheme => @@cloudstack_uri.scheme
)
end
end
end
@fifthecho
Copy link
Author

ruby ./cloudstack.rb < event.json
/Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:52:in api_request': undefined method[]' for nil:NilClass (NoMethodError)
from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:83:in stash_exists?' from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:94:inblock (2 levels) in filter_silenced'
from /Users/jmoody/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/timeout.rb:66:in timeout' from /Users/jmoody/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/timeout.rb:97:intimeout'
from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:93:in block in filter_silenced' from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:91:ineach'
from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:91:in filter_silenced' from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:22:infilter'
from /Users/jmoody/.rvm/gems/ruby-2.0.0-p195/gems/sensu-plugin-0.1.7/lib/sensu-handler.rb:40:in `block in class:Handler'

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