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
54 def self.register_report(name, options = {}, &block)
55   name = name.intern
56 
57   mod = genmodule(name,
58                   :extend    => Puppet::Util::Docs,
59                   :hash      => instance_hash(:report),
60                   :overwrite => true,
61                   :block     => block)
62 
63   mod.useyaml = true if options[:useyaml]
64 
65   mod.send(:define_method, :report_name) do
66     name
67   end
68 end
reportdocs() click to toggle source

Collects the docs for all reports. @api private

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

Lists each of the reports. @api private

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