forked from choria-legacy/marionette-collective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mc-facts
executable file
·61 lines (44 loc) · 1.23 KB
/
mc-facts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env ruby
require 'mcollective'
include MCollective::RPC
options = rpcoptions do |parser, options|
parser.define_head "Report on usage for a specific fact"
parser.banner = "Usage: mc-facts [options] fact"
end
if ARGV.length > 0
fact = ARGV.shift
else
puts("Please specify a fact to report")
exit 1
end
def show_single_fact_report(fact, facts, verbose=false)
puts("Report for fact: #{fact}\n\n")
facts.keys.sort.each do |k|
printf(" %-40sfound %d times\n", k, facts[k].size)
if verbose
puts
facts[k].sort.each do |f|
puts(" #{f}")
end
puts
end
end
end
begin
rpcutil = rpcclient("rpcutil", :options => options)
rpcutil.progress = false
facts = {}
rpcutil.get_fact(:fact => fact) do |resp|
value = resp[:body][:data][:value]
if value
facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ]
end
end
show_single_fact_report(fact, facts, options[:verbose])
rescue Exception => e
STDERR.puts "Could not call remote agent: #{e}"
exit 1
end
printrpcstats
rpcutil.disconnect
# vi:tabstop=4:expandtab:ai