112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/vendor/puppet/application/inspect.rb', line 112
def run_command
benchmark(:notice, "Finished inspection") do
retrieval_starttime = Time.now
unless catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname])
raise "Could not find catalog for #{Puppet[:certname]}"
end
@report.configuration_version = catalog.version
@report.environment = Puppet[:environment]
inspect_starttime = Time.now
@report.add_times("config_retrieval", inspect_starttime - retrieval_starttime)
if Puppet[:archive_files]
dipper = Puppet::FileBucket::Dipper.new(:Server => Puppet[:archive_file_server])
end
catalog.to_ral.resources.each do |ral_resource|
audited_attributes = ral_resource[:audit]
next unless audited_attributes
status = Puppet::Resource::Status.new(ral_resource)
begin
audited_resource = ral_resource.to_resource
rescue StandardError => detail
puts detail.backtrace if Puppet[:trace]
ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}"
audited_attributes.each do |name|
event = ral_resource.event(
:property => name,
:status => "failure",
:audited => true,
:message => "failed to inspect #{name}"
)
status.add_event(event)
end
else
audited_attributes.each do |name|
next if audited_resource[name].nil?
if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent
event = ral_resource.event(
:previous_value => audited_resource[name],
:property => name,
:status => "audit",
:audited => true,
:message => "inspected value is #{audited_resource[name].inspect}"
)
status.add_event(event)
end
end
end
if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content)
path = ral_resource[:path]
if ::File.readable?(path)
begin
dipper.backup(path)
rescue StandardError => detail
Puppet.warning detail
end
end
end
@report.add_resource_status(status)
end
finishtime = Time.now
@report.add_times("inspect", finishtime - inspect_starttime)
@report.finalize_report
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
|