Class: Puppet::Reports

Inherits:
Object show all
Extended by:
Util::ClassGen, Util::InstanceLoader
Defined in:
lib/puppet/reports.rb

Overview

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 Reports.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 Transaction::Report which provides the actual data for the report via its methods.

Required configuration: –

  • A .rb file that defines a new report should be placed in the master’s directory lib/puppet/reports

  • The puppet.conf file must have ‘report = true` in the [agent] section

Examples:

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

See Also:

API:

  • public

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util::ClassGen

genclass, genmodule, rmclass

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::InstanceLoader

instance_docs, instance_hash, instance_load, instance_loader, instance_loading?, loaded_instance, loaded_instances

Class Attribute Details

.hooksObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



39
40
41
# File 'lib/puppet/reports.rb', line 39

def hooks
  @hooks
end

Class Method Details

.register_report(name, options = {}, &block) ⇒ Object

TODO:

Uncertain what the options :useyaml really does; “whether yaml should be used or not”, used where/how?

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 Transaction::Report.

For an example, see the overview of this class.

Parameters:

  • the name of the report (do not use whitespace in the name).

  • (defaults to: {})

    a hash of options

Options Hash (options):

  • :useyaml (Boolean)

    whether yaml should be used or not

API:

  • public



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/puppet/reports.rb', line 54

def self.register_report(name, options = {}, &block)
  name = name.intern

  mod = genmodule(name,
                  :extend    => Puppet::Util::Docs,
                  :hash      => instance_hash(:report),
                  :overwrite => true,
                  :block     => block)

  mod.useyaml = true if options[:useyaml]

  mod.send(:define_method, :report_name) do
    name
  end
end

.reportdocsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Collects the docs for all reports.

API:

  • private



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puppet/reports.rb', line 72

def self.reportdocs
  docs = ""

  # Use this method so they all get loaded
  instance_loader(:report).loadall
  loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
    mod = self.report(name)
    docs << "#{name}\n#{"-" * name.to_s.length}\n"

    docs << Puppet::Util::Docs.scrub(mod.doc) << "\n\n"
  end

  docs
end

.reportsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lists each of the reports.

API:

  • private



89
90
91
92
# File 'lib/puppet/reports.rb', line 89

def self.reports
  instance_loader(:report).loadall
  loaded_instances(:report)
end