Class: HostStatus::HostReportStatus
- Inherits:
-
Status
- Object
- Status
- HostStatus::HostReportStatus
- Defined in:
- app/models/host_status/host_report_status.rb
Overview
rubocop:disable Style/GuardClause
Constant Summary collapse
- UNKNOWN =
Constants are bit-mask friendly in case we want to query them in the DB
-0b000000000000010000000000000000 # -65536
- FAILURES =
-65536
-0b000000000000000000000000000001 # -1
- EMPTY =
-1
0b000000000000000000000000000000
- NO_CHANGES =
0
0b000000000000000000000100000000
- CHANGES =
256
0b000000000000010000000000000000
- LABELS =
65536
{ FAILURES => N_("Failure(s)"), EMPTY => N_("Empty"), NO_CHANGES => N_("No changes"), CHANGES => N_("Changes applied"), }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#change ⇒ Object
<host report fields>.
- #change? ⇒ Boolean
-
#expected_report_interval ⇒ Object
</legacy report compatibility fields>.
- #failed_restarts ⇒ Object
- #failure ⇒ Object
- #failure? ⇒ Boolean
- #last_report ⇒ Object
- #last_report=(report) ⇒ Object
- #no_reports? ⇒ Boolean
- #nochange ⇒ Object
- #nochange? ⇒ Boolean
- #out_of_sync? ⇒ Boolean
- #relevant?(options = {}) ⇒ Boolean
- #reported_format_interval ⇒ Object
-
#restarted ⇒ Object
<legacy report compatibility fields>.
- #skipped ⇒ Object
- #status_link ⇒ Object
- #to_global(options = {}) ⇒ Object
- #to_label(_options = {}) ⇒ Object
- #to_status(options = {}) ⇒ Object
Class Method Details
.status_name ⇒ Object
78 79 80 |
# File 'app/models/host_status/host_report_status.rb', line 78 def self.status_name N_("Configuration") end |
Instance Method Details
#change ⇒ Object
<host report fields>
15 16 17 |
# File 'app/models/host_status/host_report_status.rb', line 15 def change last_report&.change || 0 end |
#change? ⇒ Boolean
27 28 29 |
# File 'app/models/host_status/host_report_status.rb', line 27 def change? change.positive? end |
#expected_report_interval ⇒ Object
</legacy report compatibility fields>
54 55 56 |
# File 'app/models/host_status/host_report_status.rb', line 54 def expected_report_interval (reported_format_interval.presence || default_report_interval).to_i.minutes end |
#failed_restarts ⇒ Object
45 46 47 |
# File 'app/models/host_status/host_report_status.rb', line 45 def failed_restarts 0 end |
#failure ⇒ Object
23 24 25 |
# File 'app/models/host_status/host_report_status.rb', line 23 def failure last_report&.failure || 0 end |
#failure? ⇒ Boolean
35 36 37 |
# File 'app/models/host_status/host_report_status.rb', line 35 def failure? failure.positive? end |
#last_report ⇒ Object
4 5 6 7 |
# File 'app/models/host_status/host_report_status.rb', line 4 def last_report self.last_report = host.last_host_report_object_any_format unless @last_report_set @last_report end |
#last_report=(report) ⇒ Object
9 10 11 12 |
# File 'app/models/host_status/host_report_status.rb', line 9 def last_report=(report) @last_report_set = true @last_report = report end |
#no_reports? ⇒ Boolean
74 75 76 |
# File 'app/models/host_status/host_report_status.rb', line 74 def no_reports? host && last_report.nil? end |
#nochange ⇒ Object
19 20 21 |
# File 'app/models/host_status/host_report_status.rb', line 19 def nochange last_report&.nochange || 0 end |
#nochange? ⇒ Boolean
31 32 33 |
# File 'app/models/host_status/host_report_status.rb', line 31 def nochange? nochange.positive? end |
#out_of_sync? ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'app/models/host_status/host_report_status.rb', line 66 def out_of_sync? if (host && !host.enabled?) || no_reports? || out_of_sync_disabled? false else !reported_at.nil? && reported_at < (Time.now.utc - expected_report_interval) end end |
#relevant?(options = {}) ⇒ Boolean
138 139 140 141 142 |
# File 'app/models/host_status/host_report_status.rb', line 138 def relevant?( = {}) () host.configuration? || last_report.present? || Setting[:always_show_configuration_status] end |
#reported_format_interval ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/host_status/host_report_status.rb', line 58 def reported_format_interval if host.params.key? "#{last_report.format.downcase}_interval" host.params["#{last_report.format.downcase}_interval"] else Setting[:"#{last_report.format.downcase}_interval"] end end |
#restarted ⇒ Object
<legacy report compatibility fields>
41 42 43 |
# File 'app/models/host_status/host_report_status.rb', line 41 def restarted 0 end |
#skipped ⇒ Object
49 50 51 |
# File 'app/models/host_status/host_report_status.rb', line 49 def skipped 0 end |
#status_link ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/models/host_status/host_report_status.rb', line 144 def status_link return @status_link if defined?(@status_link) return @status_link = nil if last_report.nil? return @status_link = nil unless User.current.can?(:view_host_reports, last_report, false) @status_link = last_report && Rails.application.routes.url_helpers.host_report_path(last_report) end |
#to_global(options = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/host_status/host_report_status.rb', line 106 def to_global( = {}) () if failure? HostStatus::Global::ERROR elsif out_of_sync? HostStatus::Global::WARN elsif no_reports? && (host.configuration? || Setting[:always_show_configuration_status]) HostStatus::Global::WARN else HostStatus::Global::OK end end |
#to_label(_options = {}) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'app/models/host_status/host_report_status.rb', line 96 def to_label( = {}) if host && !host.enabled return N_("Alerts disabled") elsif out_of_sync? return N_("Out of sync") end LABELS.fetch(to_status, N_("Unknown config status")) end |
#to_status(options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/host_status/host_report_status.rb', line 120 def to_status( = {}) () if host&.enabled && last_report.present? if last_report.failure.positive? FAILURES elsif last_report.change.positive? CHANGES elsif last_report.nochange.positive? NO_CHANGES else EMPTY end else UNKNOWN end end |