Class: OpenvasCli::VasReport

Inherits:
VasBase
  • Object
show all
Defined in:
lib/openvas-cli/vas_report.rb

Overview

Contains the details of a single OpenVAS report.

Instance Attribute Summary collapse

Attributes inherited from VasBase

#id

Class Method Summary collapse

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

included

Methods included from XmlAddin

included

Constructor Details

This class inherits a constructor from OpenvasCli::VasBase

Instance Attribute Details

#started_atObject

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

#statusObject

Overall Status Only



10
11
12
# File 'lib/openvas-cli/vas_report.rb', line 10

def status
  @status
end

#task_idObject

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_nameObject

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(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

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/openvas-cli/vas_report.rb', line 140

def empty?
  !(@result_count && @result_count[:total] > 0)
end

#result_countObject



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

#resultsObject



123
124
125
# File 'lib/openvas-cli/vas_report.rb', line 123

def results
  @results ||= []
end

#taskObject



119
120
121
# File 'lib/openvas-cli/vas_report.rb', line 119

def task
  @task ||= VasTask.get_by_id(@task_id)
end

#to_xmlObject



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