Module: NRPE::Check

Defined in:
lib/nrpe_check/check.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



4
5
6
7
8
9
10
# File 'lib/nrpe_check/check.rb', line 4

def check
  set_default_status

  yield if block_given?
rescue Exception => message
  exit_with_status :unknown, message
end

#exit_with_status(status, message = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/nrpe_check/check.rb', line 18

def exit_with_status status, message = nil
  case status.downcase
  when :ok, :warning, :critical, :unknown
    STDOUT.puts "#{status.upcase}: " + message if message

    exit! eval ['NRPE', 'Status', status.upcase].join '::'
  else
    raise 'invalid NRPE::Check exit status'
  end
end

#set_default_statusObject



29
30
31
# File 'lib/nrpe_check/check.rb', line 29

def set_default_status
  status :unknown, "#{$0} failed to set an exit status"
end

#status(status, message = nil) ⇒ Object



12
13
14
15
16
# File 'lib/nrpe_check/check.rb', line 12

def status status, message = nil
  at_exit do
    exit_with_status status, message
  end
end