inspec-reporter-otel-hny 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/inspec-reporter-otel-hny/plugin.rb +14 -0
- data/lib/inspec-reporter-otel-hny/reporter.rb +127 -0
- data/lib/inspec-reporter-otel-hny.rb +1 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '096530e65ec17d5e310808a1ecdd37db07f4d58c2989af5c4ac0d6776f45c18e'
|
4
|
+
data.tar.gz: bb49eceb301994ab2b2ad73bbd154af978ceed2a6f5b1010fe8d9613c70c0a7b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1c98332fc21e95c386e8a303f6a64661f8adb4bb944108fc43d88dcd5befefbd3c0d341b3f98c1b7601a2d83a02643ec2d4dd91cd2f4ca488edacf43096c771
|
7
|
+
data.tar.gz: 5027e346d3f04af00344787009f610a7b15af2549440ed1da944001ad7a540ce795ec24a562b02ec498a5a79122470d8829dde681c3e7fe7497515a5e915e968
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'inspec/plugin/v2'
|
2
|
+
|
3
|
+
module InspecPlugins
|
4
|
+
module OtelHnyReporter
|
5
|
+
class Plugin < Inspec.plugin(2)
|
6
|
+
plugin_name :'inspec-reporter-otel-hny'
|
7
|
+
|
8
|
+
reporter :otelhny do
|
9
|
+
require_relative 'reporter.rb'
|
10
|
+
InspecPlugins::OtelHnyReporter::Reporter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
|
2
|
+
require 'inspec/plugin/v2'
|
3
|
+
require 'json'
|
4
|
+
require "securerandom" unless defined?(SecureRandom)
|
5
|
+
|
6
|
+
module InspecPlugins::OtelHnyReporter
|
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 = {
|
23
|
+
'trace.trace_id' => trace_id,
|
24
|
+
'trace.span_id' => root_span_id,
|
25
|
+
'service.name' => 'compliance',
|
26
|
+
'name' => 'inspec-run',
|
27
|
+
'platform.name' => report[:platform][:name],
|
28
|
+
'duration' => report[:statistics][:duration],
|
29
|
+
'version' => report[:version],
|
30
|
+
}
|
31
|
+
|
32
|
+
trace_batch << root_span_data.to_json
|
33
|
+
|
34
|
+
report[:profiles].each do |profile|
|
35
|
+
profile_span_id = SecureRandom.hex(8)
|
36
|
+
profile[:controls].each do |control|
|
37
|
+
control_span_id = SecureRandom.hex(8)
|
38
|
+
control[:results].each do |result|
|
39
|
+
result_span_id = SecureRandom.hex(8)
|
40
|
+
trace_batch << generate_span_data(
|
41
|
+
parent_id: control_span_id,
|
42
|
+
span_id: result_span_id,
|
43
|
+
trace_id: trace_id,
|
44
|
+
data: result,
|
45
|
+
platform: report[:platform][:name],
|
46
|
+
type: 'result',
|
47
|
+
).to_json
|
48
|
+
end
|
49
|
+
control.tap { |ct| ct.delete(:results) }
|
50
|
+
trace_batch << generate_span_data(
|
51
|
+
parent_id: profile_span_id,
|
52
|
+
span_id: control_span_id,
|
53
|
+
trace_id: trace_id,
|
54
|
+
data: control,
|
55
|
+
platform: report[:platform][:name],
|
56
|
+
type: 'control',
|
57
|
+
).to_json
|
58
|
+
end
|
59
|
+
profile.tap { |pf| pf.delete(:controls) }
|
60
|
+
trace_batch << generate_span_data(
|
61
|
+
parent_id: root_span_id,
|
62
|
+
span_id: profile_span_id,
|
63
|
+
trace_id: trace_id,
|
64
|
+
data: profile,
|
65
|
+
platform: report[:platform][:name],
|
66
|
+
type: 'profile',
|
67
|
+
).to_json
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
headers = { "Content-Type" => "application/json" }
|
73
|
+
headers["X-Honeycomb-Team"] = ENV['HONEYCOMB_API_KEY']
|
74
|
+
|
75
|
+
uri = URI(ENV['HONEYCOMB_API_URL'])
|
76
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
77
|
+
req.body = trace_batch
|
78
|
+
begin
|
79
|
+
Inspec::Log.debug "Posting report to Honeycomb: #{uri.path}"
|
80
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
81
|
+
http.use_ssl = uri.scheme == "https"
|
82
|
+
if ENV['VERIFY_SSL'] == true
|
83
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
84
|
+
else
|
85
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
86
|
+
end
|
87
|
+
|
88
|
+
res = http.request(req)
|
89
|
+
if res.is_a?(Net::HTTPSuccess)
|
90
|
+
true
|
91
|
+
else
|
92
|
+
Inspec::Log.error "send_report: POST to #{uri.path} returned: #{res.body}"
|
93
|
+
false
|
94
|
+
end
|
95
|
+
rescue => e
|
96
|
+
Inspec::Log.error "send_report: POST to #{uri.path} returned: #{e.message}"
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def generate_span_data(**args)
|
104
|
+
span_data = {
|
105
|
+
'trace.trace_id' => args[:trace_id],
|
106
|
+
'trace.span_id' => args[:span_id],
|
107
|
+
'service.name' => 'compliance',
|
108
|
+
'trace.parent_id' => args[:parent_id],
|
109
|
+
'platform.name' => args[:platform],
|
110
|
+
'type' => args[:type],
|
111
|
+
}
|
112
|
+
|
113
|
+
args[:data].each do |k,v|
|
114
|
+
require 'pry';binding.pry
|
115
|
+
if v.is_a?(Array)
|
116
|
+
value = v.join(",")
|
117
|
+
else
|
118
|
+
value = v
|
119
|
+
end
|
120
|
+
span_data[k] = value.to_s
|
121
|
+
end
|
122
|
+
span_data
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'inspec-reporter-otel-hny/plugin'
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inspec-reporter-otel-hny
|
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-otel-hny.rb
|
63
|
+
- lib/inspec-reporter-otel-hny/plugin.rb
|
64
|
+
- lib/inspec-reporter-otel-hny/reporter.rb
|
65
|
+
homepage: https://github.com/andy-dufour/inspec-reporter-otel-hny
|
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 Otel & Honeycomb
|
88
|
+
test_files: []
|