Class | HostMap::Managers::PluginManager |
In: |
lib/plugin_manager.rb
|
Parent: | Object |
Handles the plugins. Loading and running jobs.
Creates a new plugin manager.
# File lib/plugin_manager.rb, line 23 def initialize(engine) self.engine = engine # Load plugins. self.load # Store plugin queue @queue = Queue.new @pool = [] # Throw exceptions in threads Thread.abort_on_exception = true # Callback to call when execution is done @callback = nil end
Enqueue a plugin to be runned.
# File lib/plugin_manager.rb, line 105 def enq(plugin, input) @queue << {plugin => input} end
Runs all plugins that depends from an enumerated domain.
# File lib/plugin_manager.rb, line 46 def run_domain(name) PlugMan.registered_plugins[:main].do_group(:domain, name, self) end
Runs all plugins that depends from an enumerated hostname.
# File lib/plugin_manager.rb, line 60 def run_hostname(name) PlugMan.registered_plugins[:main].do_group(:hostname, name, self) end
Runs all plugins that depends from an enumerated ip.
# File lib/plugin_manager.rb, line 39 def run_ip(ip) PlugMan.registered_plugins[:main].do_group(:ip, ip, self) end
Runs all plugins that depends from an enumerated nameserver.
# File lib/plugin_manager.rb, line 53 def run_ns(name) PlugMan.registered_plugins[:main].do_group(:ns, name, self) end
Start the engine suppling the parameters to start the first plugin.
# File lib/plugin_manager.rb, line 67 def start(type, value, callback) # Set callback to later user @callback = callback # Select the right plugin to start case type when :ip then self.run_ip(value) end # Plugins loop loop do until @queue.empty? do # Dequeue a plugin and run it @queue.deq.each { |k,v| # Creating a thread, running the plugin inside job = Thread.new do out = k.run(v, self.engine.opts) # Reports the result self.engine.host_discovery.report(out) $LOG.debug "Plugin: #{k.name.inspect} Output: #{set2txt(out)}" end @pool << job } end # Consume long threads @pool.each { |th| th.join } # Break loop if no more plugins break if @queue.empty? end # Stop plugin manager stop_all end
Stops all the plugins.
# File lib/plugin_manager.rb, line 112 def stop_all $LOG.debug "Stopping all plugins." @pool.each { |th| th.kill } PlugMan.stop_all_plugins() # Callback to discovery @callback.call end
Load plugins from plugin directory
# File lib/plugin_manager.rb, line 125 def load $LOG.debug "Loading plugins." # Load all the plugins PlugMan.load_plugins PLUGINDIR # Start all the pluins PlugMan.start_all_plugins end