From 033f600c0032ad5029a034662075ea9debac9888 Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Sun, 1 Mar 2009 16:44:03 +0000 Subject: [PATCH] [project @ steve@lobefin.net-20090301164403-k2dxmmnlwwjntk4u] Add puppet freshness test --- dsa-nagios-nrpe-config/dsa-check-puppet | 91 +++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 dsa-nagios-nrpe-config/dsa-check-puppet diff --git a/dsa-nagios-nrpe-config/dsa-check-puppet b/dsa-nagios-nrpe-config/dsa-check-puppet new file mode 100755 index 0000000..2f6a9f1 --- /dev/null +++ b/dsa-nagios-nrpe-config/dsa-check-puppet @@ -0,0 +1,91 @@ +#!/usr/bin/env ruby + +require 'optparse' + +class CheckPuppet + + VERSION = '0.1' + script_name = File.basename($0) + + # default options + OPTIONS = { + :statefile => "/var/puppet/state/state.yaml", + :interval => 30, + } + + o = OptionParser.new do |o| + o.set_summary_indent(' ') + o.banner = "Usage: #{script_name} [OPTIONS]" + o.define_head "The check_puppet Nagios plug-in checks that the specified " + + "puppet state file is no older than specified interval." + o.separator "" + o.separator "Mandatory arguments to long options are mandatory for " + + "short options too." + + o.on("-s", "--statefile=statefile", String, "The state file", + "Default: #{OPTIONS[:statefile]}") { |OPTIONS[:statefile]| } + o.on("-i", "--interval=value", Integer, + "Default: #{OPTIONS[:interval]} minutes") { |OPTIONS[:interval]| } + + o.separator "" + o.on_tail("-h", "--help", "Show this help message.") do + puts o + exit + end + + o.parse!(ARGV) + end + + def check_state + + # Set variables + curt = Time.now + intv = OPTIONS[:interval] * 60 + + # Check file time + @modt = 0 + begin + @modt = File.mtime("#{OPTIONS[:statefile]}") + rescue + @file = 3 + end + + diff = (curt - @modt).to_i + + @file = 2 + @file = 0 if diff <= intv + + end + + def output_status + + case @file + when 0 + state = "state file status okay updated on " + @modt.strftime("%m/%d/%Y at %H:%M:%S") + when 2 + state = "state file is missing or older than #{OPTIONS[:interval]} minutes" + when 3 + state = "state file status unknown" + end + + case @file + when 0 + status = "OK" + exitcode = 0 + when 2 + status = "CRITICAL" + exitcode = 2 + when 3 + status = "UNKNOWN" + exitcide = 3 + end + + puts "PUPPET " + status + ": " + state + exit(exitcode) + end +end + +cp = CheckPuppet.new +cp.check_state +cp.output_status + -- 2.20.1