Class: CheckPuppet

Inherits:
Object show all
Defined in:
ext/nagios/check_puppet.rb

Constant Summary collapse

VERSION =
'0.1'
OPTIONS =

default options

{
  :statefile => "/var/lib/puppet/state/state.yaml",
  :process   => "puppetd",
  :interval  => 30,
}

Instance Method Summary collapse

Instance Method Details

#check_procObject


51
52
53
54
55
56
57
58
59
# File 'ext/nagios/check_puppet.rb', line 51

def check_proc

  unless ProcTable.ps.find { |p| p.name == OPTIONS[:process]}
    @proc = 2
  else
    @proc = 0
  end

end

#check_stateObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/nagios/check_puppet.rb', line 61

def check_state

  # Set variables
  curt = Time.now
  intv = OPTIONS[:interval] * 60

  # Check file time
  begin
    @modt = File.mtime("#{OPTIONS[:statefile]}")
  rescue
    @file = 3
  end

  diff = (curt - @modt).to_i

  if diff > intv
    @file = 2
  else
    @file = 0
  end

end

#output_statusObject


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/nagios/check_puppet.rb', line 84

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 fille is not up to date and is older than #{OPTIONS[:interval]} minutes"
  when 3
    state = "state file status unknown"
  end

  case @proc
  when 0
    process = "process #{OPTIONS[:process]} is running"
  when 2
    process = "process #{OPTIONS[:process]} is not running"
  end

  case
  when (@proc == 2 or @file == 2)
    status = "CRITICAL"
    exitcode = 2
  when (@proc == 0 and @file == 0)
    status = "OK"
    exitcode = 0
  else
    status = "UNKNOWN"
    exitcode = 3
  end

  puts "PUPPET #{status}: #{process}, #{state}"
  exit(exitcode)
end