Puppet: System Administration Automated

Puppet Training Schedule
Next Class July 27-29
New York, New York
Discount before July 1st

Ticket #1188: puppetlast

File puppetlast, 0.8 kB (added by Fujin, 1 year ago)

Ruby version, with error handling

Line 
1 #!/usr/bin/env ruby
2 #
3 # Script to print out when puppet ran successfully last
4 # AJ Christensen <aj@junglist.gen.nz>
5 #
6
7 require 'puppet'
8 require 'puppet/defaults'
9 require 'yaml'
10
11 Puppet[:config] = "/etc/puppet/puppet.conf"
12 Puppet.parse_config
13
14 print "puppetlast\n"
15
16 nodes = {}
17
18 yfdir = Puppet.settings.value(:vardir) + "/yaml/facts"
19
20 if yfdir
21    begin
22       Dir.chdir(yfdir) do
23          Dir.glob("*.yaml").each do |yaml|
24             data = YAML.load_file(yaml)
25             t = Time.now
26             age = t - data.version
27             nodes[data.name] = age.to_i
28          end
29       end
30
31       nodes.sort.each do |node,age|
32          minutes = age / 60 + 0.5
33          print minutes.floor.to_s + ' minutes ago: ' + node + "\n"
34       end
35
36    rescue
37       print 'error: ' + $! + "\n"
38    end
39
40 end