Class: OpenvasCli::VasResult
- Defined in:
- lib/openvas-cli/vas_result.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#host ⇒ Object
Returns the value of attribute host.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#overrides ⇒ Object
Returns the value of attribute overrides.
-
#port ⇒ Object
Returns the value of attribute port.
-
#result_id ⇒ Object
Returns the value of attribute result_id.
-
#rule_id ⇒ Object
Returns the value of attribute rule_id.
-
#subnet ⇒ Object
Returns the value of attribute subnet.
-
#task_id ⇒ Object
Returns the value of attribute task_id.
-
#threat ⇒ Object
Returns the value of attribute threat.
Attributes inherited from VasBase
Class Method Summary collapse
- .get_all(options = {}) ⇒ Object
- .get_by_id(id) ⇒ Object
- .parse_result_node(node, task_id = nil) ⇒ Object
Instance Method Summary collapse
Methods inherited from VasBase
#create_or_update, #delete_record, #destroy, #destroy!, #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
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def description @description end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def host @host end |
#notes ⇒ Object
Returns the value of attribute notes.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def notes @notes end |
#overrides ⇒ Object
Returns the value of attribute overrides.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def overrides @overrides end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def port @port end |
#result_id ⇒ Object
Returns the value of attribute result_id.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def result_id @result_id end |
#rule_id ⇒ Object
Returns the value of attribute rule_id.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def rule_id @rule_id end |
#subnet ⇒ Object
Returns the value of attribute subnet.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def subnet @subnet end |
#task_id ⇒ Object
Returns the value of attribute task_id.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def task_id @task_id end |
#threat ⇒ Object
Returns the value of attribute threat.
6 7 8 |
# File 'lib/openvas-cli/vas_result.rb', line 6 def threat @threat end |
Class Method Details
.get_all(options = {}) ⇒ Object
15 16 17 18 19 20 21 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 |
# File 'lib/openvas-cli/vas_result.rb', line 15 def self.get_all( = {}) [:sort_by] ||= :threat params = {:overrides => 0, :notes => 0} params[:result_id] = [:id] if [:id] if [:task_id] params[:task_id] = [:task_id] params[:apply_overrides] = 1 if [:apply_overrides] end levels = [] if [:filter] [:filter].each { |ft| case ft when :high levels << "High" when :medium levels << "Medium" when :low levels << "Low" when :log levels << "Log" when :debug levels << "Debug" end } end req = Nokogiri::XML::Builder.new { |xml| xml.get_results(params) } results = {} begin xml = connection.send_receive(req.doc) xml.xpath("//result").each { |xr| id = extract_value_from("@id", xr) threat = extract_value_from("threat", xr) if (levels.empty? || levels.include?(threat)) && results.has_key?(id) == false res = parse_result_node(xr, [:task_id]) results[res.result_id] = res end } rescue VasExceptions::CommandException => e end ret = results.values #Sort Results ret.sort!{ |a,b| a.result_id <=> b.result_id } if [:sort_by] == :result_id ret.sort!{ |a,b| a.host <=> b.host } if [:sort_by] == :host ret.sort!{ |a,b| a.rule_id <=> b.rule_id } if [:sort_by] == :rule_id ret.sort!{ |a,b| a.subnet <=> b.subnet } if [:sort_by] == :subnet ret.sort!{ |a,b| b.threat_level <=> a.threat_level } if [:sort_by] == :threat #Fake Pagination if [:start] if [:count] ret = ret[[:start], [:count]] else ret = ret[[:start], ret.length - [:start]] end end ret end |
.get_by_id(id) ⇒ Object
11 12 13 |
# File 'lib/openvas-cli/vas_result.rb', line 11 def self.get_by_id(id) get_all(:id => id)[0] end |
.parse_result_node(node, task_id = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/openvas-cli/vas_result.rb', line 83 def self.parse_result_node(node, task_id = nil) res = VasResult.new res.id = extract_value_from("@id", node) res.threat = extract_value_from("threat", node) res.subnet = extract_value_from("subnet", node) res.host = extract_value_from("host", node) res.rule_id = extract_value_from("nvt/@oid", node) res.description = extract_value_from("description", node) res.task_id = task_id if task_id res end |
Instance Method Details
#threat_level ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/openvas-cli/vas_result.rb', line 96 def threat_level case @threat when "High" 5 when "Medium" 4 when "Low" 3 when "Log" 2 when "Debug" 1 else 0 end end |