Class: Kafo::PuppetReport
- Inherits:
-
Object
- Object
- Kafo::PuppetReport
- Defined in:
- lib/kafo/puppet_report.rb
Overview
An abstraction over the Puppet report format
Class Method Summary collapse
-
.load_report_file(path) ⇒ PuppetReport
Load a Puppet report from a path.
Instance Method Summary collapse
-
#failed_resources ⇒ Array[PuppetFailedResource]
The failed resources and their status.
-
#initialize(report) ⇒ PuppetReport
constructor
A new instance of PuppetReport.
-
#logs ⇒ Array[Hash]
The Puppet logs.
-
#report_format ⇒ Integer
The report format.
Constructor Details
#initialize(report) ⇒ PuppetReport
Returns a new instance of PuppetReport.
35 36 37 |
# File 'lib/kafo/puppet_report.rb', line 35 def initialize(report) @report = report end |
Class Method Details
.load_report_file(path) ⇒ PuppetReport
Load a Puppet report from a path
Both YAML and JSON are supported.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kafo/puppet_report.rb', line 14 def self.load_report_file(path) raise ArgumentError, 'No path given' unless path || path.empty? raise ArgumentError, "#{path} is not a readable file" unless File.file?(path) && File.readable?(path) data = case File.extname(path) when '.yaml' require 'yaml' content = File.read(path).gsub(%r{!ruby/object.*$}, '') YAML.safe_load(content, permitted_classes: [Time, Symbol]) when '.json' require 'json' JSON.parse(File.read(path)) else raise ArgumentError, "Unsupported file extension for #{path}" end PuppetReport.new(data) end |
Instance Method Details
#failed_resources ⇒ Array[PuppetFailedResource]
Returns The failed resources and their status.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kafo/puppet_report.rb', line 50 def failed_resources statuses = @report['resource_statuses'] raise PuppetReportError, "No resource statuses found in report" unless statuses statuses.select { |_title, status| status['failed'] }.map do |title, status| # TODO: There's also a message with source Puppet # Executing with uid=USER: '/tmp/failing-command' # This shows up after Executing '/tmp/failing-command' = logs.select { |log| log['source'].include?(title) } PuppetFailedResource.new(status, ) end end |
#logs ⇒ Array[Hash]
Returns The Puppet logs.
45 46 47 |
# File 'lib/kafo/puppet_report.rb', line 45 def logs @report['logs'] end |
#report_format ⇒ Integer
Returns The report format.
40 41 42 |
# File 'lib/kafo/puppet_report.rb', line 40 def report_format @report['report_format'] end |