Class: Inspec::Resources::KernelModule

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/kernel_module.rb

Instance Method Summary collapse

Constructor Details

#initialize(modulename = nil) ⇒ KernelModule

Returns a new instance of KernelModule.



36
37
38
39
40
# File 'lib/inspec/resources/kernel_module.rb', line 36

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." unless inspec.os.linux?
end

Instance Method Details

#blacklisted?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/inspec/resources/kernel_module.rb', line 63

def blacklisted?
  !modprobe_output.match(/^blacklist\s+#{@module}/).nil? || disabled_via_bin_true? || disabled_via_bin_false?
end

#disabled?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/inspec/resources/kernel_module.rb', line 59

def disabled?
  !modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/(true|false)}).nil?
end

#loaded?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/inspec/resources/kernel_module.rb', line 42

def loaded?
  if inspec.os.redhat? || inspec.os.name == "fedora"
    lsmod_cmd = "/sbin/lsmod"
  else
    lsmod_cmd = "lsmod"
  end

  # 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

#resource_idObject



72
73
74
# File 'lib/inspec/resources/kernel_module.rb', line 72

def resource_id
  @module || "Kernel Module"
end

#to_sObject



76
77
78
# File 'lib/inspec/resources/kernel_module.rb', line 76

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

#versionObject



67
68
69
70
# File 'lib/inspec/resources/kernel_module.rb', line 67

def version
  cmd = inspec.command("#{modinfo_cmd_for_os} -F version #{@module}")
  cmd.exit_status == 0 ? cmd.stdout.delete("\n") : nil
end