Class: Nexpose::SiteListing

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose/site.rb

Overview

Description

Object that represents a listing of all of the sites available on an NSC.

Example

# Create a new Nexpose Connection on the default port and Login
nsc = Connection.new("10.1.40.10","nxadmin","password")
nsc->login;

# Get Site Listing
sitelisting = SiteListing.new(nsc)

# Enumerate through all of the SiteSummaries
sitelisting.sites.each do |sitesummary|
    # Do some operation on each site
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ SiteListing

Constructor SiteListing (connection)



486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/nexpose/site.rb', line 486

def initialize(connection)
  @sites = []

  @connection = connection

  r = @connection.execute('<SiteListingRequest session-id="' + @connection.session_id.to_s + '"/>')

  if r.success
    parse(r.res)
  else
    raise APIError.new(r, 'Failed to get site listing.')
  end
end

Instance Attribute Details

#connectionObject (readonly)

The NSC Connection associated with this object



478
479
480
# File 'lib/nexpose/site.rb', line 478

def connection
  @connection
end

#site_countObject (readonly)

The number of sites



482
483
484
# File 'lib/nexpose/site.rb', line 482

def site_count
  @site_count
end

#sitesObject (readonly)

Array containing SiteSummary objects for each site in the connection



480
481
482
# File 'lib/nexpose/site.rb', line 480

def sites
  @sites
end

Instance Method Details

#parse(r) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/nexpose/site.rb', line 500

def parse(r)
  r.elements.each('SiteListingResponse/SiteSummary') do |s|
    site_summary = SiteSummary.new(
      s.attributes['id'].to_s,
      s.attributes['name'],
      s.attributes['description'],
      s.attributes['riskfactor'].to_s
    )
    @sites.push(site_summary)
  end
  @site_count = @sites.length
end