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:

Constant Summary

Constants included from Util

Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE

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, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask

Methods included from Util::POSIX

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

Methods included from Util::SymbolicFileMode

#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::InstanceLoader

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.



41
42
43
# File 'lib/puppet/reports.rb', line 41

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:

  • name (Symbol)

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

  • options (Hash) (defaults to: {})

    a hash of options

Options Hash (options):

  • :useyaml (Boolean)

    whether yaml should be used or not



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

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.



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

def self.reportdocs
  docs = ''.dup

  # Use this method so they all get loaded
  instance_loader(:report).loadall(Puppet.lookup(:current_environment))
  loaded_instances(:report).sort_by(&:to_s).each do |name|
    mod = 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.



91
92
93
94
# File 'lib/puppet/reports.rb', line 91

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