diff options
Diffstat (limited to 'lib/chef/audit/audit_reporter.rb')
-rw-r--r-- | lib/chef/audit/audit_reporter.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index 28a9940af4..0a108ef278 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -24,8 +24,8 @@ class Chef class Audit class AuditReporter < EventDispatch::Base - attr_reader :rest_client, :audit_data, :ordered_control_groups - private :rest_client, :audit_data, :ordered_control_groups + attr_reader :rest_client, :audit_data, :ordered_control_groups, :run_status + private :rest_client, :audit_data, :ordered_control_groups, :run_status PROTOCOL_VERSION = '0.1.0' @@ -39,6 +39,7 @@ class Chef def audit_phase_start(run_status) Chef::Log.debug("Audit Reporter starting") @audit_data = AuditData.new(run_status.node.name, run_status.run_id) + @run_status = run_status end def audit_phase_complete @@ -46,7 +47,6 @@ class Chef ordered_control_groups.each do |name, control_group| audit_data.add_control_group(control_group) end - post_auditing_data end # If the audit phase failed, its because there was some kind of error in the framework @@ -57,7 +57,14 @@ class Chef ordered_control_groups.each do |name, control_group| audit_data.add_control_group(control_group) end - post_auditing_data(error) + end + + def run_completed(node) + post_auditing_data + end + + def run_failed(error) + post_reporting_data(error) end def control_group_started(name) @@ -77,8 +84,9 @@ class Chef control_group.example_failure(example_data, error.message) end + # If @audit_enabled is nil or true, we want to run audits def auditing_enabled? - @audit_enabled + @audit_enabled != false end private @@ -89,6 +97,14 @@ class Chef return end + unless run_status + Chef::Log.debug("Run failed before audits were initialized, not sending audit report to server") + return + end + + audit_data.start_time = run_status.start_time.utc.iso8601.to_s + audit_data.end_time = run_status.end_time.utc.iso8601.to_s + audit_history_url = "controls" Chef::Log.info("Sending audit report (run-id: #{audit_data.run_id})") run_data = audit_data.to_hash |