Class: NagiosResque::Plugin

Inherits:
NagiosPlugin::Plugin
  • Object
show all
Includes:
NagiosPlugin::DefaultOptions
Defined in:
lib/nagios_resque/plugin.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Plugin

Returns a new instance of Plugin.



55
56
57
58
59
60
61
# File 'lib/nagios_resque/plugin.rb', line 55

def initialize(*args)
  parse_options(*args, &default_options)

  @service = Check.new(@options)

  ENV['PATH'] = "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
end

Class Method Details

.run(*args) ⇒ Object



6
7
8
# File 'lib/nagios_resque/plugin.rb', line 6

def run(*args)
  self.new(*args).run
end

Instance Method Details

#checkObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nagios_resque/plugin.rb', line 63

def check
  if @service.critical?
    critical @service.critical_message
  elsif @service.warning?
    warning @service.warning_message
  else
    ok @service.ok_message
  end
ensure
  @service.requeue
end

#parse_options(*args) ⇒ Object



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
41
42
43
44
45
46
47
48
49
# File 'lib/nagios_resque/plugin.rb', line 11

def parse_options(*args)
  @options = {}
  OptionParser.new do |opts|
    opts.on("-H", "--host hosname", String, "redis server") do |host|
      @options[:host] = host
    end
    opts.on("-p", "--port number", Integer, "redis server port") do |port|
      @options[:port] = port
    end
    opts.on("-n", "--namespace name", String, "redis namespace") do |namespace|
      @options[:namespace] = namespace
    end
    opts.on("-j", "--job name", String, "resque job name") do |job|
      @options[:job] = job
    end
    opts.on("-k", "--key name", String, "redis key for timestamp") do |key|
      @options[:key] = key
    end

    yield(opts) if block_given?

    begin
      opts.parse!(args)

      if @options[:warn].nil? && @options[:crit].nil?
        @options[:crit] ||= (600..600)
      end

      if !@options[:warn].nil? && !@options[:crit].nil?
        if @options[:warn].last > @options[:crit].first
          unknown "Critical and Warning thresholds shouldn't overlap"
        end
      end
      @options
    rescue => e
      unknown "#{e}\n\n#{opts}"
    end
  end
end

#serviceObject



51
52
53
# File 'lib/nagios_resque/plugin.rb', line 51

def service
  'Resque'
end