diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-29 20:32:17 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-06-29 20:32:17 +0000 |
commit | e47a98769380b37ec1ee65cf922ce2cc7aa7b88a (patch) | |
tree | a973a2e6346e9e08b2b4684e01f61e5a196e9e78 /lib/puppet/server | |
parent | ea9189604a5f8475a87ec03415a1a47681eba0fb (diff) | |
download | puppet-e47a98769380b37ec1ee65cf922ce2cc7aa7b88a.tar.gz puppet-e47a98769380b37ec1ee65cf922ce2cc7aa7b88a.tar.xz puppet-e47a98769380b37ec1ee65cf922ce2cc7aa7b88a.zip |
First commit of complete reporting support. The only existing report at this point is the tagmail report. I expect reporting to get significantly modified from here, but it is a good start.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1339 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-x | lib/puppet/server/report.rb | 89 |
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 |