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
|
# File 'lib/chef/knife/ohno.rb', line 15
def run
unless hours = name_args.first
ui.error "You need to specify a number of hours behind the checkins are"
exit 1
end
if nocolor = name_args[1]
color = 0
else
color = 1
end
hours = hours.to_i
stdout_orig = $stdout
$stdout = File.open('/dev/null', 'w')
knife_status = Chef::Knife::Status.new
hitlist = knife_status.run
$stdout.close
$stdout = stdout_orig
print "\nLost cheep in need of chefherding for more than #{hours} hours: \n"
hitlist.each { |node|
hour, minutes, seconds = Chef::Knife::Status.new.time_difference_in_hms(node["ohai_time"])
if hour >= hours
x = hour.to_s()
if (color == 1)
ui.msg("#{node['fqdn']}:\t\t" + ui.color("#{x} hours", :red))
else
ui.msg("#{node['fqdn']}:\t\t#{x} hours")
end
end
}
end
|