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



42
43
44
# File 'app/models/host_status/monitoring_status.rb', line 42

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

Instance Method Details

#host_known_in_monitoring?Boolean

Returns:

  • (Boolean)


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

def host_known_in_monitoring?
  host.monitoring_results.any?
end

#host_not_in_build?Boolean

Returns:

  • (Boolean)


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

def host_not_in_build?
  host && !host.build
end

#relevant?(_options = {}) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/host_status/monitoring_status.rb', line 10

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

#should_affect_global_status?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/host_status/monitoring_status.rb', line 69

def should_affect_global_status?
  Setting[:monitoring_affect_global_status]
end

#to_global(_options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/host_status/monitoring_status.rb', line 27

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



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/host_status/monitoring_status.rb', line 46

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



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

def to_status(_options = {})
  state = OK
  grouped_results.each_key do |resultset|
    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