Class: ThreatScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_support/threat_scanner.rb

Overview

Runs a virus/malware check against the given path, using ClamAV.

Sample usage:

# Call with a file object:
ThreatScanner.new(@unknown_tempfile).check!

# ...or with a path:
ThreatScanner.new('path/to/README').check!

Defined Under Namespace

Classes: Error, MissingFileError, MissingScannerError, ScannerOperationError, ThreatDetectedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ThreatScanner

Returns a new instance of ThreatScanner.



28
29
30
# File 'lib/ndr_support/threat_scanner.rb', line 28

def initialize(path)
  @path = path.respond_to?(:path) ? path.path : path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/ndr_support/threat_scanner.rb', line 26

def path
  @path
end

Class Method Details

.installed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ndr_support/threat_scanner.rb', line 22

def self.installed?
  system('which clamdscan > /dev/null 2>&1')
end

Instance Method Details

#checkObject

Returns true if the given file is deemed safe, and false if it could not be checked. Raises if a threat is detected, or the file did not exist.



34
35
36
37
38
# File 'lib/ndr_support/threat_scanner.rb', line 34

def check
  check!
rescue MissingScannerError, ScannerOperationError
  false
end

#check!Object

Returns true if the given file is deemed safe, and raises an exception otherwise (if the file is unsafe / does not exist / scanner broke etc).



42
43
44
# File 'lib/ndr_support/threat_scanner.rb', line 42

def check!
  check_existence! && check_installed! && run_scanner!
end