summaryrefslogtreecommitdiff
path: root/lib/chef/audit
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2015-05-08 17:30:33 -0700
committerBryan McLellan <btm@loftninjas.org>2015-05-27 14:16:23 -0400
commit9890e02b3bc16ddc2416497ad39acc40afe98c32 (patch)
tree36155fd108e16b599b1f5a7fcc8786e3452cd710 /lib/chef/audit
parent67b9fdc307fd0a7480cc4f11c18540763ec43b09 (diff)
downloadchef-9890e02b3bc16ddc2416497ad39acc40afe98c32.tar.gz
Save and report audit phase failure on run_completed or run_failed.
Diffstat (limited to 'lib/chef/audit')
-rw-r--r--lib/chef/audit/audit_reporter.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb
index a4f84ed7eb..8268de3aa7 100644
--- a/lib/chef/audit/audit_reporter.rb
+++ b/lib/chef/audit/audit_reporter.rb
@@ -34,6 +34,7 @@ class Chef
@rest_client = rest_client
# Ruby 1.9.3 and above "enumerate their values in the order that the corresponding keys were inserted."
@ordered_control_groups = Hash.new
+ @exception = nil
end
def run_context
@@ -59,6 +60,7 @@ class Chef
# known control groups.
def audit_phase_failed(error)
# The stacktrace information has already been logged elsewhere
+ @exception = error
Chef::Log.debug("Audit Reporter failed.")
ordered_control_groups.each do |name, control_group|
audit_data.add_control_group(control_group)
@@ -116,8 +118,10 @@ class Chef
Chef::Log.debug("Sending audit report (run-id: #{audit_data.run_id})")
run_data = audit_data.to_hash
- if error
- run_data[:error] = "#{error.class.to_s}: #{error.message}\n#{error.backtrace.join("\n")}"
+ if @exception || error
+ errors = [@exception, error].uniq.compact
+ errors_messages = errors.map { |err| "#{err.class.to_s}: #{err.message}\n#{err.backtrace.join("\n")}" }
+ run_data[:error] = errors_messages.join("\n")
end
Chef::Log.debug "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}"
@@ -164,6 +168,9 @@ class Chef
time.utc.iso8601.to_s
end
+ def error_message_for_run_data(error)
+ "#{err.class.to_s}: #{err.message}\n#{err.backtrace.join("\n")}"
+ end
end
end
end