Class: NscaHostStatus

Inherits:
Status
  • Object
show all
Defined in:
lib/rnagios/nsca_host_status.rb

Overview

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.

Constant Summary collapse

UP =

Host is up and available

'UP'
DOWN =

Host is down and unavailable

'DOWN'
UNREACHABLE =

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

'UNREACHABLE'
UP_CODE =

Host status code for UP

0
DOWN_CODE =

Host status code for DOWN

1
UNREACHABLE_CODE =

Host status code for UNREACHABLE

2

Instance Attribute Summary collapse

Attributes inherited from Status

#exit_code, #message, #status

Instance Method Summary collapse

Methods inherited from Status

#to_s

Constructor Details

#initialize(status = nil, message = nil) ⇒ NscaHostStatus

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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

Instance Attribute Details

#passive_codeObject (readonly)

Stand-in for host status



12
13
14
# File 'lib/rnagios/nsca_host_status.rb', line 12

def passive_code
  @passive_code
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/rnagios/nsca_host_status.rb', line 73

def empty?
  @status == UNREACHABLE && (@message.nil? || @message.empty? || @message == '<EMPTY>')
end

#status=(value) ⇒ Object

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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