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



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

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

Instance Method Details

#host_known_in_monitoring?Boolean

Returns:



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

def host_known_in_monitoring?
  host.monitoring_results.any?
end

#host_not_in_build?Boolean

Returns:



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

def host_not_in_build?
  host && !host.build
end

#relevant?(_options = {}) ⇒ Boolean

Returns:



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

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

#should_affect_global_status?Boolean

Returns:



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

def should_affect_global_status?
  Setting[:monitoring_affect_global_status]
end

#to_global(_options = {}) ⇒ Object



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

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



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

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
# 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 = WARNING if acknowledged || result == UNKNOWN
    state = result if result > state
  end
  state
end