Class: ForemanOpenscap::ComplianceStatus

Inherits:
HostStatus::Status
  • Object
show all
Defined in:
app/models/foreman_openscap/compliance_status.rb

Constant Summary collapse

COMPLIANT =
0
INCONCLUSIVE =
1
INCOMPLIANT =
2

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bit_mask(status) ⇒ Object



15
16
17
# File 'app/models/foreman_openscap/compliance_status.rb', line 15

def self.bit_mask(status)
  "#{ArfReport::BIT_NUM * ArfReport::METRIC.index(status)} & #{ArfReport::MAX}"
end

.status_nameObject



7
8
9
# File 'app/models/foreman_openscap/compliance_status.rb', line 7

def self.status_name
  N_('Compliance')
end

Instance Method Details

#relevant?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'app/models/foreman_openscap/compliance_status.rb', line 43

def relevant?(options = {})
  # May fail host status during migration
  return false unless ForemanOpenscap::Asset.table_exists?
  host.policies.present?
end


11
12
13
# File 'app/models/foreman_openscap/compliance_status.rb', line 11

def status_link
  host.arf_reports_path(:search => "host = #{host.name}")
end

#to_global(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'app/models/foreman_openscap/compliance_status.rb', line 32

def to_global(options = {})
  case to_status
  when COMPLIANT
    ::HostStatus::Global::OK
  when INCONCLUSIVE
    ::HostStatus::Global::WARN
  else
    ::HostStatus::Global::ERROR
  end
end

#to_label(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/foreman_openscap/compliance_status.rb', line 19

def to_label(options = {})
  case to_status
  when COMPLIANT
    N_('Compliant')
  when INCONCLUSIVE
    N_('Inconclusive')
  when INCOMPLIANT
    N_('Incompliant')
  else
    N_('Unknown Compliance status')
  end
end

#to_status(options = {}) ⇒ Object



49
50
51
52
53
54
# File 'app/models/foreman_openscap/compliance_status.rb', line 49

def to_status(options = {})
  latest_reports = host.policies.map { |p| host.last_report_for_policy p }.flatten
  return INCOMPLIANT if latest_reports.any?(&:failed?)
  return INCONCLUSIVE if latest_reports.any?(&:othered?)
  COMPLIANT
end