summaryrefslogtreecommitdiffstats
path: root/ext/puppetlast
blob: e8c2ea1a7f5147b55499d6a0b31fe4669b190a13 (plain)
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
#!/usr/bin/env ruby
#
# Script to print out when puppet ran successfully last
# AJ Christensen <aj@junglist.gen.nz>
#

require 'puppet'
require 'puppet/defaults'
require 'yaml'

Puppet[:config] = "/etc/puppet/puppet.conf"
Puppet.parse_config

print "puppetlast\n"

nodes = {}

yfdir = Puppet.settings.value(:vardir) + "/yaml/facts"

if yfdir
   begin
      Dir.chdir(yfdir) do
         Dir.glob("*.yaml").each do |yaml|
            data = YAML.load_file(yaml)
            t = Time.now
            age = t - data.version
            nodes[data.name] = age.to_i
         end
      end

      nodes.sort.each do |node,age|
         minutes = age / 60 + 0.5
         print minutes.floor.to_s + ' minutes ago: ' + node + "\n"
      end

   rescue
      print 'error: ' + $! + "\n"
   end

end