Class: Nagios::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios/plugin.rb

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



4
5
6
7
# File 'lib/nagios/plugin.rb', line 4

def initialize
  @config = Nagios::Config.new
  @status_used = nil
end

Instance Method Details

#run!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nagios/plugin.rb', line 9

def run!
  @config.parse!
  begin
    @value = measure
    if critical(@value)
      exit_with :critical, @value
    elsif warning(@value)
      exit_with :warning, @value
    else
      exit_with :ok, @value
    end
  rescue => e
    exit_unknown e
  end
end

#statusObject



39
40
41
42
# File 'lib/nagios/plugin.rb', line 39

def status
  @status_used = true
  @status
end

#threshold(level) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/nagios/plugin.rb', line 25

def threshold(level)
  if level == :warning
    @config[:warning] || -1
  elsif level == :critical
    @config[:critical] || -1
  else
    -1
  end
end

#to_s(value) ⇒ Object



35
36
37
# File 'lib/nagios/plugin.rb', line 35

def to_s(value)
  "#{value}"
end