Class: HostStatus::MonitoringStatus

Inherits:
Status
  • Object
show all
Defined in:
app/models/host_status/monitoring_status.rb

Constant Summary collapse

OK =
0
WARNING =
1
CRITICAL =
2
UNKNOWN =
3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.status_nameObject



38
39
40
# File 'app/models/host_status/monitoring_status.rb', line 38

def self.status_name
  N_('Monitoring Status')
end

Instance Method Details

#host_known_in_monitoring?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/host_status/monitoring_status.rb', line 59

def host_known_in_monitoring?
  host.monitoring_results.any?
end

#host_monitored?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/host_status/monitoring_status.rb', line 63

def host_monitored?
  host.monitored?
end

#host_not_in_build?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/host_status/monitoring_status.rb', line 55

def host_not_in_build?
  host && !host.build
end

#relevant?(_options = {}) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/host_status/monitoring_status.rb', line 8

def relevant?(_options = {})
  host_not_in_build? && host.monitored? && host_known_in_monitoring?
end

#should_affect_global_status?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/host_status/monitoring_status.rb', line 67

def should_affect_global_status?
  Setting[:monitoring_affect_global_status]
end

#to_global(_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/host_status/monitoring_status.rb', line 24

def to_global(_options = {})
  return HostStatus::Global::OK unless should_affect_global_status?
  case status
  when OK
    HostStatus::Global::OK
  when WARNING
    HostStatus::Global::WARN
  when CRITICAL
    HostStatus::Global::ERROR
  else
    HostStatus::Global::WARN
  end
end

#to_label(_options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/host_status/monitoring_status.rb', line 42

def to_label(_options = {})
  case status
  when OK
    N_('OK')
  when WARNING
    N_('Warning')
  when CRITICAL
    N_('Critical')
  else
    N_('Unknown')
  end
end

#to_status(_options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/host_status/monitoring_status.rb', line 12

def to_status(_options = {})
  state = OK
  grouped_results.each do |resultset, _count|
    result, downtime, acknowledged = resultset
    next if downtime
    result = map_result_to_status(result)
    result = WARNING if acknowledged || result == UNKNOWN
    state = result if result > state
  end
  state
end