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

- old
+ new

@@ -13,55 +13,66 @@ Usage: onering [global] report [options] Options: EOS - opt :id, "Override the autodetected Hardware ID for this node", :short => '-I', :type => :string - opt :fields, "Set the named FIELD to equal VALUE in the format FIELD=VALUE. Can be specified multiple times", :short => '-o', :type => :string, :multi => true - opt :save, "Save the report output to the configured Onering server" - opt :timeout, "The maximum amount of time to wait for a report to be generated", :type => :integer + opt :id, "Override the autodetected Hardware ID for this node", :short => '-I', :type => :string + opt :fields, "Set the named FIELD to equal VALUE in the format FIELD=VALUE. Can be specified multiple times", :short => '-o', :type => :string, :multi => true + opt :save, "Save the report output to the configured Onering server" + opt :timeout, "The maximum amount of time to wait for a report to be generated", :type => :integer, :default => 60 + opt :plugin_timeout, "The maximum amount of time to wait for a report plugin to return data", :type => :integer, :default => 10 end # initialize report generator with user options Onering::Reporter.setup({ - :id => @opts[:id], - :timeout => @opts[:timeout] + :id => @opts[:id], + :timeout => @opts[:timeout], + :plugin_timeout => @opts[:plugin_timeout] }.compact) end def self.run(args) - report = Onering::Reporter.report().stringify_keys() + begin + Onering::Logger.debug("Gathering local data for report") + report = Onering::Reporter.report().stringify_keys() - # pull report overrides from the config file - Onering::Config.get('reporter.fields',{}).each do |key, value| - if value.is_a?(Hash) - value.coalesce(key, nil, '.').each do |k,v| - v = nil if ['null', '', '-'].include?(v.to_s.strip.chomp) - report = report.set(k, v) + # pull report overrides from the config file + Onering::Config.get('reporter.fields',{}).each do |key, value| + Onering::Logger.debug("Override value #{key} from config file") + + if value.is_a?(Hash) + value.coalesce(key, nil, '.').each do |k,v| + v = nil if ['null', '', '-'].include?(v.to_s.strip.chomp) + report = report.set(k, v) + end + else + value = nil if ['null', '', '-'].include?(value.to_s.strip.chomp) + report = report.set(key, value) end - else + end + + # pull overrides from CLI arguments + @opts[:fields].each do |field| + key, value = field.split('=', 2) + Onering::Logger.debug("Override value #{key} from command line argument") + value = nil if ['null', '', '-'].include?(value.to_s.strip.chomp) report = report.set(key, value) end - end - # pull overrides from CLI arguments - @opts[:fields].each do |field| - key, value = field.split('=', 2) - value = nil if ['null', '', '-'].include?(value.to_s.strip.chomp) - report = report.set(key, value) - end - - # save if specified - if @opts[:save] === true - @api.connect() - @api.devices.save(report['id']) do - MultiJson.dump(report) + # save if specified + if @opts[:save] === true + @api.connect() + @api.devices.save(report['id']) do + MultiJson.dump(report) + end end - end - return report + return report + rescue Timeout::Error + Onering::Logger.fatal("Report took too long to generate, exiting...") + end end end end end \ No newline at end of file