Last active
January 11, 2020 22:57
-
-
Save fifthecho/6675153 to your computer and use it in GitHub Desktop.
sensu handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:in
block (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:in
timeout'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:in
each'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:in
filter'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'