@!attribute [rw] logger
@return [Array] logger provided by Sensu.
@!attribute [rw] settings
@return [Array] settings hash provided by Sensu.
Determine classes that have inherited this class, used by the extension loader. Do not override this method!
@return [Array<object>]
# File lib/sensu/extension.rb, line 109 def self.descendants ObjectSpace.each_object(Class).select do |klass| klass < self end end
Initialize the extension, call #post_init() when the eventmachine reactor starts up, stop() when it stops.
# File lib/sensu/extension.rb, line 19 def initialize EM.next_tick do post_init end EM.add_shutdown_hook do stop end end
Retrieve the definition object corresponding to a key, acting like a Hash object. Do not override this method!
@param key [String, Symbol] @return [Object] value for key.
# File lib/sensu/extension.rb, line 77 def [](key) definition[key.to_sym] end
Override this method to change the extension's definition, a hash. You probably don't need to touch this. The hash must contain :type (“extension”) and :name.
# File lib/sensu/extension.rb, line 41 def definition { :type => "extension", :name => name } end
Override this method to set the extension's description.
# File lib/sensu/extension.rb, line 34 def description "extension description (change me)" end
Check to see if the definition has a key. Do not override this method!
@param key [String, Symbol] @return [TrueClass, FalseClass]
# File lib/sensu/extension.rb, line 86 def has_key?(key) definition.has_key?(key.to_sym) end
Override this method to set the extension's name.
# File lib/sensu/extension.rb, line 29 def name "base" end
Override this method to do something immediately after the eventmachine reactor is started. This method is great for setting up connections etc.
# File lib/sensu/extension.rb, line 51 def post_init true end
Override this method to do something when the extension is run, you must yield or call the callback with two parameters, an output string and exit code.
@param data [Object, nil] provided by Sensu. @param callback [Proc] provided by Sensu, expecting to be
called with two parameters, an output string and exit code.
# File lib/sensu/extension.rb, line 62 def run(data=nil, &callback) callback.call("noop", 0) end
Run the extension with a few safeties. This method wraps run() with a begin;rescue, and duplicates data before passing it to ensure the extension doesn't mutate the original. Do not override this method!
@param data [Object, nil) to dup() and pass to run(). @param callback [Proc] to pass to run().
# File lib/sensu/extension.rb, line 97 def safe_run(data=nil, &callback) begin data ? run(data.dup, &callback) : run(&callback) rescue => error callback.call(error.to_s, 2) end end
Override this method to do something when the eventmachine reactor stops, such as connection or file cleanup.
# File lib/sensu/extension.rb, line 68 def stop true end