2016-09-08 15:37:09 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
module Inspec::Resources
|
|
|
|
# this resource returns additional system informatio
|
|
|
|
class System < Inspec.resource(1)
|
|
|
|
name 'sys_info'
|
2018-02-19 14:26:49 +00:00
|
|
|
supports platform: 'unix'
|
|
|
|
supports platform: 'windows'
|
2016-09-08 15:37:09 +00:00
|
|
|
|
|
|
|
desc 'Use the user InSpec system resource to test for operating system properties.'
|
2019-03-19 14:17:32 +00:00
|
|
|
example <<~EXAMPLE
|
2016-09-26 09:56:16 +00:00
|
|
|
describe sys_info do
|
2016-09-08 15:37:09 +00:00
|
|
|
its('hostname') { should eq 'example.com' }
|
|
|
|
end
|
2019-03-19 14:17:32 +00:00
|
|
|
EXAMPLE
|
2016-09-08 15:37:09 +00:00
|
|
|
|
2016-09-09 08:30:41 +00:00
|
|
|
# returns the hostname of the local system
|
2016-09-08 15:37:09 +00:00
|
|
|
def hostname
|
|
|
|
os = inspec.os
|
2017-04-12 10:57:45 +00:00
|
|
|
if os.linux? || os.darwin?
|
2016-09-08 15:37:09 +00:00
|
|
|
inspec.command('hostname').stdout.chomp
|
|
|
|
elsif os.windows?
|
|
|
|
inspec.powershell('$env:computername').stdout.chomp
|
|
|
|
else
|
2016-09-09 08:30:41 +00:00
|
|
|
skip_resource 'The `sys_info.hostname` resource is not supported on your OS yet.'
|
2016-09-08 15:37:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|