~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to ext/nagios/check_puppet.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
class CheckPuppet
8
8
 
9
 
  VERSION = '0.1'
10
 
  script_name = File.basename($0)
11
 
 
12
 
  # default options
13
 
  OPTIONS = {
14
 
     :statefile   => "/var/puppet/state/state.yaml",
15
 
     :process     => "puppetd",
16
 
     :interval    => 30,
17
 
  }
18
 
 
19
 
  o = OptionParser.new do |o|    
20
 
    o.set_summary_indent('  ')
21
 
    o.banner =    "Usage: #{script_name} [OPTIONS]"
22
 
    o.define_head "The check_puppet Nagios plug-in checks that specified " +
 
9
    VERSION = '0.1'
 
10
    script_name = File.basename($0)
 
11
 
 
12
    # default options
 
13
    OPTIONS = {
 
14
        :statefile => "/var/puppet/state/state.yaml",
 
15
        :process   => "puppetd",
 
16
        :interval  => 30,
 
17
    }
 
18
 
 
19
    o = OptionParser.new do |o|
 
20
        o.set_summary_indent('  ')
 
21
        o.banner =    "Usage: #{script_name} [OPTIONS]"
 
22
        o.define_head "The check_puppet Nagios plug-in checks that specified " +
23
23
                  "Puppet process is running and the state file is no " +
24
24
                  "older than specified interval."
25
 
    o.separator   ""
26
 
    o.separator   "Mandatory arguments to long options are mandatory for " +
 
25
                  o.separator   ""
 
26
                  o.separator   "Mandatory arguments to long options are mandatory for " +
27
27
                  "short options too."
28
 
  
29
 
    o.on("-s", "--statefile=statefile", String, "The state file",
 
28
 
 
29
                  o.on("-s", "--statefile=statefile", String, "The state file",
30
30
         "Default: #{OPTIONS[:statefile]}") { |OPTIONS[:statefile]| }
31
 
    o.on("-p", "--process=processname", String, "The process to check",
 
31
         o.on("-p", "--process=processname", String, "The process to check",
32
32
         "Default: #{OPTIONS[:process]}")   { |OPTIONS[:process]| }
33
 
    o.on("-i", "--interval=value", Integer, 
 
33
         o.on("-i", "--interval=value", Integer,
34
34
         "Default: #{OPTIONS[:interval]} minutes")  { |OPTIONS[:interval]| }
35
 
     
36
 
    o.separator ""
37
 
    o.on_tail("-h", "--help", "Show this help message.") do 
38
 
      puts o
39
 
      exit  
40
 
    end
41
 
  
42
 
    o.parse!(ARGV)
43
 
   end
44
 
 
45
 
  def check_proc
46
 
 
47
 
    unless ProcTable.ps.find { |p| p.name == OPTIONS[:process]}
48
 
      @proc = 2
49
 
    else
50
 
      @proc = 0 
51
 
    end
52
 
  
53
 
  end
54
 
 
55
 
  def check_state
56
 
 
57
 
    # Set variables
58
 
    curt = Time.now
59
 
    intv = OPTIONS[:interval] * 60
60
 
 
61
 
    # Check file time
62
 
    begin
63
 
      @modt = File.mtime("#{OPTIONS[:statefile]}")
64
 
    rescue
65
 
      @file = 3
66
 
    end
67
 
 
68
 
    diff = (curt - @modt).to_i
69
 
 
70
 
    if diff > intv
71
 
      @file = 2
72
 
    else
73
 
      @file = 0
74
 
    end
75
 
 
76
 
  end
77
 
 
78
 
  def output_status
79
 
   
80
 
    case @file
81
 
    when 0
82
 
      state = "state file status okay updated on " + @modt.strftime("%m/%d/%Y at %H:%M:%S")
83
 
    when 2
84
 
      state = "state fille is not up to date and is older than #{OPTIONS[:interval]} minutes"
85
 
    when 3
86
 
      state = "state file status unknown"
87
 
    end
88
 
 
89
 
    case @proc
90
 
    when 0
91
 
      process = "process #{OPTIONS[:process]} is running"
92
 
    when 2
93
 
      process = "process #{OPTIONS[:process]} is not running" 
94
 
    end
95
 
 
96
 
    case @proc or @file
97
 
    when 0
98
 
      status = "OK"
99
 
      exitcode = 0
100
 
    when 2
101
 
      status = "CRITICAL"
102
 
      exitcode = 2
103
 
    when 3
104
 
      status = "UNKNOWN"
105
 
      exitcide = 3
106
 
    end
107
 
 
108
 
    puts "PUPPET " + status + ": " + process + ", " + state
109
 
    exit(exitcode)
110
 
 end
 
35
 
 
36
         o.separator ""
 
37
         o.on_tail("-h", "--help", "Show this help message.") do
 
38
             puts o
 
39
             exit
 
40
         end
 
41
 
 
42
         o.parse!(ARGV)
 
43
    end
 
44
 
 
45
    def check_proc
 
46
 
 
47
        unless ProcTable.ps.find { |p| p.name == OPTIONS[:process]}
 
48
            @proc = 2
 
49
        else
 
50
            @proc = 0
 
51
        end
 
52
 
 
53
    end
 
54
 
 
55
    def check_state
 
56
 
 
57
        # Set variables
 
58
        curt = Time.now
 
59
        intv = OPTIONS[:interval] * 60
 
60
 
 
61
        # Check file time
 
62
        begin
 
63
            @modt = File.mtime("#{OPTIONS[:statefile]}")
 
64
        rescue
 
65
            @file = 3
 
66
        end
 
67
 
 
68
        diff = (curt - @modt).to_i
 
69
 
 
70
        if diff > intv
 
71
            @file = 2
 
72
        else
 
73
            @file = 0
 
74
        end
 
75
 
 
76
    end
 
77
 
 
78
    def output_status
 
79
 
 
80
        case @file
 
81
        when 0
 
82
            state = "state file status okay updated on " + @modt.strftime("%m/%d/%Y at %H:%M:%S")
 
83
        when 2
 
84
            state = "state fille is not up to date and is older than #{OPTIONS[:interval]} minutes"
 
85
        when 3
 
86
            state = "state file status unknown"
 
87
        end
 
88
 
 
89
        case @proc
 
90
        when 0
 
91
            process = "process #{OPTIONS[:process]} is running"
 
92
        when 2
 
93
            process = "process #{OPTIONS[:process]} is not running"
 
94
        end
 
95
 
 
96
        case @proc or @file
 
97
        when 0
 
98
            status = "OK"
 
99
            exitcode = 0
 
100
        when 2
 
101
            status = "CRITICAL"
 
102
            exitcode = 2
 
103
        when 3
 
104
            status = "UNKNOWN"
 
105
            exitcide = 3
 
106
        end
 
107
 
 
108
        puts "PUPPET " + status + ": " + process + ", " + state
 
109
        exit(exitcode)
 
110
    end
111
111
end
112
112
 
113
113
cp = CheckPuppet.new