class LogStash::Plugin
Attributes
logger[RW]
params[RW]
Public Class Methods
lookup(type, name)
click to toggle source
Look up a plugin by type and name.
# File lib/logstash/plugin.rb, line 124 def self.lookup(type, name) # Try to load the plugin requested. # For example, load("filter", "grok") will try to require # logstash/filters/grok # # And expects to find LogStash::Filters::Grok (or something similar based # on pattern matching path = "logstash/#{type}s/#{name}" require(path) base = LogStash.const_get("#{type.capitalize}s") klass = nil #klass_sym = base.constants.find { |c| c.to_s =~ /^#{Regexp.quote(name)}$/i } #if klass_sym.nil? # Look for a plugin by the config_name klass_sym = base.constants.find { |k| base.const_get(k).config_name == name } klass = base.const_get(klass_sym) raise LoadError if klass.nil? return klass rescue LoadError => e raise LogStash::PluginLoadingError, I18n.t("logstash.pipeline.plugin-loading-error", :type => type, :name => name, :path => path, :error => e.to_s) end
new(params=nil)
click to toggle source
# File lib/logstash/plugin.rb, line 23 def initialize(params=nil) @params = params @logger = Cabin::Channel.get(LogStash) end
Public Instance Methods
eql?(other)
click to toggle source
# File lib/logstash/plugin.rb, line 18 def eql?(other) self.class.name == other.class.name && @params == other.params end
finished()
click to toggle source
You should call this method when you (the plugin) are done with work forever.
# File lib/logstash/plugin.rb, line 50 def finished # TODO(sissel): I'm not sure what I had planned for this shutdown_queue # thing if @shutdown_queue @logger.info("Sending shutdown event to agent queue", :plugin => self) @shutdown_queue << self end if @plugin_state != :finished @logger.info("Plugin is finished", :plugin => self) @plugin_state = :finished end end
finished?()
click to toggle source
# File lib/logstash/plugin.rb, line 79 def finished? return @plugin_state == :finished end
hash()
click to toggle source
# File lib/logstash/plugin.rb, line 12 def hash params.hash ^ self.class.name.hash end
inspect()
click to toggle source
# File lib/logstash/plugin.rb, line 111 def inspect if !@config.nil? description = @config \ .select { |k,v| !v.nil? && (v.respond_to?(:empty?) && !v.empty?) } \ .collect { |k,v| "#{k}=>#{v.inspect}" } return "<#{self.class.name} #{description.join(", ")}>" else return "<#{self.class.name} --->" end end
reload()
click to toggle source
This method is called when a SIGHUP triggers a reload operation
# File lib/logstash/plugin.rb, line 74 def reload # Do nothing by default end
running?()
click to toggle source
# File lib/logstash/plugin.rb, line 84 def running? return @plugin_state != :finished end
shutdown(queue)
click to toggle source
This method is called when someone or something wants this plugin to shut down. When you successfully shutdown, you must call 'finished' You must also call 'super' in any subclasses.
# File lib/logstash/plugin.rb, line 32 def shutdown(queue) # By default, shutdown is assumed a no-op for all plugins. # If you need to take special efforts to shutdown (like waiting for # an operation to complete, etc) teardown @logger.info("Received shutdown signal", :plugin => self) @shutdown_queue = queue if @plugin_state == :finished finished else @plugin_state = :terminating end end
teardown()
click to toggle source
Subclasses should implement this teardown method if you need to perform any special tasks during shutdown (like flushing, etc.)
# File lib/logstash/plugin.rb, line 67 def teardown # nothing by default finished end
terminating?()
click to toggle source
# File lib/logstash/plugin.rb, line 89 def terminating? return @plugin_state == :terminating end
to_s()
click to toggle source
# File lib/logstash/plugin.rb, line 94 def to_s return "#{self.class.name}: #{@params}" end
Protected Instance Methods
clear_watchdog()
click to toggle source
# File lib/logstash/plugin.rb, line 105 def clear_watchdog Thread.current[:watchdog] = nil Thread.current[:watchdog_state] = nil end
update_watchdog(state)
click to toggle source
# File lib/logstash/plugin.rb, line 99 def update_watchdog(state) Thread.current[:watchdog] = Time.now Thread.current[:watchdog_state] = state end