Class: CemAcpt::TestRunner::LogFormatter::ScanResultFormatter
- Defined in:
- lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb
Overview
Formats the results of a Scan::Result. Mirrors the shape of GossActionResponse so the runner’s ‘process_test_results` loop treats scan results the same way: `summary` for the one-liner, `results` for the per-rule detail (used at debug only — full per-rule output bloats normal logs without adding decision-grade information).
Constant Summary collapse
- OUTCOME_PREFIXES =
CIS-CAT Pro v4 JSON does not carry a severity field, and the test_runner routes log lines by past-tense prefix (“Passed:”, “Skipped:”) to choose log level. Mapping outcome → prefix here keeps passes at verbose, not-applicable rules at info, and surfaces fails/errors at error level.
{ 'pass' => 'Passed', 'fail' => 'Failed', 'notchecked' => 'Skipped', 'notapplicable' => 'Skipped', 'notselected' => 'Skipped', }.freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #host_name(response = nil) ⇒ Object
-
#initialize(config, instance_names_ips, subject: nil) ⇒ ScanResultFormatter
constructor
A new instance of ScanResultFormatter.
- #results(response = nil) ⇒ Object
- #summary(response = nil) ⇒ Object
- #test_name(response = nil) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(config, instance_names_ips, subject: nil) ⇒ ScanResultFormatter
Returns a new instance of ScanResultFormatter.
14 15 16 17 18 |
# File 'lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb', line 14 def initialize(config, instance_names_ips, subject: nil) super(subject) @config = config @instance_names_ips = instance_names_ips end |
Instance Method Details
#host_name(response = nil) ⇒ Object
60 61 62 63 |
# File 'lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb', line 60 def host_name(response = nil) super(response) log_subject.test_case end |
#results(response = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb', line 47 def results(response = nil) super(response) rules = log_subject.to_h[:rules] return [] unless rules.is_a?(Array) rules.map do |rule| outcome = (rule['result'] || rule[:result]).to_s.downcase id = rule['id'] || rule[:id] prefix = OUTCOME_PREFIXES[outcome] || outcome.capitalize "#{prefix}: rule=#{id}" end end |
#summary(response = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb', line 20 def summary(response = nil) super(response) r = log_subject status = r.pass? ? 'passed' : 'failed' [ "SUMMARY: #{status.capitalize}: Scan #{r.test_case}:", "scanner=#{r.scanner}", "score=#{format('%.2f', r.score)}", "threshold=#{format('%.2f', r.threshold)}", "passed=#{r.to_h[:passed_count]}", "failed=#{r.to_h[:failed_count]}", ].join(' ') end |
#test_name(response = nil) ⇒ Object
65 66 67 68 |
# File 'lib/cem_acpt/test_runner/log_formatter/scan_result_formatter.rb', line 65 def test_name(response = nil) super(response) log_subject.test_case end |