lib/onering/plugins/reporter.rb in onering-client-0.2.1 vs lib/onering/plugins/reporter.rb in onering-client-0.2.3
- old
+ new
@@ -110,13 +110,13 @@
end
def load_plugins()
# load plugins from @path
- @path.compact.each do |root|
+ @path.compact.uniq.each do |root|
begin
- Dir["#{root}/*"].each do |directory|
+ Dir["#{root}/*"].uniq.each do |directory|
# only process top-level directories
if File.directory?(directory)
d = File.basename(directory)
@@ -132,10 +132,11 @@
plugin = File.basename(plugin, '.rb')
begin
Timeout.timeout((@options[:plugin_timeout] || 10).to_i) do
Onering::Logger.debug("Loading plugin #{directory}/#{plugin}.rb", "Onering::Reporter")
+ Onering::Logger.debug3("Properties will be set in report object #{@_report.object_id}", "Onering::Reporter")
eval(File.read("#{directory}/#{plugin}.rb"), PluginDelegate.new(self, {
:plugin => plugin,
:path => "#{directory}/#{plugin}.rb"
}).get_binding())
end
@@ -160,29 +161,29 @@
end
end
def property(name, value=nil)
unless value.nil?
- Onering::Logger.debug3("-> Set property #{name.to_s} (was: #{@_report[:properties].get(name.to_s,'null')})", "Onering::Reporter")
+ Onering::Logger.debug3("-> Set property #{name.to_s} (was: #{@_report[:properties].get(name.to_s,'null')}) in object #{@_report.object_id}", "Onering::Reporter")
@_report[:properties].set(name.to_s, value)
end
end
def report(options={})
options = @options.merge(options)
- @id = (@options[:id] || Onering::Util.fact('hardwareid', nil))
+ @id = (@options[:id] || Onering::Config.get('id') || Onering::Config.get('reporter.fields.id') || Onering::Util.fact('hardwareid', nil))
if not @id.nil?
if options[:nocache]
return _generated_report()
else
rv = _cached_report(options)
return _generated_report() if rv.nil? or rv.empty?
return rv
end
else
- Onering::Logger.fatal!("Cannot generate report without a hardware ID", "Onering::Reporter")
+ Onering::Logger.fatal!("Cannot generate report without an ID", "Onering::Reporter")
end
return {}
end
@@ -202,9 +203,25 @@
}
# loads plugins and populates @_report
load_plugins()
+ # pull report field overrides from the config file
+ Onering::Config.get('reporter.fields',{}).each do |key, value|
+ Onering::Logger.debug("Override value #{key} from config file", "Onering::CLI::Report")
+
+ 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
+ end
+
+ # return final report
return @_report.stringify_keys()
end
return {}
end