Class: Nexpose::DiscoveryConnection
- Includes:
- XMLUtils
- Defined in:
- lib/nexpose/discovery.rb
Direct Known Subclasses
MobileDiscoveryConnection, MobileOffice365DiscoveryConnection, MobilePowershellDiscoveryConnection
Defined Under Namespace
Modules: CollectionMethod, EventSource, Protocol, Type Classes: Criteria, Criterion
Instance Attribute Summary collapse
-
#address ⇒ Object
The IP address or fully qualified domain name of the server.
-
#collection_method ⇒ Object
The collection method (e.g. for DHCP discovery connections).
-
#engine_id ⇒ Object
The engine ID to use for this connection.
-
#event_source ⇒ Object
The event source (e.g. for DHCP discovery connections).
-
#exchange_hostname ⇒ Object
The hostname of the exchange server to connect for exchange powershell connections.
-
#exchange_password ⇒ Object
The exchange password to connect for exchange powershell connections.
-
#exchange_username ⇒ Object
The exchange username to connect for exchange powershell connections.
-
#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 connecting 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
- #==(other) ⇒ Object
- #as_xml ⇒ Object
-
#connect(nsc) ⇒ Object
Initiates a connection to a target used for dynamic discovery of assets.
-
#create(nsc) ⇒ Object
Save this discovery connection on a given Nexpose console.
-
#delete(nsc) ⇒ Object
Delete this connection from the console.
-
#discover(nsc, criteria = nil) ⇒ Array[DiscoveredAsset]
Perform dynamic discover of assets against this connection.
- #eql?(other) ⇒ Boolean
-
#initialize(name = nil, address = nil, user = nil, password = nil) ⇒ DiscoveryConnection
constructor
Create a new discovery connection.
-
#save(nsc) ⇒ Object
Save this discovery connection to a Nexpose console.
- #to_h ⇒ Object
- #to_json ⇒ Object
- #to_xml ⇒ Object
-
#update(nsc) ⇒ Boolean
Update this (existing) discovery connection on a given Nexpose console.
Methods included from XMLUtils
#make_xml, #parse_xml, success?
Methods inherited from APIObject
Constructor Details
#initialize(name = nil, address = nil, user = nil, password = nil) ⇒ DiscoveryConnection
Create a new discovery connection.
102 103 104 105 106 107 108 109 110 111 |
# 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 |
Instance Attribute Details
#address ⇒ Object
The IP address or fully qualified domain name of the server.
69 70 71 |
# File 'lib/nexpose/discovery.rb', line 69 def address @address end |
#collection_method ⇒ Object
The collection method (e.g. for DHCP discovery connections)
87 88 89 |
# File 'lib/nexpose/discovery.rb', line 87 def collection_method @collection_method end |
#engine_id ⇒ Object
The engine ID to use for this connection.
71 72 73 |
# File 'lib/nexpose/discovery.rb', line 71 def engine_id @engine_id end |
#event_source ⇒ Object
The event source (e.g. for DHCP discovery connections)
89 90 91 |
# File 'lib/nexpose/discovery.rb', line 89 def event_source @event_source end |
#exchange_hostname ⇒ Object
The hostname of the exchange server to connect for exchange powershell connections
81 82 83 |
# File 'lib/nexpose/discovery.rb', line 81 def exchange_hostname @exchange_hostname end |
#exchange_password ⇒ Object
The exchange password to connect for exchange powershell connections
85 86 87 |
# File 'lib/nexpose/discovery.rb', line 85 def exchange_password @exchange_password end |
#exchange_username ⇒ Object
The exchange username to connect for exchange powershell connections
83 84 85 |
# File 'lib/nexpose/discovery.rb', line 83 def exchange_username @exchange_username end |
#id ⇒ Object
A unique identifier for this connection.
63 64 65 |
# File 'lib/nexpose/discovery.rb', line 63 def id @id end |
#name ⇒ Object
A unique name for this connection.
65 66 67 |
# File 'lib/nexpose/discovery.rb', line 65 def name @name end |
#password ⇒ Object
The password to use when connecting with the defined user.
75 76 77 |
# File 'lib/nexpose/discovery.rb', line 75 def password @password end |
#port ⇒ Object
The port used for connecting to the server. A valid port from 1 to 65535.
79 80 81 |
# File 'lib/nexpose/discovery.rb', line 79 def port @port end |
#protocol ⇒ Object
The protocol used for connecting to the server. One of DiscoveryConnection::Protocol
77 78 79 |
# File 'lib/nexpose/discovery.rb', line 77 def protocol @protocol end |
#status ⇒ Object
Whether or not the connection is active. Discovery is only possible when the connection is active.
92 93 94 |
# File 'lib/nexpose/discovery.rb', line 92 def status @status end |
#type ⇒ Object
Type of discovery connection
67 68 69 |
# File 'lib/nexpose/discovery.rb', line 67 def type @type end |
#user ⇒ Object
A user name that can be used to log into the server.
73 74 75 |
# File 'lib/nexpose/discovery.rb', line 73 def user @user end |
Class Method Details
.parse(xml) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
233 234 235 |
# File 'lib/nexpose/discovery.rb', line 233 def ==(other) eql?(other) end |
#as_xml ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# 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) ⇒ Object
Initiates a connection to a target used for dynamic discovery of assets. As long as a connection is active, dynamic discovery is continuous.
171 172 173 174 175 |
# 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) ⇒ Object
Save this discovery connection on a given Nexpose console.
117 118 119 120 121 122 123 124 125 126 |
# 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) ⇒ Object
Delete this connection from the console.
181 182 183 |
# File 'lib/nexpose/discovery.rb', line 181 def delete(nsc) nsc.delete_discovery_connection(@id) end |
#discover(nsc, criteria = nil) ⇒ Array[DiscoveredAsset]
Perform dynamic discover of assets against this connection.
157 158 159 160 161 162 163 164 |
# 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) ⇒ Boolean
237 238 239 240 |
# 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) ⇒ Object
Save this discovery connection to a Nexpose console.
145 146 147 148 |
# File 'lib/nexpose/discovery.rb', line 145 def save(nsc) @id == -1 ? create(nsc) : update(nsc) @id end |
#to_h ⇒ Object
224 225 226 227 228 229 230 231 |
# 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 ⇒ Object
220 221 222 |
# File 'lib/nexpose/discovery.rb', line 220 def to_json JSON.generate(to_h) end |
#to_xml ⇒ Object
204 205 206 |
# File 'lib/nexpose/discovery.rb', line 204 def to_xml as_xml.to_s end |
#update(nsc) ⇒ Boolean
Update this (existing) discovery connection on a given Nexpose console.
133 134 135 136 137 138 139 |
# 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 |