diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-13 14:07:24 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-13 14:07:24 -0500 |
commit | 29feac0cecddc910b74601d0914fa2c83757b10c (patch) | |
tree | 888305ecde1e4a488304f7e2e169bf1ca38e6d19 /lib/puppet/indirector/code | |
parent | 74d77f76a012d523430e43f1092609a4ca584cc7 (diff) | |
download | puppet-29feac0cecddc910b74601d0914fa2c83757b10c.tar.gz puppet-29feac0cecddc910b74601d0914fa2c83757b10c.tar.xz puppet-29feac0cecddc910b74601d0914fa2c83757b10c.zip |
Translating the report handler to an indirected model.
I've provided backward compatibility with the old
handler.
The only terminus type that currently exists for reports
is the 'code' terminus, which is used to process reports
in the style of the old handler. At some point, we should
likely switch at least some of these report types (e.g., 'store')
to terminus types.
Diffstat (limited to 'lib/puppet/indirector/code')
-rw-r--r-- | lib/puppet/indirector/code/report.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/puppet/indirector/code/report.rb b/lib/puppet/indirector/code/report.rb new file mode 100644 index 000000000..a3c3a6df5 --- /dev/null +++ b/lib/puppet/indirector/code/report.rb @@ -0,0 +1,49 @@ +require 'puppet/indirector/code' +require 'puppet/reports' + +class Puppet::Indirector::Code::Report < Puppet::Indirector::Code + desc "Puppet's report processor. Processes the report with each of + the report types listed in the 'reports' setting." + + def initialize + Puppet.settings.use(:reporting, :metrics) + end + + def save(report) + process(report) + end + + private + + # Process the report with each of the configured report types. + # LAK:NOTE This isn't necessarily the best design, but it's backward + # compatible and that's good enough for now. + def process(report) + return if Puppet[:reports] == "none" + + reports().each do |name| + if mod = Puppet::Reports.report(name) + # We have to use a dup because we're including a module in the + # report. + newrep = report.dup + begin + newrep.extend(mod) + newrep.process + rescue => detail + if Puppet[:trace] + puts detail.backtrace + end + Puppet.err "Report %s failed: %s" % + [name, detail] + end + else + Puppet.warning "No report named '%s'" % name + end + end + end + + # Handle the parsing of the reports attribute. + def reports + Puppet[:reports].gsub(/(^\s+)|(\s+$)/, '').split(/\s*,\s*/) + end +end |