#!/usr/bin/env ruby require 'rubygems' require 'optparse' require 'json' require 'hashlib' def report(&block) Onering::Reporter.add(&block) end module Onering class Reporter DEFAULT_PLUGIN_GEMNAMES=[ 'onering-report-plugins' ] DEFAULT_PLUGIN_PATH = [ '/var/lib/onering/reporter' ] DEFAULT_FACTER_PATH = [ '/etc/facter' ] class<- - load if == # 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}" end end end end rescue Exception => e STDERR.puts e.message next end end end def add(&block) if block_given? instance_eval(&block) end end def property(name, value=nil) @_report[:properties].set(name, value) if value end def stat(name, value=nil) @_report[:properties][:metrics] ||= {} @_report[:properties][:metrics].set(name, value) if value end def report @id = (@options[:id] || (IO.read('/etc/hardware.id').to_s.nil_empty rescue nil)) if not @id.nil? hostname = (Facter.value('fqdn') rescue %x{hostname -f}.strip.chomp) @_report = { :id => @id, :name => hostname, :aliases => @options[:aliases], :tags => @options[:tags], :status => (@options[:status] || 'online'), :inventory => true, :properties => {} } # loads plugins and populates @_report load_plugins return @_report.compact() else raise "Cannot generate report without a hardware ID" end nil end end end end