lib/onering/plugins/reporter.rb in onering-client-0.0.83 vs lib/onering/plugins/reporter.rb in onering-client-0.0.84

- old
+ new

@@ -39,20 +39,22 @@ begin p = File.join(Util.gem_path(g), 'lib') @path << File.join(p, 'reporter') @facter_path << File.join(p, 'facter') rescue Gem::LoadError => e - STDERR.puts("Error loading gem: #{e.message}") + Onering::Logger.warn("Error loading gem: #{e.message}", "Onering::Reporter") next end end begin ENV['FACTERLIB'] = @facter_path.join(':') require 'facter' + Onering::Logger.debug("Facter loaded successfully, FACTERLIB is #{ENV['FACTERLIB']}", "Onering::Reporter") + rescue LoadError - STDERR.puts("Unable to load Facter library") + Onering::Logger.error("Unable to load Facter library", "Onering::Reporter") end end def load_plugins # load plugins from @path @@ -69,17 +71,25 @@ # <fact>-<fact_value> - load if <fact> == <fact_value> # if d == 'default' or Facter.value(d.split('-',2).first).to_s.downcase.nil_empty == d.split('-',2).last.to_s.downcase.nil_empty Dir[File.join(directory, '*.rb')].each do |e| e = File.basename(e, '.rb') - require "#{directory}/#{e}" + + begin + Timeout.timeout((@options[:plugin_timeout] || 10).to_i) do + Onering::Logger.debub("Loading plugin #{e}", "Onering::Reporter") + require "#{directory}/#{e}" + end + rescue Timeout::Error + Onering::Logger.warn("Plugin #{e} took too long to return, skipping", "Onering::Reporter") + end end end end end rescue Exception => e - STDERR.puts e.message + Onering::Logger.warn(e.message, e.class.name) next end end end @@ -119,10 +129,10 @@ load_plugins return @_report.stringify_keys() end else - raise "Cannot generate report without a hardware ID" + Onering::Logger.fatal("Cannot generate report without a hardware ID", "Onering::Reporter") end {} end end