Sha256: 387f39c9a54bf4cc48a051613f0d4d1fd787b63f45747e6b9d0bde55714189b9

Contents?: true

Size: 1.93 KB

Versions: 16

Compression:

Stored size: 1.93 KB

Contents

module Onering
  module CLI
    module Report
      def self.configure(global={})
        @api = (Onering::CLI.connect(global.merge({
          :autoconnect => false
        })) rescue nil)
        @opts = ::Trollop::options do
          banner <<-EOS
Generate a system report that can be saved or submitted to a Onering server

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"
        end

      # initialize report generator with user options
        Onering::Reporter.setup({
          :id => @opts[:id]
        }.compact)
      end

      def self.run(args)
        report = Onering::Reporter.report().stringify_keys()

      # pull report overrides from the config file
        @api.opt('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)
            end
          else
            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)
          end
        end

        return report
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
onering-client-0.0.76 lib/onering/cli/reporter.rb
onering-client-0.0.75 lib/onering/cli/reporter.rb
onering-client-0.0.74 lib/onering/cli/reporter.rb
onering-client-0.0.73 lib/onering/cli/reporter.rb
onering-client-0.0.72 lib/onering/cli/reporter.rb
onering-client-0.0.71 lib/onering/cli/reporter.rb
onering-client-0.0.70 lib/onering/cli/reporter.rb
onering-client-0.0.69 lib/onering/cli/reporter.rb
onering-client-0.0.68 lib/onering/cli/reporter.rb
onering-client-0.0.67 lib/onering/cli/reporter.rb
onering-client-0.0.66 lib/onering/cli/reporter.rb
onering-client-0.0.65 lib/onering/cli/reporter.rb
onering-client-0.0.64 lib/onering/cli/reporter.rb
onering-client-0.0.63 lib/onering/cli/reporter.rb
onering-client-0.0.62 lib/onering/cli/reporter.rb
onering-client-0.0.61 lib/onering/cli/reporter.rb