forked from choria-legacy/marionette-collective
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mc-facts
executable file
·54 lines (38 loc) · 1.12 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
#!/usr/bin/env ruby
require 'mcollective'
oparser = MCollective::Optionparser.new({}, "filter")
options = oparser.parse{|parser, options|
parser.define_head "Report on usage for a specific fact"
parser.banner = "Usage: mc-facts [options] fact"
}
if ARGV.length > 0
fact = ARGV.shift
else
puts("Please specify a fact to report")
exit 1
end
begin
client = MCollective::Client.new(options[:config])
client.options = options
facts = {}
stats = client.req("get_fact #{fact}", "discovery") do |resp|
next if resp == nil
value = resp[:body]
facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ]
end
rescue Exception => e
raise
end
puts("\rReport for fact: #{fact} \n\n")
facts.keys.sort.each do |k|
printf(" %-40sfound %d times\n", k, facts[k].size)
if options[:verbose]
puts
facts[k].sort.each do |f|
puts(" #{f}")
end
puts
end
end
client.display_stats(stats, options, "fact call stats")
# vi:tabstop=4:expandtab:ai