Class: Openvas::Scan

Inherits:
Client show all
Defined in:
lib/openvas/scan.rb

Overview

Class used to interact with OpenVAS’ scans

Constant Summary

Constants inherited from Client

Client::BLOCK_SIZE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

connect, disconnect, query, version

Constructor Details

#initialize(scan) ⇒ Scan

Returns a new instance of Scan.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/openvas/scan.rb', line 10

def initialize(scan)
  @id = scan.at_xpath('@id').value
  @name = scan.at_xpath('name').text
  @comment = scan.at_xpath('comment').text
  @user = scan.at_xpath('owner/name').text
  @trend = scan.at_xpath('trend').text
  @status = scan.at_xpath('status').text
  @target = scan.at_xpath('target')&.first_element_child&.text

  @created_at = Time.parse(scan.at_xpath('creation_time').text)
  @updated_at = Time.parse(scan.at_xpath('modification_time').text)

  @last_report_id = scan.at_xpath('last_report/report/@id')&.value
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def comment
  @comment
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def id
  @id
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def name
  @name
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def status
  @status
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def target
  @target
end

#trendObject

Returns the value of attribute trend.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def trend
  @trend
end

#updated_atObject

Returns the value of attribute updated_at.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def updated_at
  @updated_at
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'lib/openvas/scan.rb', line 8

def user
  @user
end

Class Method Details

.allObject



38
39
40
41
42
43
44
# File 'lib/openvas/scan.rb', line 38

def all
  data = Nokogiri::XML::Builder.new { get_tasks }

  query(data).xpath('//get_tasks_response/task').map do |scan|
    new(scan)
  end
end

.find_by(id:) ⇒ Object



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

def find_by(id:)
  data = Nokogiri::XML::Builder.new { get_tasks(task_id: id) }
  new(query(data).at_xpath('//get_tasks_response/task'))
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/openvas/scan.rb', line 33

def finished?
  @status == 'Done'
end

#last_reportObject



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

def last_report
  Openvas::Reports.find_by_id(@last_report_id)
end

#last_resultsObject



29
30
31
# File 'lib/openvas/scan.rb', line 29

def last_results
  Openvas::Result.find_by_report_id(@last_report_id)
end