inspec-reporter-honeycomb 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0da6bc7af71195b03caa4c18a6328024ad2707778b9ca183d4bd900d141a0ee7
4
- data.tar.gz: c337c14a866a179a3ea350a60877bab0e9cb5ce178076a6036ab1561ed67f23c
3
+ metadata.gz: 6a8e894a1f5773a7dbfec2acf30dde30e556c46378f12a09e916a782a476588e
4
+ data.tar.gz: e6ad1c6e8c297b22f09aee6b03bfd864ea1f5956469f37a06bf88f1eb30dea97
5
5
  SHA512:
6
- metadata.gz: 0236b9d5449584924e895b2b69fd72e1179b20243d863437668b97140d4cd9d3538a2b88897460fface12228fe749bb4cb954a7165a302a2a6000fe69e44f327
7
- data.tar.gz: 4441f6b32430b734acec407277c6a69a7692352eeacfd05ccb1f2a9bfc15bc288b14344be98ecec6c49cebdc060c8d71f489455481a30697f0b53538287a0f0c
6
+ metadata.gz: d4bfef6d8d1ab99b4cdbcf54d9049f99f6be89830784758136c7488d60c36a6cd13093c3b43fb570bbfc843dee1d9111d6df5e8028cbbcc22cf580b741773163
7
+ data.tar.gz: 4ab196b5290d34d8a8685426139467a8de1fe04489ad1aac536e2473e1b5679c3f0ee29fd7c9ab578f188e5244481cc6b186f9cc7a1e4841b9f0dee7a245ce7b
@@ -1,7 +1,8 @@
1
1
 
2
2
  require 'inspec/plugin/v2'
3
3
  require 'json'
4
- require "securerandom" unless defined?(SecureRandom)
4
+ require 'socket'
5
+ require 'securerandom' unless defined?(SecureRandom)
5
6
 
6
7
  module InspecPlugins::HoneycombReporter
7
8
  # Reporter Plugin Class
@@ -15,10 +16,14 @@ module InspecPlugins::HoneycombReporter
15
16
  end
16
17
 
17
18
  def report
18
- report = Inspec::Reporters::Json.new(@config).report
19
+ report = Inspec::Reporters::JsonAutomate.new(@config).report
19
20
  trace_id = SecureRandom.hex(16)
20
21
  root_span_id = SecureRandom.hex(8)
21
22
  trace_batch = []
23
+ ip_addresses = []
24
+ Socket.ip_address_list.each do |ipaddr|
25
+ ip_addresses << ipaddr.ip_address unless ipaddr.ip_address == '127.0.0.1'
26
+ end
22
27
  root_span_data = Hash.new
23
28
  root_span_data[:data] = {
24
29
  'trace.trace_id' => trace_id,
@@ -26,48 +31,98 @@ module InspecPlugins::HoneycombReporter
26
31
  'service.name' => 'compliance',
27
32
  'name' => 'inspec-run',
28
33
  'platform.name' => report[:platform][:name],
34
+ 'platform.release' => report[:platform][:release],
29
35
  'duration' => report[:statistics][:duration]*1000,
30
36
  'version' => report[:version],
37
+ 'hostname' => Socket.gethostname,
38
+ 'arch' => ::RbConfig::CONFIG['arch'],
39
+ 'os' => ::RbConfig::CONFIG['host_os'],
40
+ 'ip_addresses' => ip_addresses,
31
41
  }
32
42
 
33
43
  trace_batch << root_span_data
34
44
 
35
45
  report[:profiles].each do |profile|
36
46
  profile_span_id = SecureRandom.hex(8)
47
+ profile_duration = 0.0
48
+ profile_statuses = []
49
+ profile_name = profile[:name]
50
+ profile_title = profile[:title]
51
+ profile_version = profile[:version]
52
+ profile_attributes = profile[:attributes]
37
53
  profile[:controls].each do |control|
38
- control_span_id = SecureRandom.hex(8)
39
- control[:results].each do |result|
40
- result_span_id = SecureRandom.hex(8)
41
- trace_batch << generate_span_data(
42
- parent_id: control_span_id,
43
- span_id: result_span_id,
44
- trace_id: trace_id,
45
- data: result,
46
- platform: report[:platform][:name],
47
- type: 'result',
48
- name: result[:code_desc],
49
- duration: result[:run_time],
50
- )
51
- end
52
- control.tap { |ct| ct.delete(:results) }
54
+ control_span_id = SecureRandom.hex(8)
55
+ control_duration = 0.0
56
+ control_statuses = []
57
+ control_name = control[:name]
58
+ control_id = control[:id]
59
+ control_desc = control[:desc]
60
+ control_impact = control[:impact]
61
+ control[:results].each do |result|
62
+ result_span_id = SecureRandom.hex(8)
63
+ control_duration += result[:run_time]
64
+ control_statuses << result[:status]
53
65
  trace_batch << generate_span_data(
54
- parent_id: profile_span_id,
55
- span_id: control_span_id,
56
- trace_id: trace_id,
57
- data: control,
58
- platform: report[:platform][:name],
59
- type: 'control',
60
- name: control[:title],
66
+ parent_id: control_span_id,
67
+ span_id: result_span_id,
68
+ trace_id: trace_id,
69
+ data: result,
70
+ platform: report[:platform][:name],
71
+ platform_release: report[:platform][:release],
72
+ type: 'result',
73
+ name: result[:code_desc],
74
+ duration: result[:run_time],
75
+ profile_name: profile_name,
76
+ profile_title: profile_title,
77
+ profile_version: profile_version,
78
+ profile_attributes: profile_attributes,
79
+ control_name: control_name,
80
+ control_id: control_id,
81
+ control_desc: control_desc,
82
+ control_impact: control_impact,
61
83
  )
