summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 17:11:10 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-06-29 17:11:10 +0000
commit1677594f3de4070af8712515a20e6448b990ba8d (patch)
treeda9668ae2a155b365e8c8c3ce8fef5e97df88df0 /lib/puppet/server
parent56a28456c240bc25b89a4a6b02e39aaaef162391 (diff)
downloadpuppet-1677594f3de4070af8712515a20e6448b990ba8d.tar.gz
puppet-1677594f3de4070af8712515a20e6448b990ba8d.tar.xz
puppet-1677594f3de4070af8712515a20e6448b990ba8d.zip
Adding reporting client, server, and tests. At this point, the server just stores the report in a file as YAML.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1337 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-xlib/puppet/server/report.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/puppet/server/report.rb b/lib/puppet/server/report.rb
new file mode 100755
index 000000000..3c1455105
--- /dev/null
+++ b/lib/puppet/server/report.rb
@@ -0,0 +1,80 @@
+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|
+ 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."]
+ )
+
+ def initialize
+ Puppet.config.use(:reporting)
+ end
+
+ def mkclientdir(client, dir)
+ Puppet.config.setdefaults("reportclient-#{client}",
+ :clientdir => { :default => dir,
+ :mode => 0750,
+ :owner => "$user",
+ :group => "$group"
+ }
+ )
+
+ Puppet.config.use("reportclient-#{client}")
+ end
+
+ # Accept a report from a client.
+ def report(report, client = nil, clientip = nil)
+ # We need the client name for storing files.
+ client ||= Facter["hostname"].value
+
+ # Unescape the report
+ unless @local
+ report = CGI.unescape(report)
+ end
+
+ # We don't want any tracking back in the fs. Unlikely, but there
+ # you go.
+ client.gsub("..",".")
+
+ dir = File.join(Puppet[:reportdirectory], client)
+
+ unless FileTest.exists?(dir)
+ mkclientdir(client, dir)
+ end
+
+ # Now store the report.
+ now = Time.now.gmtime
+ name = %w{year month day hour min}.collect do |method|
+ # Make sure we're at least two digits everywhere
+ "%02d" % now.send(method).to_s
+ end.join("") + ".yaml"
+
+ file = File.join(dir, name)
+
+ begin
+ File.open(file, "w", 0640) do |f|
+ f.puts report
+ end
+ rescue => detail
+ if Puppet[:debug]
+ puts detail.backtrace
+ end
+ Puppet.warning "Could not write report for %s at %s: %s" %
+ [client, file, detail]
+ end
+
+
+ # Our report is in YAML
+ return file
+ end
+ end
+end
+end
+
+# $Id$