summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-11-20 16:49:15 -0800
committertyler-ball <tyleraball@gmail.com>2014-11-20 16:49:15 -0800
commit3ac2eba09bcd04671f208873dd530f69c82b9851 (patch)
treebb34043584e5f6fa3b28030566c9ef5b6f20d852
parent9e4beb2aa3eecf5672b5b42418727430076fc779 (diff)
downloadchef-tball/start-end-time.tar.gz
Adding start_time and end_time to array per requesttball/start-end-time
-rw-r--r--lib/chef/audit/audit_reporter.rb26
-rw-r--r--lib/chef/audit/control_group_data.rb3
2 files changed, 24 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
diff --git a/lib/chef/audit/control_group_data.rb b/lib/chef/audit/control_group_data.rb
index e19a6e1a15..e221ae94cc 100644
--- a/lib/chef/audit/control_group_data.rb
+++ b/lib/chef/audit/control_group_data.rb
@@ -4,6 +4,7 @@ class Chef
class Audit
class AuditData
attr_reader :node_name, :run_id, :control_groups
+ attr_accessor :start_time, :end_time
def initialize(node_name, run_id)
@node_name = node_name
@@ -19,6 +20,8 @@ class Chef
{
:node_name => node_name,
:run_id => run_id,
+ :start_time => start_time,
+ :end_time => end_time,
:control_groups => control_groups.collect { |c| c.to_hash }
}
end