Class: ActiveStatus

Inherits:
Status show all
Defined in:
lib/rnagios/active_status.rb

Overview

Represents the status of an active check. Valid status strings for Nagios are OK, WARNING, CRITICAL, and UNKNOWN. UNIX/Linux exit codes are set automatically when you set the status attribute.

Direct Known Subclasses

NscaServiceStatus

Constant Summary collapse

OK =

Indicates everything is good with the service

'OK'
WARNING =

Indicates a status of concern; not necessarily catastrophic

'WARNING'
CRITICAL =

Indicates a serious failure or error

'CRITICAL'
UNKNOWN =

Indicates that the status is unknown or can not be determined

'UNKNOWN'
OK_EXIT_CODE =

UNIX/Linux exit code for Nagios OK

0
WARNING_EXIT_CODE =

UNIX/Linux exit code for Nagios WARNING

1
CRITICAL_EXIT_CODE =

UNIX/Linux exit code for Nagios CRITICAL

2
UNKNOWN_EXIT_CODE =

UNIX/Linux exit code for Nagios UNKNOWN

3

Instance Attribute Summary

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

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rnagios/active_status.rb', line 27

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

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

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

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/rnagios/active_status.rb', line 71

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

#status=(value) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rnagios/active_status.rb', line 52

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

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