Class: Inspec::Resources::KernelParameter

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

Direct Known Subclasses

LinuxKernelParameter

Instance Method Summary collapse

Constructor Details

#initialize(parameter = nil) ⇒ KernelParameter

Returns a new instance of KernelParameter.



14
15
16
17
18
19
# File 'lib/inspec/resources/kernel_parameter.rb', line 14

def initialize(parameter = nil)
  @parameter = parameter

  # 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

#resource_idObject



32
33
34
# File 'lib/inspec/resources/kernel_parameter.rb', line 32

def resource_id
  @parameter || "Kernel Parameter"
end

#to_sObject



36
37
38
# File 'lib/inspec/resources/kernel_parameter.rb', line 36

def to_s
  "Kernel Parameter #{@parameter}"
end

#valueObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/inspec/resources/kernel_parameter.rb', line 21

def value
  cmd = inspec.command("/sbin/sysctl -q -n #{@parameter}")
  return nil if cmd.exit_status != 0

  # remove whitespace
  cmd = cmd.stdout.chomp.strip
  # convert to number if possible
  cmd = cmd.to_i if cmd =~ /^\d+$/
  cmd
end