From 82a4e21cf768f2f408df52f16db64539881580fa Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Thu, 8 Sep 2016 17:37:09 +0200 Subject: [PATCH] add sys_info resource to get information about the hostname --- lib/inspec/resource.rb | 1 + lib/resources/sys_info.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/resources/sys_info.rb diff --git a/lib/inspec/resource.rb b/lib/inspec/resource.rb index 9039db1c8..d43530112 100644 --- a/lib/inspec/resource.rb +++ b/lib/inspec/resource.rb @@ -106,6 +106,7 @@ require 'resources/service' require 'resources/shadow' require 'resources/ssl' require 'resources/ssh_conf' +require 'resources/sys_info' require 'resources/users' require 'resources/vbscript' require 'resources/windows_feature' diff --git a/lib/resources/sys_info.rb b/lib/resources/sys_info.rb new file mode 100644 index 000000000..70541ae2d --- /dev/null +++ b/lib/resources/sys_info.rb @@ -0,0 +1,26 @@ +# encoding: utf-8 +module Inspec::Resources + # this resource returns additional system informatio + class System < Inspec.resource(1) + name 'sys_info' + + desc 'Use the user InSpec system resource to test for operating system properties.' + example " + describe sysinfo do + its('hostname') { should eq 'example.com' } + end + " + + def hostname + os = inspec.os + if os.linux? + inspec.command('hostname').stdout.chomp + elsif os.windows? + # windows hostname + inspec.powershell('$env:computername').stdout.chomp + else + return skip_resource 'The `system` resource is not supported on your OS yet.' + end + end + end +end