inspec-reporter-honeycomb 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4eb32b04b057f01512ba79db4145ff08b2dcddc65180315cba4fafd6e5a16ee9
4
+ data.tar.gz: e74b389396a6930562af472ae1fa2c77bac31e5bc6126e0dabb9951277ab9f7d
5
+ SHA512:
6
+ metadata.gz: 3e2697d9f64be8d886aa04b2bcb5d97d14473d409b8e2e6be172ee4db9ed9894299296d6500bc642ba52fad5c134bded41c808585c9e88243c63b537e77995a9
7
+ data.tar.gz: ac1d78f88a59a2e754209c2ae91bbc71094956cc3cbfae57d967c88b971e50e160488384de8f87c7a7b278a996d0dc428a8446229bbbcd1ec779cef663c9e3b9
@@ -0,0 +1,14 @@
1
+ require 'inspec/plugin/v2'
2
+
3
+ module InspecPlugins
4
+ module HoneycombReporter
5
+ class Plugin < Inspec.plugin(2)
6
+ plugin_name :'inspec-reporter-honeycomb'
7
+
8
+ reporter :honeycomb do
9
+ require_relative 'reporter.rb'
10
+ InspecPlugins::HoneycombReporter::Reporter
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,135 @@
1
+
2
+ require 'inspec/plugin/v2'
3
+ require 'json'
4
+ require "securerandom" unless defined?(SecureRandom)
5
+
6
+ module InspecPlugins::HoneycombReporter
7
+ # Reporter Plugin Class
8
+ class Reporter < Inspec.plugin(2, :reporter)
9
+ def render
10
+ output(report.to_json, false)
11
+ end
12
+
13
+ def self.run_data_schema_constraints
14
+ '~> 0.0' # Accept any non-breaking change
15
+ end
16
+
17
+ def report
18
+ report = Inspec::Reporters::Json.new(@config).report
19
+ trace_id = SecureRandom.hex(16)
20
+ root_span_id = SecureRandom.hex(8)
21
+ trace_batch = []
22
+ root_span_data = Hash.new
23
+ root_span_data[:data] = {
24
+ 'trace.trace_id' => trace_id,
25
+ 'trace.span_id' => root_span_id,
26
+ 'service.name' => 'compliance',
27
+ 'name' => 'inspec-run',
28
+ 'platform.name' => report[:platform][:name],
29
+ 'duration' => report[:statistics][:duration]*1000,
30
+ 'version' => report[:version],
31
+ }
32
+
33
+ trace_batch << root_span_data
34
+
35
+ report[:profiles].each do |profile|
36
+ profile_span_id = SecureRandom.hex(8)
37
+ 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) }
53
+ 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],
61
+ )
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,
67
+ trace_id: trace_id,
68
+ data: profile,
69
+ platform: report[:platform][:name],
70
+ type: 'profile',
71
+ )
72
+ end
73
+
74
+
75
+
76
+ headers = { "Content-Type" => "application/json" }
77
+ headers["X-Honeycomb-Team"] = ENV['HONEYCOMB_API_KEY']
78
+
79
+ uri = URI(ENV['HONEYCOMB_API_URL'])
80
+ req = Net::HTTP::Post.new(uri.path, headers)
81
+ req.body = trace_batch.to_json
82
+ begin
83
+ Inspec::Log.debug "Posting report to Honeycomb: #{uri.path}"
84
+ http = Net::HTTP.new(uri.hostname, uri.port)
85
+ http.use_ssl = uri.scheme == "https"
86
+ if ENV['VERIFY_SSL'] == true
87
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
88
+ else
89
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
90
+ end
91
+
92
+ res = http.request(req)
93
+ if res.is_a?(Net::HTTPSuccess)
94
+ true
95
+ else
96
+ Inspec::Log.error "send_report: POST to #{uri.path} returned: #{res.body}"
97
+ false
98
+ end
99
+ rescue => e
100
+ Inspec::Log.error "send_report: POST to #{uri.path} returned: #{e.message}"
101
+ false
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def generate_span_data(**args)
108
+
109
+ time_in_ms = args[:duration] ? args[:duration] * 1000 : 0
110
+ span_data = {
111
+ 'trace.trace_id' => args[:trace_id],
112
+ 'trace.span_id' => args[:span_id],
113
+ 'service.name' => 'compliance',
114
+ 'trace.parent_id' => args[:parent_id],
115
+ 'platform.name' => args[:platform],
116
+ 'type' => args[:type],
117
+ 'name' => args[:name],
118
+ 'duration' => time_in_ms,
119
+ }
120
+
121
+ args[:data].each do |k,v|
122
+ if v.is_a?(Array)
123
+ value = v.join(",")
124
+ else
125
+ value = v
126
+ end
127
+ span_data[k] = value.to_s
128
+ end
129
+ return_data = Hash.new
130
+ return_data[:data] = span_data
131
+ return_data
132
+ end
133
+
134
+ end
135
+ end
@@ -0,0 +1 @@
1
+ require_relative 'inspec-reporter-honeycomb/plugin'
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspec-reporter-honeycomb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Dufour
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentelemetry-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-exporter-otlp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: inspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: InSpec Reporter plugin to report Otel formatted traces to Honeycomb.
56
+ email:
57
+ - andy.k.dufour@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/inspec-reporter-honeycomb.rb
63
+ - lib/inspec-reporter-honeycomb/plugin.rb
64
+ - lib/inspec-reporter-honeycomb/reporter.rb
65
+ homepage: https://github.com/andy-dufour/inspec-reporter-honeycomb
66
+ licenses:
67
+ - Apache-2.0
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2.7'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.3.11
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: InSpec Reporter plugin for Honeycomb
88
+ test_files: []