class OpenvasCli::VasReport
Contains the details of a single OpenVAS report.
Attributes
started_at[RW]
status[RW]
Overall Status Only
task_id[RW]
task_name[RW]
Public Class Methods
get_all(options={})
click to toggle source
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.
# File lib/openvas-cli/vas_report.rb, line 22 def self.get_all(options={}) params = {} params[:report_id] = options[:id] if options[:id] if options[:levels] params[:levels] = "" options[: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.message =~ /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 } options[:sort] = :started_at unless options[:sort] options[:sort_order] = :descending unless options[:sort_order] unless options[:id] if options[:sort] == :started_at if options[: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 options[:sort] == :task_name if options[: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
Public Instance Methods
empty?()
click to toggle source
# File lib/openvas-cli/vas_report.rb, line 140 def empty? !(@result_count && @result_count[:total] > 0) end
result_count()
click to toggle source
# 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()
click to toggle source
# File lib/openvas-cli/vas_report.rb, line 123 def results @results ||= [] end
task()
click to toggle source
# File lib/openvas-cli/vas_report.rb, line 119 def task @task ||= VasTask.get_by_id(@task_id) end
to_xml()
click to toggle source
# 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