class Nexpose::DiscoveryConnection

Attributes

address[RW]

The IP address or fully qualified domain name of the server.

collection_method[RW]

The collection method (e.g. for DHCP discovery connections)

engine_id[RW]

The engine ID to use for this connection.

event_source[RW]

The event source (e.g. for DHCP discovery connections)

exchange_hostname[RW]

The hostname of the exchange server to connect for exchange powershell connections

exchange_password[RW]

The exchange password to connect for exchange powershell connections

exchange_username[RW]

The exchange username to connect for exchange powershell connections

id[RW]

A unique identifier for this connection.

name[RW]

A unique name for this connection.

password[RW]

The password to use when connecting with the defined user.

port[RW]

The port used for connecting to the server. A valid port from 1 to 65535.

protocol[RW]

The protocol used for connecting to the server. One of DiscoveryConnection::Protocol

status[RW]

Whether or not the connection is active. Discovery is only possible when the connection is active.

type[RW]

Type of discovery connection

user[RW]

A user name that can be used to log into the server.

Public Class Methods

new(name = nil, address = nil, user = nil, password = nil) click to toggle source

Create a new discovery connection.

@param [String] name Name to assign to this connection. @param [String] address IP or fully qualified domain name of the

connection server.

@param [String] user User name for credentials on this connection. @param [String] password Password for credentials on this connection.

# File lib/nexpose/discovery.rb, line 102
def initialize(name = nil, address = nil, user = nil, password = nil)
  @name     = name
  @address  = address
  @user     = user
  @password = password
  @type     = nil # For backwards compatibilitly, at some point should set this to Type::VSPHERE
  @id       = -1
  @port     = 443
  @protocol = Protocol::HTTPS
end
parse(xml) click to toggle source
# File lib/nexpose/discovery.rb, line 208
def self.parse(xml)
  conn = new(xml.attributes['name'],
             xml.attributes['address'],
             xml.attributes['user-name'])
  conn.id        = xml.attributes['id'].to_i
  conn.protocol  = xml.attributes['protocol']
  conn.port      = xml.attributes['port'].to_i
  conn.status    = xml.attributes['connection-status']
  conn.engine_id = xml.attributes['engine-id'].to_i
  conn
end

Public Instance Methods

==(other) click to toggle source
# File lib/nexpose/discovery.rb, line 233
def ==(other)
  eql?(other)
end
as_xml() click to toggle source
# File lib/nexpose/discovery.rb, line 185
def as_xml
  xml = REXML::Element.new('DiscoveryConnection')
  xml.attributes['name']              = @name
  xml.attributes['address']           = @address
  xml.attributes['port']              = @port
  xml.attributes['protocol']          = @protocol
  xml.attributes['user-name']         = @user
  xml.attributes['password']          = @password
  xml.attributes['exchange-hostname'] = @exchange_hostname if @exchange_hostname
  xml.attributes['exchange-username'] = @exchange_username if @exchange_username
  xml.attributes['exchange-password'] = @exchange_password if @exchange_password
  xml.attributes['type']              = @type if @type
  xml.attributes['collectionmethod']  = @collection_method if @collection_method
  xml.attributes['eventsource']       = @event_source if @event_source
  xml.attributes['engine-id'] = @engine_id if @engine_id && @engine_id != -1
  xml.attributes['id'] = @id if @id && @id != -1
  xml
end
connect(nsc) click to toggle source

Initiates a connection to a target used for dynamic discovery of assets. As long as a connection is active, dynamic discovery is continuous.

@param [Connection] nsc Connection to a console.

# File lib/nexpose/discovery.rb, line 171
def connect(nsc)
  xml      = nsc.make_xml('DiscoveryConnectionConnectRequest', { 'id' => id })
  response = nsc.execute(xml, '1.2')
  response.success
end
create(nsc) click to toggle source

Save this discovery connection on a given Nexpose console.

@param [Connection] nsc Connection to a console.

# File lib/nexpose/discovery.rb, line 117
def create(nsc)
  xml = nsc.make_xml('DiscoveryConnectionCreateRequest')
  xml.add_element(as_xml)

  response = nsc.execute(xml, '1.2')
  if response.success
    ret = REXML::XPath.first(response.res, 'DiscoveryConnectionCreateResponse')
    @id = ret.attributes['id'].to_i unless ret.nil?
  end
end
delete(nsc) click to toggle source

Delete this connection from the console.

@param [Connection] nsc Connection to a console.

# File lib/nexpose/discovery.rb, line 181
def delete(nsc)
  nsc.delete_discovery_connection(@id)
end
discover(nsc, criteria = nil) click to toggle source

Perform dynamic discover of assets against this connection.

@param [Connection] nsc Connection to a console. @param [Criteria] criteria Criteria search object narrowing which assets

to filter.

@return [Array] All discovered assets matching the criteria.

# File lib/nexpose/discovery.rb, line 157
def discover(nsc, criteria = nil)
  parameters = { 'table-id' => 'assetdiscovery',
                 'sort' => 'assetDiscoveryName',
                 'searchCriteria' => criteria.nil? ? 'null' : criteria.to_json,
                 'configID' => @id }
  data = DataTable._get_json_table(nsc, '/data/discoveryAsset/discoverAssets', parameters)
  data.map { |a| DiscoveredAsset.parse(a) }
end
eql?(other) click to toggle source
# File lib/nexpose/discovery.rb, line 237
def eql?(other)
  id.eql?(other.id) && name.eql?(other.name) && type.eql?(other.type)
  # TODO: Add remaining instance fields, once it is introduced in resource object
end
save(nsc) click to toggle source

Save this discovery connection to a Nexpose console.

@param [Connection] nsc Connection to a console.

# File lib/nexpose/discovery.rb, line 145
def save(nsc)
  @id == -1 ? create(nsc) : update(nsc)
  @id
end
to_h() click to toggle source
# File lib/nexpose/discovery.rb, line 224
def to_h
  {
    id: id,
    name: name,
    type: type
    # TODO: Add remaining instance fields, once it is introduced in resource object
  }
end
to_json() click to toggle source
# File lib/nexpose/discovery.rb, line 220
def to_json
  JSON.generate(to_h)
end
to_xml() click to toggle source
# File lib/nexpose/discovery.rb, line 204
def to_xml
  as_xml.to_s
end
update(nsc) click to toggle source

Update this (existing) discovery connection on a given Nexpose console.

@param [Connection] nsc Connection to a console. @return [Boolean] whether the update request was successful

# File lib/nexpose/discovery.rb, line 133
def update(nsc)
  xml = nsc.make_xml('DiscoveryConnectionUpdateRequest')
  xml.add_element(as_xml)

  response = nsc.execute(xml, '1.2')
  response.success
end