Commit dfabec4f authored by Christopher Huhn's avatar Christopher Huhn
Browse files

Add ohai plugin to collect sysctl settings

parent 51ee6452
......@@ -2,6 +2,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [1.67.1] - 2022-06-09
### Added
- New Ohai plugin [`sysctl.rb`](files/default/ohai_plugins/sysctl.rb) added to collect
information on sysctl settings
## [1.67.0] - 2022-06-08
### Changed
......
#
# Cookbook Name:: sys
# Ohai plugin to collect sysctl information
#
# Copyright 2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
#
# Authors:
# Christopher Huhn <c.huhn@gsi.de>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Ohai.plugin(:Sysctl) do
provides 'sysctl'
collect_data(:default) do
cmd = 'sysctl -a'
settings = shell_out(cmd).stdout.scan(/^(.*) = (.*)$/)
sysctl Mash.new
settings.each do |key, value|
# skip zero values to reduce space requirements
next if value == '0'
# split the sysctl key into components and create s nice data structure
path = key.split('.')
x = sysctl
path[0..-2].each do |component|
x[component] ||= Mash.new
x = x[component]
end
x[path.last] = value
end
end
end
......@@ -16,4 +16,4 @@ supports 'debian'
depends 'line', '< 1.0'
depends 'chef-vault'
version '1.67.0'
version '1.67.1'
......@@ -101,4 +101,22 @@ describe "plugins" do
})
end
end
describe 'sysctl' do
subject do
@ohai.require_plugin('sysctl')
@ohai.data['sysctl']
end
it { should be_a(Mash) }
it do
# TODO: don't hard-code rsa here
# 'anything' or match(...) don't seem to work for a hash key though
should include(kernel: a_hash_including(
ostype: 'Linux',
version: anything
))
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment