lib/ruby-nessus/host.rb in ruby-nessus-0.1.2 vs lib/ruby-nessus/host.rb in ruby-nessus-0.1.3

- old
+ new

@@ -24,32 +24,32 @@ # @return [DateTime] # The Host Scan Start Time # @example # scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985' def scan_start_time - @host_scan_time = @host.at('startTime').inner_text + @host_scan_time = DateTime.strptime(@host.at('startTime').inner_text, fmt='%a %b %d %H:%M:%S %Y') end # Return the host scan stop time. # @return [DateTime] # The Host Scan Stop Time # @example # scan.scan_start_time #=> 'Fri Nov 11 23:36:54 1985' def scan_stop_time - @host_scan_time = @host.at('stopTime').inner_text + @host_scan_time = DateTime.strptime(@host.at('stopTime').inner_text, fmt='%a %b %d %H:%M:%S %Y') end # Return the host run time. # @return [String] # The Host Scan Run Time # @example # scan.scan_run_time #=> '2 hours 5 minutes and 16 seconds' def scan_runtime - if scan_start_time.empty? | scan_stop_time.empty?; return "N/A"; end - h = ("#{Time.parse(scan_stop_time).strftime('%H').to_i - Time.parse(scan_start_time).strftime('%H').to_i}").gsub('-', '') - m = ("#{Time.parse(scan_stop_time).strftime('%M').to_i - Time.parse(scan_start_time).strftime('%M').to_i}").gsub('-', '') - s = ("#{Time.parse(scan_stop_time).strftime('%S').to_i - Time.parse(scan_start_time).strftime('%S').to_i}").gsub('-', '') + if scan_start_time.to_s.empty? | scan_stop_time.to_s.empty?; return "N/A"; end + h = ("#{Time.parse(scan_stop_time.to_s).strftime('%H').to_i - Time.parse(scan_start_time.to_s).strftime('%H').to_i}").gsub('-', '') + m = ("#{Time.parse(scan_stop_time.to_s).strftime('%M').to_i - Time.parse(scan_start_time.to_s).strftime('%M').to_i}").gsub('-', '') + s = ("#{Time.parse(scan_stop_time.to_s).strftime('%S').to_i - Time.parse(scan_start_time.to_s).strftime('%S').to_i}").gsub('-', '') return "#{h} hours #{m} minutes and #{s} seconds" end # Return the Host Netbios Name. # @return [String] @@ -112,11 +112,11 @@ def informational_events(&block) unless @informational_events @informational_events = [] @informational_event_count = 0 - @host.xpath("//ReportItem").each do |event| + @host.xpath("ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 0 @informational_events << Event.new(event) @informational_event_count += 1 end @@ -141,11 +141,11 @@ @low_severity_count = @host.at('num_lo').inner_text.to_i unless @low_severity_events @low_severity_events = [] - @host.xpath("//ReportItem").each do |event| + @host.xpath("ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 1 @low_severity_events << Event.new(event) end end @@ -169,11 +169,11 @@ @high_severity_count = @host.at('num_med').inner_text.to_i unless @medium_severity_events @medium_severity_events = [] - @host.xpath("//ReportItem").each do |event| + @host.xpath("ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 2 @medium_severity_events << Event.new(event) end end @@ -197,11 +197,11 @@ @high_severity_count = @host.at('num_hi').inner_text.to_i unless @high_severity_events @high_severity_events = [] - @host.xpath("//ReportItem").each do |event| + @host.xpath("ReportItem").each do |event| next if event.at('severity').inner_text.to_i != 3 @high_severity_events << Event.new(event) end end @@ -227,10 +227,10 @@ # host.events do |event| # puts event.name if event.name # puts event.port # end def events(&block) - @host.xpath("//ReportItem").each do |event| + @host.xpath("ReportItem").each do |event| block.call(Event.new(event)) if block end end end