Class: Openvas::Result
Overview
Class used to interact with OpenVAS’ scans results
Constant Summary collapse
- MAX_RESULTS =
1000
Constants inherited from Client
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#cves ⇒ Object
Returns the value of attribute cves.
-
#description ⇒ Object
Returns the value of attribute description.
-
#host ⇒ Object
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#port ⇒ Object
Returns the value of attribute port.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(result) ⇒ Result
constructor
A new instance of Result.
- #results ⇒ Object
Methods inherited from Client
connect, disconnect, query, version
Constructor Details
#initialize(result) ⇒ Result
Returns a new instance of Result.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/openvas/result.rb', line 10 def initialize(result) @id = result.at_xpath('@id').value @name = result.at_xpath('name').text @comment = result.at_xpath('comment').text @user = result.at_xpath('owner/name').text @host = result.at_xpath('host').text @port = result.at_xpath('port').text @severity = result.at_xpath('severity').text @description = result.at_xpath('description').text @cves = result.at_xpath('nvt').at_xpath('cve').text.split(',').map(&:strip) @created_at = Time.parse(result.at_xpath('creation_time').text) @updated_at = Time.parse(result.at_xpath('modification_time').text) end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def comment @comment end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def created_at @created_at end |
#cves ⇒ Object
Returns the value of attribute cves.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def cves @cves end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def description @description end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def name @name end |
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def port @port end |
#severity ⇒ Object
Returns the value of attribute severity.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def severity @severity end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def updated_at @updated_at end |
#user ⇒ Object
Returns the value of attribute user.
8 9 10 |
# File 'lib/openvas/result.rb', line 8 def user @user end |
Class Method Details
.all ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/openvas/result.rb', line 32 def all # TODO: implement pagination query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") } query(query).xpath('//get_results_response/result').map do |result| new(result) end end |
.find_by(id:) ⇒ Object
41 42 43 44 |
# File 'lib/openvas/result.rb', line 41 def find_by(id:) query = Nokogiri::XML::Builder.new { get_results(result_id: id) } new(query(query).at_xpath('//get_results_response/result')) end |
.find_by_report_id(id) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/openvas/result.rb', line 46 def find_by_report_id(id) # TODO: implement pagination query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") } query(query).xpath('//get_results_response/result').map do |result| new(result) end end |
Instance Method Details
#results ⇒ Object
25 26 27 |
# File 'lib/openvas/result.rb', line 25 def results Openvas::Result.find_by_report_id(@id) end |