Class: Inspec::Reporters::Automate
Instance Attribute Summary
Attributes inherited from Base
#run_data
Instance Method Summary
collapse
#render, #report
Methods inherited from Json
#render, #report
Methods inherited from Base
#output, #render, #rendered_output
Constructor Details
#initialize(config) ⇒ Automate
6
7
8
9
10
11
12
13
14
|
# File 'lib/inspec/reporters/automate.rb', line 6
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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/inspec/reporters/automate.rb', line 16
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"] || @config["target_id"]
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])
final_report
end
|
#send_report ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/inspec/reporters/automate.rb', line 32
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
res = http.request(req)
if res.is_a?(Net::HTTPSuccess)
return true
else
Inspec::Log.error "send_report: POST to #{uri.path} returned: #{res.body}"
return false
end
rescue => e
Inspec::Log.error "send_report: POST to #{uri.path} returned: #{e.message}"
return false
end
end
|