class Puppet::Reports

This class is an implementation of a simple mechanism for loading and returning reports. The intent is that a user registers a report by calling {register_report} and providing a code block that performs setup, and defines a method called `process`. The setup, and the `process` method are called in the context where `self` is an instance of {Puppet::Transaction::Report} which provides the actual data for the report via its methods.

@example Minimal scaffolding for a report…

Puppet::Reports::.register_report(:myreport) do
  # do setup here
  def process
    if self.status == 'failed'
      msg = "failed puppet run for #{self.host} #{self.status}"
      . . .
    else
      . . .
    end
  end
end

Required configuration: –

@see Puppet::Transaction::Report @api public

Attributes

hooks[R]

@api private

Public Class Methods

register_report(name, options = {}, &block) click to toggle source

Adds a new report type. The block should contain setup, and define a method with the name `process`. The `process` method is called when the report is executed; the `process` method has access to report data via methods available in its context where `self` is an instance of {Puppet::Transaction::Report}.

For an example, see the overview of this class.

@param name [Symbol] the name of the report (do not use whitespace in the name). @param options [Hash] a hash of options @option options [Boolean] :useyaml whether yaml should be used or not @todo Uncertain what the options :useyaml really does; “whether yaml should be used or not”, used where/how?

   # File lib/puppet/reports.rb
55 def self.register_report(name, options = {}, &block)
56   name = name.intern
57 
58   mod = genmodule(name,
59                   :extend    => Puppet::Util::Docs,
60                   :hash      => instance_hash(:report),
61                   :overwrite => true,
62                   :block     => block)
63 
64   mod.useyaml = true if options[:useyaml]
65 
66   mod.send(:define_method, :report_name) do
67     name
68   end
69 end
reportdocs() click to toggle source

Collects the docs for all reports. @api private

   # File lib/puppet/reports.rb
73 def self.reportdocs
74   docs = String.new
75 
76   # Use this method so they all get loaded
77   instance_loader(:report).loadall(Puppet.lookup(:current_environment))
78   loaded_instances(:report).sort_by(&:to_s).each do |name|
79     mod = self.report(name)
80     docs << "#{name}\n#{"-" * name.to_s.length}\n"
81 
82     docs << Puppet::Util::Docs.scrub(mod.doc) << "\n\n"
83   end
84 
85   docs
86 end
reports() click to toggle source

Lists each of the reports. @api private

   # File lib/puppet/reports.rb
90 def self.reports
91   instance_loader(:report).loadall(Puppet.lookup(:current_environment))
92   loaded_instances(:report)
93 end