Class: NessusAPI::Scan

Inherits:
Object
  • Object
show all
Defined in:
lib/nessus_api/scan.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, scan_name, policy, session = Session.current) ⇒ Scan

The class that handles API calls for individuals scans.



9
10
11
12
13
14
15
16
17
18
# File 'lib/nessus_api/scan.rb', line 9

def initialize(target, scan_name, policy, session=Session.current)
  # Creates a new scan on the Nessus
  # installation using the given params.
  @target = target
  @name = scan_name
  @policy = policy
  @session = session
  @uuid = @session.get('scan/new', {'target' => @target,
    'scan_name' => @name, 'policy_id' => @policy}).at_css("uuid").text
end

Class Method Details

.list(session = Session.current) ⇒ Object



50
51
52
53
# File 'lib/nessus_api/scan.rb', line 50

def self.list(session = Session.current)
  # Returns all currently running scan jobs.
  session.scanList
end

Instance Method Details

#changeStatus(path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/nessus_api/scan.rb', line 35

def changeStatus(path)
  # Helper function for stop, pause
  # and resume.
  if @session.get("scan/#{path}",
                  {'scan_uuid' => @uuid}).css('status').text == 'OK'
    return true
  else
    return false
  end
end

#pauseObject



24
25
26
27
# File 'lib/nessus_api/scan.rb', line 24

def pause
  # Pauses the current scan.
  changeStatus('pause')
end

#resumeObject



29
30
31
32
33
# File 'lib/nessus_api/scan.rb', line 29

def resume
  # Resumes the current scan from being
  # paused.
  changeStatus('resume')
end

#stopObject



20
21
22
# File 'lib/nessus_api/scan.rb', line 20

def stop
  changeStatus('stop')
end

#uuidObject



46
47
48
# File 'lib/nessus_api/scan.rb', line 46

def uuid
  @uuid
end