class NscaHostStatus

NscaHostStatus has a different set of statuses from ActiveStatus. Instead of OK, WARNING, UNKNOWN, and CRITICAL, NscaHostStatus uses UP, DOWN, and UNREACHABLE. These statuses are all meant to apply only to hosts and not services. Also, passive checks do not need to concern themselves with exit codes, as their output will be sent via the send_nsca program to a Nagios server for processing. It just so happens that the ‘host status’ is exactly the same as the UNIX/Linux exit codes, but we use the @passive_code attribute anyway for clarity.

Constants

DOWN

Host is down and unavailable

DOWN_CODE

Host status code for DOWN

UNREACHABLE

Host is unreachable (e.g. behind a router or host that is down)

UNREACHABLE_CODE

Host status code for UNREACHABLE

UP

Host is up and available

UP_CODE

Host status code for UP

Attributes

passive_code[R]

Stand-in for host status

Public Class Methods

new(status=nil, message=nil) click to toggle source

If status is not given, it will default to UNREACHABLE. If message is not given, it will default to <EMPTY>. UNIX/Linux exit codes are assigned automatically.

# File lib/rnagios/nsca_host_status.rb, line 31
def initialize(status=nil, message=nil)
  if status.nil? || (status != UP && status != DOWN && status != UNREACHABLE)
    @status = UNREACHABLE
  else
    @status = status
  end

  if message.nil?
    @message = '<EMPTY>'
  else
    @message = message
  end

  case @status
  when UP
    @passive_code = UP_CODE
  when DOWN
    @passive_code = DOWN_CODE
  when UNREACHABLE
    @passive_code = UNREACHABLE_CODE
  end
end

Public Instance Methods

empty?() click to toggle source
# File lib/rnagios/nsca_host_status.rb, line 73
def empty?
  @status == UNREACHABLE && (@message.nil? || @message.empty? || @message == '<EMPTY>')
end
status=(value) click to toggle source

If status is not given, it will default to UNREACHABLE. Changing the status will change the passive_code accordingly

# File lib/rnagios/nsca_host_status.rb, line 56
def status=(value)
  if value.nil? || (value != UP && value != DOWN && value != UNREACHABLE)
    @status = UNREACHABLE
  else
    @status = value
  end

  case @status
  when UP
    @passive_code = UP_CODE
  when DOWN
    @passive_code = DOWN_CODE
  when UNREACHABLE
    @passive_code = UNREACHABLE_CODE
  end
end