@!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 132 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 17 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 84 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 45 def definition { :type => "extension", :name => name } end
Override this method to set the extension's description.
# File lib/sensu/extension.rb, line 38 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 93 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 27 def name "base" end
Override this method to set a name alias for the extension. The extention can be referenced by the name alias. This method is used to aid in the transition to the extension from a Sensu component sharing the same name, e.g. pipe handler.
# File lib/sensu/extension.rb, line 35 def name_alias; 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 55 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. @yield [output, status] callback/block provided by Sensu,
expecting to be called with two parameters, an output string and exit status code.
@yieldparam output [String] @yieldparam status [Integer]
# File lib/sensu/extension.rb, line 69 def run(data=nil) yield("noop", 0) end
Run the extension with a few safeties. This method wraps run() with a begin;rescue and determines if the extension utilizes the provided data (i.e. event data). Do not override this method!
@param data [Object, nil) to pass to run(), if run() has an
absolue arity of 1 or more.
@yield [output, status] callback/block provided by Sensu,
expecting to be called with two parameters, an output string and exit status code.
@yieldparam output [String] @yieldparam status [Integer]
# File lib/sensu/extension.rb, line 109 def safe_run(data=nil) begin @run_arity ||= method(:run).arity.abs if @run_arity >= 1 run(data) do |output, status| yield(output, status) end else run do |output, status| yield(output, status) end end rescue => error klass = error.class.name backtrace = error.backtrace.map { |line| "\s\s#{line}" }.join("\n") yield("#{klass}: #{error}\n#{backtrace}", 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 75 def stop true end