Class: Nexpose::DiscoveryConnection
- Inherits:
-
Object
- Object
- Nexpose::DiscoveryConnection
- Includes:
- XMLUtils
- Defined in:
- lib/nexpose/discovery.rb
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#address ⇒ Object
The IP address or fully qualified domain name of the server.
-
#id ⇒ Object
A unique identifier for this connection.
-
#name ⇒ Object
A unique name for this connection.
-
#password ⇒ Object
The password to use when connecting with the defined user.
-
#port ⇒ Object
The port used for connecting to the server.
-
#protocol ⇒ Object
The protocol used for conneting to the server.
-
#status ⇒ Object
Whether or not the connection is active.
-
#type ⇒ Object
Type of discovery connection.
-
#user ⇒ Object
A user name that can be used to log into the server.
Class Method Summary collapse
Instance Method Summary collapse
- #as_xml ⇒ Object
-
#connect(nsc) ⇒ Object
Initiates a connection to a target used for dynamic discovery of assets.
-
#delete(nsc) ⇒ Object
Delete this connection from the console.
-
#discover(nsc, criteria = nil) ⇒ Array[DiscoveredAsset]
Perform dynamic discover of assets against this connection.
-
#initialize(name, address, user, password = nil) ⇒ DiscoveryConnection
constructor
Create a new discovery connection.
-
#save(nsc) ⇒ Object
Save this discovery connection to a Nexpose console.
- #to_xml ⇒ Object
Methods included from XMLUtils
#make_xml, #parse_xml, success?
Constructor Details
#initialize(name, address, user, password = nil) ⇒ DiscoveryConnection
Create a new discovery connection.
82 83 84 85 86 87 88 |
# File 'lib/nexpose/discovery.rb', line 82 def initialize(name, address, user, password = nil) @name, @address, @user, @password = name, address, user, password @type = nil # for backwards compatibilitly, at some point should set this to Type::VSPHERE @id = -1 @port = 443 @protocol = Protocol::HTTPS end |
Instance Attribute Details
#address ⇒ Object
The IP address or fully qualified domain name of the server.
56 57 58 |
# File 'lib/nexpose/discovery.rb', line 56 def address @address end |
#id ⇒ Object
A unique identifier for this connection.
47 48 49 |
# File 'lib/nexpose/discovery.rb', line 47 def id @id end |
#name ⇒ Object
A unique name for this connection.
50 51 52 |
# File 'lib/nexpose/discovery.rb', line 50 def name @name end |
#password ⇒ Object
The password to use when connecting with the defined user.
62 63 64 |
# File 'lib/nexpose/discovery.rb', line 62 def password @password end |
#port ⇒ Object
The port used for connecting to the server. A valid port from 1 to 65535.
68 69 70 |
# File 'lib/nexpose/discovery.rb', line 68 def port @port end |
#protocol ⇒ Object
The protocol used for conneting to the server. One of DiscoveryConnection::Protocol
65 66 67 |
# File 'lib/nexpose/discovery.rb', line 65 def protocol @protocol end |
#status ⇒ Object
Whether or not the connection is active. Discovery is only possible when the connection is active.
72 73 74 |
# File 'lib/nexpose/discovery.rb', line 72 def status @status end |
#type ⇒ Object
Type of discovery connection
53 54 55 |
# File 'lib/nexpose/discovery.rb', line 53 def type @type end |
#user ⇒ Object
A user name that can be used to log into the server.
59 60 61 |
# File 'lib/nexpose/discovery.rb', line 59 def user @user end |
Class Method Details
.parse(xml) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/nexpose/discovery.rb', line 160 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 end |
Instance Method Details
#as_xml ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/nexpose/discovery.rb', line 144 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['type'] = @type if @type xml end |
#connect(nsc) ⇒ Object
Initiates a connection to a target used for dynamic discovery of assets. As long as a connection is active, dynamic discovery is continuous.
130 131 132 133 134 |
# File 'lib/nexpose/discovery.rb', line 130 def connect(nsc) xml = nsc.make_xml('DiscoveryConnectionConnectRequest', { 'id' => id }) response = nsc.execute(xml, '1.2') response.success end |
#delete(nsc) ⇒ Object
Delete this connection from the console.
140 141 142 |
# File 'lib/nexpose/discovery.rb', line 140 def delete(nsc) nsc.delete_discovery_connection(@id) end |
#discover(nsc, criteria = nil) ⇒ Array[DiscoveredAsset]
Perform dynamic discover of assets against this connection.
116 117 118 119 120 121 122 123 |
# File 'lib/nexpose/discovery.rb', line 116 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 |
#save(nsc) ⇒ Object
Save this discovery connection to a Nexpose console.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/nexpose/discovery.rb', line 94 def save(nsc) if @id == -1 xml = nsc.make_xml('DiscoveryConnectionCreateRequest') else xml = nsc.make_xml('DiscoveryConnectionUpdateRequest') end 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 @id end |
#to_xml ⇒ Object
156 157 158 |
# File 'lib/nexpose/discovery.rb', line 156 def to_xml as_xml.to_s end |