Class: OpenvasCli::VasReport
- Defined in:
- lib/openvas-cli/vas_report.rb
Overview
Contains the details of a single OpenVAS report.
Instance Attribute Summary collapse
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#status ⇒ Object
Overall Status Only.
-
#task_id ⇒ Object
Returns the value of attribute task_id.
-
#task_name ⇒ Object
Returns the value of attribute task_name.
Attributes inherited from VasBase
Class Method Summary collapse
-
.get_all(options = {}) ⇒ Object
Pulls report details based off of the options passed.
Instance Method Summary collapse
Methods inherited from VasBase
#create_or_update, #delete_record, #destroy, #destroy!, get_by_id, #initialize, #new_record?, #reset_changes, #save, #save!, #to_key, #to_param, #update_attributes
Methods included from ConnAddin
Methods included from XmlAddin
Constructor Details
This class inherits a constructor from OpenvasCli::VasBase
Instance Attribute Details
#started_at ⇒ Object
Returns the value of attribute started_at.
8 9 10 |
# File 'lib/openvas-cli/vas_report.rb', line 8 def started_at @started_at end |
#status ⇒ Object
Overall Status Only
10 11 12 |
# File 'lib/openvas-cli/vas_report.rb', line 10 def status @status end |
#task_id ⇒ Object
Returns the value of attribute task_id.
6 7 8 |
# File 'lib/openvas-cli/vas_report.rb', line 6 def task_id @task_id end |
#task_name ⇒ Object
Returns the value of attribute task_name.
7 8 9 |
# File 'lib/openvas-cli/vas_report.rb', line 7 def task_name @task_name end |
Class Method Details
.get_all(options = {}) ⇒ Object
Pulls report details based off of the options passed. By default, pulls all reports.
Options:
- :report_id => [report_id]
-
Pulls a specific
report_id. If the id provided is bogus, an empty set is returned. - :levels => [array_of_filter_symbols]
-
Filters the report results by severity. Valid symbols are: [:high, :medium, :low, :log, :deubg].
- :sort => [sort_field]
-
Sorts the report by the given field. Possible values are
:task_name,:started_at. defaults to:started_at - :sort_order => [:ascending, :descending]
-
Order of sort. Defaults to :descending.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openvas-cli/vas_report.rb', line 22 def self.get_all(={}) params = {} params[:report_id] = [:id] if [:id] if [:levels] params[:levels] = "" [:levels].each { |f| case f when :high params[:levels] += 'h' when :medium params[:levels] += 'm' when :low params[:levels] += 'l' when :log params[:levels] += 'g' when :debug params[:levels] += 'd' end } end req = Nokogiri::XML::Builder.new { |xml| if params.empty? xml.get_reports else xml.get_reports(params) end } begin repts = connection.send_receive(req.doc) rescue VasExceptions::CommandException => e raise e unless e. =~ /Failed to find/i return [] end ret = [] repts.xpath('/get_reports_response/report/report').each { |r| rep = VasReport.new rep.id = extract_value_from("@id", r) rep.task_id = extract_value_from("task/@id", r) rep.task_name = extract_value_from("task/name", r) rep.status = extract_value_from("scan_run_status", r) rep.started_at = Time.parse(extract_value_from("scan_start", r)) rep.result_count[:total] = extract_value_from("result_count/full", r).to_i rep.result_count[:filtered] = extract_value_from("result_count/filtered", r).to_i rep.result_count[:debug][:total] = extract_value_from("result_count/debug/full", r).to_i rep.result_count[:debug][:filtered] = extract_value_from("result_count/debug/filtered", r).to_i rep.result_count[:high][:total] = extract_value_from("result_count/hole/full", r).to_i rep.result_count[:high][:filtered] = extract_value_from("result_count/hold/filtered", r).to_i rep.result_count[:low][:total] = extract_value_from("result_count/info/full", r).to_i rep.result_count[:low][:filtered] = extract_value_from("result_count/info/filtered", r).to_i rep.result_count[:log][:total] = extract_value_from("result_count/log/full", r).to_i rep.result_count[:log][:filtered] = extract_value_from("result_count/log/filtered", r).to_i rep.result_count[:medium][:total] = extract_value_from("result_count/warning/full", r).to_i rep.result_count[:medium][:filtered] = extract_value_from("result_count/warning/filtered", r).to_i r.xpath("./results/result").each { |result| rep.results << VasResult.parse_result_node(result) } ret << rep } [:sort] = :started_at unless [:sort] [:sort_order] = :descending unless [:sort_order] unless [:id] if [:sort] == :started_at if [:sort_order] == :ascending ret.sort! { |a,b| a.started_at <=> b.started_at } else ret.sort! { |a,b| b.started_at <=> a.started_at } end elsif [:sort] == :task_name if [:sort_order] == :ascending ret.sort! { |a,b| a.task_name <=> b.task_name } else ret.sort! { |a,b| b.task_name <=> a.task_name } end end end ret end |
Instance Method Details
#empty? ⇒ Boolean
140 141 142 |
# File 'lib/openvas-cli/vas_report.rb', line 140 def empty? !(@result_count && @result_count[:total] > 0) end |
#result_count ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/openvas-cli/vas_report.rb', line 127 def result_count unless @result_count @result_count = {:total => 0, :filtered => 0, :debug => {:total => 0, :filtered => 0}, :log => {:total => 0, :filtered => 0}, :low => {:total => 0, :filtered => 0}, :medium => {:total => 0, :filtered => 0}, :high => {:total => 0, :filtered => 0} } end @result_count end |
#results ⇒ Object
123 124 125 |
# File 'lib/openvas-cli/vas_report.rb', line 123 def results @results ||= [] end |
#task ⇒ Object
119 120 121 |
# File 'lib/openvas-cli/vas_report.rb', line 119 def task @task ||= VasTask.get_by_id(@task_id) end |
#to_xml ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/openvas-cli/vas_report.rb', line 109 def to_xml req = Nokogiri::XML::Builder.new { |xml| xml.get_reports(:report_id => @id) } report = VasReport.connection.send_receive(req.doc) report.at_xpath('/get_reports_response/report').to_xml end |