# File lib/puppet/application/inspect.rb, line 101
101:   def run_command
102:     benchmark(:notice, "Finished inspection") do
103:       retrieval_starttime = Time.now
104: 
105:       unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname])
106:         raise "Could not find catalog for #{Puppet[:certname]}"
107:       end
108: 
109:       @report.configuration_version = catalog.version
110: 
111:       inspect_starttime = Time.now
112:       @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime)
113: 
114:       if Puppet[:archive_files]
115:         dipper = Puppet::FileBucket::Dipper.new(:Server => Puppet[:archive_file_server])
116:       end
117: 
118:       catalog.to_ral.resources.each do |ral_resource|
119:         audited_attributes = ral_resource[:audit]
120:         next unless audited_attributes
121: 
122:         status = Puppet::Resource::Status.new(ral_resource)
123: 
124:         begin
125:           audited_resource = ral_resource.to_resource
126:         rescue StandardError => detail
127:           puts detail.backtrace if Puppet[:trace]
128:           ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}"
129:           audited_attributes.each do |name|
130:             event = ral_resource.event(
131:                                        :property => name,
132:                                        :status   => "failure",
133:                                        :audited  => true,
134:                                        :message  => "failed to inspect #{name}"
135:                                        )
136:             status.add_event(event)
137:           end
138:         else
139:           audited_attributes.each do |name|
140:             next if audited_resource[name].nil?
141:             # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW
142:             if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent
143:               event = ral_resource.event(
144:                                          :previous_value => audited_resource[name],
145:                                          :property       => name,
146:                                          :status         => "audit",
147:                                          :audited        => true,
148:                                          :message        => "inspected value is #{audited_resource[name].inspect}"
149:                                          )
150:               status.add_event(event)
151:             end
152:           end
153:         end
154:         if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content)
155:           path = ral_resource[:path]
156:           if File.readable?(path)
157:             begin
158:               dipper.backup(path)
159:             rescue StandardError => detail
160:               Puppet.warning detail
161:             end
162:           end
163:         end
164:         @report.add_resource_status(status)
165:       end
166: 
167:       finishtime = Time.now
168:       @report.add_times("inspect", finishtime - inspect_starttime)
169:       @report.finalize_report
170: 
171:       begin
172:         @report.save
173:       rescue => detail
174:         puts detail.backtrace if Puppet[:trace]
175:         Puppet.err "Could not send report: #{detail}"
176:       end
177:     end
178:   end