Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Feature/RFC: Remote Ohai Info #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,macos,ruby
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,macos,ruby


# Functional and Unit test data

*.swp
attestations.*
**.lock
test_hdf.json

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
# Icon must end with two
Icon


Expand Down
27 changes: 23 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
inspec-reporter-json-hdf (1.1.1.7.gbd15e2d.1.dirty.20220306.175639)
inspec-reporter-json-hdf (1.1.1.8.g1312bfc.1.dirty.20220306.210617)
git-version-bump
ohai
ruh-roo (~> 3.0.1)

GEM
Expand Down Expand Up @@ -312,6 +313,8 @@ GEM
faraday_middleware (1.0.0)
faraday (~> 1.0)
ffi (1.15.5)
ffi-yajl (2.4.0)
libyajl2 (>= 1.2)
fuzzyurl (0.9.0)
git-version-bump (0.17.1)
google-api-client (0.52.0)
Expand Down Expand Up @@ -374,9 +377,11 @@ GEM
train-core (~> 3.0)
tty-prompt (~> 0.17)
tty-table (~> 0.10)
ipaddress (0.8.3)
jmespath (1.6.0)
json (2.6.1)
jwt (2.3.0)
libyajl2 (2.1.0)
license-acceptance (2.1.13)
pastel (~> 0.7)
tomlrb (>= 1.2, < 3.0)
Expand All @@ -389,13 +394,13 @@ GEM
memoist (0.16.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
minitest-reporters (1.5.0)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
mixlib-cli (2.1.8)
mixlib-config (3.0.9)
tomlrb
mixlib-log (3.0.9)
Expand All @@ -417,17 +422,30 @@ GEM
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nokogiri (1.13.3)
mini_portile2 (~> 2.8.0)
nokogiri (1.13.3-arm64-darwin)
racc (~> 1.4)
nori (2.6.0)
ohai (17.9.0)
chef-config (>= 14.12, < 18)
chef-utils (>= 16.0, < 18)
ffi (~> 1.9)
ffi-yajl (~> 2.2)
ipaddress
mixlib-cli (>= 1.7.0)
mixlib-config (>= 2.0, < 4.0)
mixlib-log (>= 2.0.1, < 4.0)
mixlib-shellout (~> 3.2, >= 3.2.5)
plist (~> 3.1)
train-core
wmi-lite (~> 1.0)
os (1.1.4)
parallel (1.21.0)
parser (3.1.1.0)
ast (~> 2.4.1)
parslet (1.8.2)
pastel (0.8.0)
tty-color (~> 0.5)
plist (3.6.0)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -644,6 +662,7 @@ GEM
rubyzip (~> 2.0)
winrm (~> 2.0)
wisper (2.0.1)
wmi-lite (1.0.5)

PLATFORMS
ruby
Expand Down
1 change: 1 addition & 0 deletions inspec-reporter-json-hdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency 'ruh-roo', '~> 3.0.1'
spec.add_runtime_dependency 'git-version-bump'
spec.add_runtime_dependency 'ohai'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'bundler-audit'
Expand Down
51 changes: 51 additions & 0 deletions lib/inspec-reporter-json-hdf/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'inspec/plugin/v2'
require 'json'
require 'roo'
require 'pry'
require "ohai" unless defined?(Ohai::System)

VALID_FREQUENCY = %w[annually semiannually quarterly monthly every2weeks weekly every3days daily].freeze

Expand All @@ -14,6 +16,55 @@
module InspecPlugins::HdfReporter
# Reporter Plugin Class
class Reporter < Inspec.plugin(2, :reporter)

# references
# https://github.com/chef/ohai/pull/1503/files
# https://github.com/chef/chef/blob/7558c414030d082194d0d2b5f74279ce151517e9/lib/chef/client.rb#L574-L609
#
# binding.pry

# #
# # Populate the minimal ohai attributes defined in #run_ohai with data train collects.
# #
# # Eventually ohai may support colleciton of data.
# #
# def get_ohai_data_remotely
# ohai.data[:fqdn] = if transport_connection.respond_to?(:hostname)
# transport_connection.hostname
# else
# Chef::Config[:target_mode][:host]
# end
# if transport_connection.respond_to?(:os)
# ohai.data[:platform] = transport_connection.os.name
# ohai.data[:platform_version] = transport_connection.os.release
# ohai.data[:os] = transport_connection.os.family_hierarchy[1]
# ohai.data[:platform_family] = transport_connection.os.family
# end
# # train does not collect these specifically
# # ohai.data[:machinename] = nil
# # ohai.data[:hostname] = nil
# # ohai.data[:os_version] = nil # kernel version

# ohai.data[:ohai_time] = Time.now.to_f
# events.ohai_completed(node)
# end

# #
# # Run ohai plugins. Runs all ohai plugins unless minimal_ohai is specified.
# #
# # Sends the ohai_completed event when finished.
# #
# # @see Chef::EventDispatcher#
# # @see Chef::Config#minimal_ohai
# #
# # @api private
# #
# def run_ohai
# filter = Chef::Config[:minimal_ohai] ? %w{fqdn machinename hostname platform platform_version ohai_time os os_version init_package} : nil
# ohai.all_plugins(filter)
# events.ohai_completed(node)
# end

def render
output(report.to_json, false)
end
Expand Down