Class: Nagios::Plugin

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



11
12
13
14
# File 'lib/nagios/plugin.rb', line 11

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

Class Method Details

.run!Object

Syntactic sugar for creating a new instance automagically



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

def run!
  new.run!
end

Instance Method Details

#run!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nagios/plugin.rb', line 16

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

#statusObject



46
47
48
49
# File 'lib/nagios/plugin.rb', line 46

def status
  @status_used = true
  @status
end

#threshold(level) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/nagios/plugin.rb', line 32

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

#to_s(value) ⇒ Object



42
43
44
# File 'lib/nagios/plugin.rb', line 42

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