summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application/inspect.rb
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2010-12-16 11:34:09 -0800
committerNick Lewis <nick@puppetlabs.com>2010-12-16 11:34:09 -0800
commita2ff092d8302e09aa79f9bb16636f8298316c3c7 (patch)
treecb67d36e37e252edceef1cd848cc32d679f5d20e /lib/puppet/application/inspect.rb
parent4b35402ba85d8842d757becec5c8a7bf4d6f6654 (diff)
parent480c399f183627f5f588e9dc9f5f86f683c0e468 (diff)
downloadpuppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.tar.gz
puppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.tar.xz
puppet-a2ff092d8302e09aa79f9bb16636f8298316c3c7.zip
Merge branch 'next'
Diffstat (limited to 'lib/puppet/application/inspect.rb')
-rw-r--r--lib/puppet/application/inspect.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb
new file mode 100644
index 000000000..c76f9e4da
--- /dev/null
+++ b/lib/puppet/application/inspect.rb
@@ -0,0 +1,80 @@
+require 'puppet/application'
+
+class Puppet::Application::Inspect < Puppet::Application
+
+ should_parse_config
+ run_mode :agent
+
+ option("--debug","-d")
+ option("--verbose","-v")
+
+ option("--logdest LOGDEST", "-l") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:logset] = true
+ rescue => detail
+ $stderr.puts detail.to_s
+ end
+ end
+
+ def setup
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report]
+
+ @report = Puppet::Transaction::Report.new("inspect")
+
+ Puppet::Util::Log.newdestination(@report)
+ Puppet::Util::Log.newdestination(:console) unless options[:logset]
+
+ trap(:INT) do
+ $stderr.puts "Exiting"
+ exit(1)
+ end
+
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Util::Log.level = :info
+ end
+
+ Puppet::Transaction::Report.indirection.terminus_class = :rest
+ Puppet::Resource::Catalog.indirection.terminus_class = :yaml
+ end
+
+ def run_command
+ retrieval_starttime = Time.now
+
+ unless catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname])
+ raise "Could not find catalog for #{Puppet[:certname]}"
+ end
+
+ retrieval_time = Time.now - retrieval_starttime
+ @report.add_times("config_retrieval", retrieval_time)
+
+ starttime = Time.now
+
+ catalog.to_ral.resources.each do |ral_resource|
+ audited_attributes = ral_resource[:audit]
+ next unless audited_attributes
+
+ audited_resource = ral_resource.to_resource
+
+ status = Puppet::Resource::Status.new(ral_resource)
+ audited_attributes.each do |name|
+ event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}")
+ status.add_event(event)
+ end
+ @report.add_resource_status(status)
+ end
+
+ @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime})
+
+ begin
+ Puppet::Transaction::Report.indirection.save(@report)
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not send report: #{detail}"
+ end
+ end
+end