Class: Inspec::Reporters::Automate
- Inherits:
-
Json
- Object
- Base
- Json
- Inspec::Reporters::Automate
show all
- Defined in:
- lib/inspec/reporters/automate.rb
Instance Attribute Summary
Attributes inherited from Base
#run_data
Instance Method Summary
collapse
Methods inherited from Json
#render, #report
Methods inherited from Base
#output, #render, #rendered_output
Constructor Details
#initialize(config) ⇒ Automate
8
9
10
11
12
13
14
15
16
|
# File 'lib/inspec/reporters/automate.rb', line 8
def initialize(config)
super(config)
@config['verify_ssl'] = !@config['insecure'] if @config.key?('insecure')
@config['verify_ssl'] = @config['verify_ssl'] || false
end
|
Instance Method Details
#enriched_report ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/inspec/reporters/automate.rb', line 18
def enriched_report
final_report = report
final_report[:type] = 'inspec_report'
final_report[:end_time] = Time.now.utc.strftime('%FT%TZ')
final_report[:node_uuid] = @config['node_uuid'] || @run_data[:platform][:uuid]
raise Inspec::ReporterError, 'Cannot find a UUID for your node. Please specify one via json-config.' if final_report[:node_uuid].nil?
final_report[:report_uuid] = @config['report_uuid'] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid])
%w{node_name environment roles recipies job_uuid}.each do |option|
final_report[option.to_sym] = @config[option] unless @config[option].nil?
end
final_report
end
|
#send_report ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/inspec/reporters/automate.rb', line 38
def send_report
= { 'Content-Type' => 'application/json' }
['x-data-collector-token'] = @config['token']
['x-data-collector-auth'] = 'version=1.0'
uri = URI(@config['url'])
req = Net::HTTP::Post.new(uri.path, )
req.body = enriched_report.to_json
begin
Inspec::Log.debug "Posting report to Chef Automate: #{uri.path}"
http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = uri.scheme == 'https'
if @config['verify_ssl'] == true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
else
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.request(req)
return true
rescue => e
Inspec::Log.error "send_report: POST to #{uri.path} returned: #{e.message}"
return false
end
end
|