62
- end
63
- profile.tap { |pf| pf.delete(:controls) }
64
- trace_batch << generate_span_data(
65
- parent_id: root_span_id,
66
- span_id: profile_span_id,
84
+ end
85
+ control.tap { |ct| ct.delete(:results) }
86
+ profile_duration += control_duration
87
+ profile_statuses += control_statuses
88
+ control_status = get_status(control_statuses)
89
+ trace_batch << generate_span_data(
90
+ parent_id: profile_span_id,
91
+ span_id: control_span_id,
67
92
  trace_id: trace_id,
68
- data: profile,
93
+ data: control,
94
+ status: control_status,
69
95
  platform: report[:platform][:name],
70
- type: 'profile',
96
+ platform_release: report[:platform][:release],
97
+ type: 'control',
98
+ duration: control_duration,
99
+ name: control[:title],
100
+ profile_name: profile_name,
101
+ profile_title: profile_title,
102
+ profile_version: profile_version,
103
+ profile_attributes: profile_attributes,
104
+ control_name: control_name,
105
+ control_id: control_id,
106
+ control_desc: control_desc,
107
+ control_impact: control_impact,
108
+ )
109
+ end
110
+ profile.tap { |pf| pf.delete(:controls); pf.delete(:status) }
111
+ profile_status = get_status(profile_statuses)
112
+ trace_batch << generate_span_data(
113
+ parent_id: root_span_id,
114
+ span_id: profile_span_id,
115
+ trace_id: trace_id,
116
+ data: profile,
117
+ status: profile_status,
118
+ platform: report[:platform][:name],
119
+ platform_release: report[:platform][:release],
120
+ duration: profile_duration,
121
+ type: 'profile',
122
+ profile_name: profile_name,
123
+ profile_title: profile_title,
124
+ profile_version: profile_version,
125
+ profile_attributes: profile_attributes,
71
126
  )
72
127
  end
73
128
 
@@ -91,7 +146,7 @@ module InspecPlugins::HoneycombReporter
91
146
 
92
147
  res = http.request(req)
93
148
  if res.is_a?(Net::HTTPSuccess)
94
- true
149
+ Inspec::Log.debug "send_report: Honeycomb POST to #{uri.path} succeeded and returned: #{res.body} "
95
150
  else
96
151
  Inspec::Log.error "send_report: POST to #{uri.path} returned: #{res.body}"
97
152
  false
@@ -100,10 +155,31 @@ module InspecPlugins::HoneycombReporter
100
155
  Inspec::Log.error "send_report: POST to #{uri.path} returned: #{e.message}"
101
156
  false
102
157
  end
158
+ Inspec::Log.debug "Successfully sent report"
103
159
  end
104
160
 
105
161
  private
106
162
 
163
+ def safe_time(time)
164
+ if time.nil?
165
+ nil
166
+ else
167
+ time.iso8601(fraction_digits = 3)
168
+ end
169
+ end
170
+
171
+ def get_status(status_array)
172
+ if status_array.include?('failed')
173
+ 'failed'
174
+ elsif status_array.include?('skipped') && !status_array.include?('passed')
175
+ 'skipped'
176
+ elsif status_array.empty?
177
+ 'skipped'
178
+ else
179
+ 'passed'
180
+ end
181
+ end
182
+
107
183
  def generate_span_data(**args)
108
184
 
109
185
  time_in_ms = args[:duration] ? args[:duration] * 1000 : 0
@@ -113,9 +189,23 @@ module InspecPlugins::HoneycombReporter
113
189
  'service.name' => 'compliance',
114
190
  'trace.parent_id' => args[:parent_id],
115
191
  'platform.name' => args[:platform],
192
+ 'platform.release' => args[:platform_release],
193
+ 'status' => args[:status],
116
194
  'type' => args[:type],
117
195
  'name' => args[:name],
118
196
  'duration' => time_in_ms,
197
+ 'hostname' => Socket.gethostname,
198
+ 'arch' => ::RbConfig::CONFIG['arch'],
199
+ 'os' => ::RbConfig::CONFIG['host_os'],
200
+ 'ip_addresses' => ip_addresses,
201
+ 'profile.name' => args[:profile_name],
202
+ 'profile.title' => args[:profile_title],
203
+ 'profile.version' => args[:profile_version],
204
+ 'profile.attributes' => args[:profile_attributes],
205
+ 'control.name' => args[:control_name],
206
+ 'control.id' => args[:control_id],
207
+ 'control.desc' => args[:control_desc],
208
+ 'control.impact' => args[:control_impact],
119
209
  }
120
210
 
121
211
  args[:data].each do |k,v|
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-reporter-honeycomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Dufour
8
+ - Davin Taddeo
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2022-08-31 00:00:00.000000000 Z
12
+ date: 2022-09-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: inspec
@@ -27,6 +28,7 @@ dependencies:
27
28
  description: InSpec Reporter plugin to report Otel formatted traces to Honeycomb.
28
29
  email:
29
30
  - andy.k.dufour@gmail.com
31
+ - davin@davintaddeo.com
30
32
  executables: []
31
33
  extensions: []
32
34
  extra_rdoc_files: []