Class: NscaServiceStatus

Inherits:
ActiveStatus show all
Defined in:
lib/rnagios/nsca_service_status.rb

Overview

NscaServiceStatus is essentially an ActiveStatus object with only an extra :passive_code attribute.

Constant Summary

Constants inherited from ActiveStatus

ActiveStatus::CRITICAL, ActiveStatus::CRITICAL_EXIT_CODE, ActiveStatus::OK, ActiveStatus::OK_EXIT_CODE, ActiveStatus::UNKNOWN, ActiveStatus::UNKNOWN_EXIT_CODE, ActiveStatus::WARNING, ActiveStatus::WARNING_EXIT_CODE

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) ⇒ NscaServiceStatus

We call super.initialize to setup the ActiveStatus object then we set @passive_code to @exit_code. The values are exactly the same



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rnagios/nsca_service_status.rb', line 11

def initialize(status=nil, message=nil)
  if status.nil? || (status != OK && status != WARNING && status != CRITICAL && status != UNKNOWN)
    @status = UNKNOWN
  else
    @status = status
  end

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

  case @status
  when OK
    @passive_code = OK_EXIT_CODE
  when WARNING
    @passive_code = WARNING_EXIT_CODE
  when CRITICAL
    @passive_code = CRITICAL_EXIT_CODE
  when UNKNOWN
    @passive_code = UNKNOWN_EXIT_CODE
  end
end

Instance Attribute Details

#passive_codeObject (readonly)

Stand-in for return code



6
7
8
# File 'lib/rnagios/nsca_service_status.rb', line 6

def passive_code
  @passive_code
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/rnagios/nsca_service_status.rb', line 58

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

#status=(value) ⇒ Object

We call super.status to setup the ActiveStatus object then we set @passive_code to @exit_code. The values are exactly the same



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rnagios/nsca_service_status.rb', line 39

def status=(value)
  if value.nil? || (value != OK && value != WARNING && value != CRITICAL && value != UNKNOWN)
    @status = UNKNOWN
  else
    @status = value
  end

  case @status
  when OK
    @passive_code = OK_EXIT_CODE
  when WARNING
    @passive_code = WARNING_EXIT_CODE
  when CRITICAL
    @passive_code = CRITICAL_EXIT_CODE
  when UNKNOWN
    @passive_code = UNKNOWN_EXIT_CODE
  end
end