summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-xlib/puppet/server/report.rb89
1 files changed, 84 insertions, 5 deletions
diff --git a/lib/puppet/server/report.rb b/lib/puppet/server/report.rb
index 3c1455105..7be44fa44 100755
--- a/lib/puppet/server/report.rb
+++ b/lib/puppet/server/report.rb
@@ -2,17 +2,63 @@ module Puppet
class Server
# A simple server for triggering a new run on a Puppet client.
class Report < Handler
- @interface = XMLRPC::Service::Interface.new("puppetrunner") { |iface|
+ @interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
iface.add_method("string report(array)")
}
Puppet.setdefaults(:reporting,
- :reportdirectory => ["$vardir/reports",
- "The directory in which to store reports received from the
- client. Each client gets a separate subdirectory."]
+ :reportdirectory => {:default => "$vardir/reports",
+ :mode => 0750,
+ :owner => "$user",
+ :group => "$group",
+ :desc => "The directory in which to store reports received from the
+ client. Each client gets a separate subdirectory."},
+ :reports => ["none",
+ "The list of reports to generate. All reports are looked for
+ in puppet/reports/<name>.rb, and multiple report names should be
+ comma-separated (whitespace is okay)."
+ ]
)
- def initialize
+ @hooks = {}
+
+ class << self
+ attr_reader :hooks
+ end
+
+ # Add a hook for processing reports.
+ def self.newreport(name, &block)
+ name = name.intern if name.is_a? String
+ @hooks[name] = block
+ end
+
+ def self.report(name)
+ name = name.intern if name.is_a? String
+ unless @hooks.include? name
+ begin
+ require "puppet/reports/#{name}"
+ unless @hooks.include? name
+ Puppet.warning(
+ "Loaded report file for %s but report was not defined" %
+ name
+ )
+ return nil
+ end
+ rescue LoadError => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
+ Puppet.warning "Could not load report %s: %s" %
+ [name, detail]
+ next
+ end
+ end
+
+ @hooks[name]
+ end
+
+ def initialize(*args)
+ super
Puppet.config.use(:reporting)
end
@@ -38,6 +84,8 @@ class Server
report = CGI.unescape(report)
end
+ process(report)
+
# We don't want any tracking back in the fs. Unlikely, but there
# you go.
client.gsub("..",".")
@@ -73,6 +121,37 @@ class Server
# Our report is in YAML
return file
end
+
+ private
+
+ # Process the report using all of the existing hooks.
+ def process(report)
+ return if Puppet[:reports] == "none"
+
+ # First convert the report to real objects
+ begin
+ report = YAML.load(report)
+ rescue => detail
+ Puppet.warning "Could not load report: %s" % detail
+ return
+ end
+
+ Puppet[:reports].split(/\s*,\s*/).each do |name|
+ next unless hook = self.class.report(name)
+
+ Puppet.info "Processing report %s" % name
+
+ begin
+ hook.call(report)
+ rescue => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
+ Puppet.err "Report %s failed: %s" %
+ [name, detail]
+ end
+ end
+ end
end
end
end