Class: Nexpose::ScanSummary

Inherits:
ScanData show all
Defined in:
lib/nexpose/scan.rb

Overview

Object that represents a summary of a scan.

Defined Under Namespace

Classes: Nodes, Tasks, Vulnerabilities

Instance Attribute Summary collapse

Attributes inherited from ScanData

#end_time, #engine_id, #scan_id, #site_id, #start_time, #status

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scan_id, site_id, engine_id, status, start_time, end_time, message, tasks, nodes, vulnerabilities) ⇒ ScanSummary

Constructor



554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/nexpose/scan.rb', line 554

def initialize(scan_id, site_id, engine_id, status, start_time, end_time, message, tasks, nodes, vulnerabilities)
  @scan_id         = scan_id
  @site_id         = site_id
  @engine_id       = engine_id
  @status          = status
  @start_time      = start_time
  @end_time        = end_time
  @message         = message
  @tasks           = tasks
  @nodes           = nodes
  @vulnerabilities = vulnerabilities
end

Instance Attribute Details

#messageObject (readonly)

The reason the scan was stopped or failed, if applicable.



544
545
546
# File 'lib/nexpose/scan.rb', line 544

def message
  @message
end

#nodesObject (readonly)

Node statistics, including live, dead, filtered, and unresolved.



549
550
551
# File 'lib/nexpose/scan.rb', line 549

def nodes
  @nodes
end

#tasksObject (readonly)

Task statistics, including pending, active, and completed tasks.



547
548
549
# File 'lib/nexpose/scan.rb', line 547

def tasks
  @tasks
end

#vulnerabilitiesObject (readonly)

Vulnerability statistics, including statuses, severities, and counts.



551
552
553
# File 'lib/nexpose/scan.rb', line 551

def vulnerabilities
  @vulnerabilities
end

Class Method Details

.parse(xml) ⇒ ScanSummary

Parse a response from a Nexpose console into a valid ScanSummary object.

Parameters:

  • xml (REXML::Document)

    XML document to parse.

Returns:

  • (ScanSummary)

    Scan summary represented by the XML.



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'lib/nexpose/scan.rb', line 572

def self.parse(xml)
  tasks = Tasks.parse(xml.elements['tasks'])
  nodes = Nodes.parse(xml.elements['nodes'])
  vulns = Vulnerabilities.parse(xml.attributes['scan-id'], xml)
  msg = xml.elements['message'] ? xml.elements['message'].text : nil

  # Start time can be empty in some error conditions.
  start_time = nil
  unless xml.attributes['startTime'] == ''
    start_time = DateTime.parse(xml.attributes['startTime'].to_s).to_time
    # Timestamp is UTC, but parsed as local time.
    start_time -= start_time.gmt_offset
  end

  # End time is often not present, since reporting on running scans.
  end_time = nil
  if xml.attributes['endTime']
    end_time = DateTime.parse(xml.attributes['endTime'].to_s).to_time
    # Timestamp is UTC, but parsed as local time.
    end_time -= end_time.gmt_offset
  end
  ScanSummary.new(xml.attributes['scan-id'].to_i,
                  xml.attributes['site-id'].to_i,
                  xml.attributes['engine-id'].to_i,
                  xml.attributes['status'],
                  start_time,
                  end_time,
                  msg,
                  tasks,
                  nodes,
                  vulns)
end