Class: Nexpose::SiteListing

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose.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)



577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/nexpose.rb', line 577

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



569
570
571
# File 'lib/nexpose.rb', line 569

def connection
  @connection
end

#errorObject (readonly)

true if an error condition exists; false otherwise



561
562
563
# File 'lib/nexpose.rb', line 561

def error
  @error
end

#error_msgObject (readonly)

Error message string



563
564
565
# File 'lib/nexpose.rb', line 563

def error_msg
  @error_msg
end

#request_xmlObject (readonly)

The last XML request sent by this object



565
566
567
# File 'lib/nexpose.rb', line 565

def request_xml
  @request_xml
end

#response_xmlObject (readonly)

The last XML response received by this object



567
568
569
# File 'lib/nexpose.rb', line 567

def response_xml
  @response_xml
end

#site_countObject (readonly)

The number of sites



573
574
575
# File 'lib/nexpose.rb', line 573

def site_count
  @site_count
end

#sitesObject (readonly)

Array containing SiteSummary objects for each site in the connection



571
572
573
# File 'lib/nexpose.rb', line 571

def sites
  @sites
end

Instance Method Details

#parse(r) ⇒ Object



591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/nexpose.rb', line 591

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