Sha256: 214bb374013506ff01976a9e7ae7bff4d4c6d87d9fa117ce3425790dd28480ae

Contents?: true

Size: 1.08 KB

Versions: 50

Compression:

Stored size: 1.08 KB

Contents

module Serverspec::Type
  class LinuxAuditSystem < Base
    def initialize(name=nil)
      @name = 'linux_audit_system'
      @runner = Specinfra::Runner
      @rules_content = nil
    end

    def enabled?
      status_of('enabled') == '1'
    end

    def running?
      pid = status_of('pid')
      (!pid.nil? && pid.size > 0 && pid != '0')
    end

    def rules
      if @rules_content.nil?
        @rules_content = @runner.run_command('/sbin/auditctl -l').stdout || ''
      end
      @rules_content
    end

    private

    def status_of(part)
      cmd = "/sbin/auditctl -s"
      status_str = @runner.run_command(cmd).stdout.chomp
      status_map = parse_status(status_str)
      status_map[part] || ''
    end

    def parse_status(status_str)
      map = nil
      if status_str =~ /^AUDIT_STATUS/ then
        map = status_str.split(' ')[1..-1].inject({}) { |res,elem| a = elem.split('='); res.store(a[0],a[1] || ''); res }
      else
        map = status_str.split("\n").inject({}) { |res,elem| a = elem.split(' '); res.store(a[0],a[1] || ''); res } 
      end
      map
    end

  end
end

Version data entries

50 entries across 50 versions & 3 rubygems

Version Path
serverspec-2.38.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.37.2 lib/serverspec/type/linux_audit_system.rb
serverspec-2.37.1 lib/serverspec/type/linux_audit_system.rb
serverspec-2.37.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.36.1 lib/serverspec/type/linux_audit_system.rb
serverspec-2.36.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.35.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.34.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.33.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.32.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.31.1 lib/serverspec/type/linux_audit_system.rb
serverspec-2.31.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.30.1 lib/serverspec/type/linux_audit_system.rb
serverspec-2.30.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.29.2 lib/serverspec/type/linux_audit_system.rb
serverspec-2.29.1 lib/serverspec/type/linux_audit_system.rb
serverspec-2.29.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.28.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.27.0 lib/serverspec/type/linux_audit_system.rb
serverspec-2.26.0 lib/serverspec/type/linux_audit_system.rb