class MCollective::Application::Facts - mcollective version 2.12.5

# class MCollective::Application::Facts

### Public Instance Methods

main() click to toggle source

       # File lib/mcollective/application/facts.rb
    31 def main
    32   rpcutil = rpcclient("rpcutil")
    33   rpcutil.progress = false
    34
    35   facts = {}
    36
    37   rpcutil.get_fact(:fact => configuration[:fact]) do |resp|
    38     begin
    39       value = resp[:body][:data][:value]
    40       if value
    41         if facts.include?(value)
    42           facts[value] << resp[:senderid]
    43         else
    44           facts[value] = [ resp[:senderid] ]
    45         end
    46       end
    47     rescue Exception => e
    48       STDERR.puts "Could not parse facts for #{resp[:senderid]}: #{e.class}: #{e}"
    49     end
    50   end
    51
    52   if facts.empty?
    53     puts "No values found for fact #{configuration[:fact]}\n"
    54   else
    55     show_single_fact_report(configuration[:fact], facts, options[:verbose])
    56   end
    57
    58   printrpcstats
    59
    60   halt rpcutil.stats
    61 end

post_option_parser(configuration) click to toggle source

      # File lib/mcollective/application/facts.rb
    4 def post_option_parser(configuration)
    5   configuration[:fact] = ARGV.shift if ARGV.size > 0
    6 end

show_single_fact_report(fact, facts, verbose=false) click to toggle source

       # File lib/mcollective/application/facts.rb
    12 def show_single_fact_report(fact, facts, verbose=false)
    13   puts("Report for fact: #{fact}\n\n")
    14
    15   field_size = MCollective::Util.field_size(facts.keys)
    16   facts.keys.sort.each do |k|
    17     printf("        %-#{field_size}s found %d times\n", k, facts[k].size)
    18
    19     if verbose
    20       puts
    21
    22       facts[k].sort.each do |f|
    23         puts("            #{f}")
    24       end
    25
    26       puts
    27     end
    28   end
    29 end

validate_configuration(configuration) click to toggle source

       # File lib/mcollective/application/facts.rb
     8 def validate_configuration(configuration)
     9   raise "Please specify a fact to report for" unless configuration.include?(:fact)
    10 end