Sha256: 2d0d94fd0081ff1d257acceba8bb94f0e0f36e95fdad81cad16686092362bcec

Contents?: true

Size: 1.25 KB

Versions: 31

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
# license: All rights reserved

module Inspec::Resources
  class KernelModule < Inspec.resource(1)
    name 'kernel_module'
    desc 'Use the kernel_module InSpec audit resource to test kernel modules on Linux platforms. These parameters are located under /lib/modules. Any submodule may be tested using this resource.'
    example "
      describe kernel_module('bridge') do
        it { should be_loaded }
      end
    "

    def initialize(modulename = nil)
      @module = modulename

      # this resource is only supported on Linux
      return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
    end

    def loaded?
      # default lsmod command
      lsmod_cmd = 'lsmod'
      # special care for CentOS 5 and sudo
      lsmod_cmd = '/sbin/lsmod' if inspec.os[:family] == 'centos' && inspec.os[:release].to_i == 5

      # get list of all modules
      cmd = inspec.command(lsmod_cmd)
      return false if cmd.exit_status != 0

      # check if module is loaded
      re = Regexp.new('^'+Regexp.quote(@module)+'\s')
      found = cmd.stdout.match(re)
      !found.nil?
    end

    def to_s
      "Kernel Module #{@module}"
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
inspec-0.28.1 lib/resources/kernel_module.rb
inspec-0.28.0 lib/resources/kernel_module.rb
inspec-0.27.1 lib/resources/kernel_module.rb
inspec-0.27.0 lib/resources/kernel_module.rb
inspec-0.26.0 lib/resources/kernel_module.rb
inspec-0.25.0 lib/resources/kernel_module.rb
inspec-0.24.0 lib/resources/kernel_module.rb
inspec-0.23 lib/resources/kernel_module.rb
inspec-0.22.1 lib/resources/kernel_module.rb
inspec-0.22.0 lib/resources/kernel_module.rb
inspec-0.21.6 lib/resources/kernel_module.rb
inspec-0.21.5 lib/resources/kernel_module.rb
inspec-0.21.4 lib/resources/kernel_module.rb
inspec-0.21.3 lib/resources/kernel_module.rb
inspec-0.21.2 lib/resources/kernel_module.rb
inspec-0.21.1 lib/resources/kernel_module.rb
inspec-0.21.0 lib/resources/kernel_module.rb
inspec-0.20.1 lib/resources/kernel_module.rb
inspec-0.20.0 lib/resources/kernel_module.rb
inspec-0.19.2 lib/resources/kernel_module.rb