Last updated at Tue, 25 Apr 2023 23:23:40 GMT

Nexpose has long offered APIs allowing for automated workflow operations. The following examples are intended to help Nexpose users automate the discovery mechanisms feature through the API. The following code shows how to leverage the Java API client to create, list, update and delete discovery mechanisms in Nexpose.

Nexpose supports Discovery connection API starting on version 5.2.  The supported operations on the API with regards to discovery are:

DiscoveryConnectionCreateRequest To create a discovery connection. This automatically establishes the connection between Nexpose and the discovery mechanism, for instance, you would use this to create a connection to a VMware deployment managed by a vCenter server instance.

  • DiscoveryConnectionConnectRequest To re-establish a lost connection.
  • DiscoveryConnectionUpdateRequest To update the settings of an existing discovery connection. You would use this if you change the password of the user used in Nexpose to connect to a discovery connection. For instance if you change the password of your Nexpose user in VMware, you would need to update the connection to reflect this change.
  • DiscoveryConnectionListingRequest To list the discovery connections that exist in Nexpose.
  • DiscoveryConnectionDeleteRequest To delete a discovery connection.

I have enhanced the Java API client to support the previous operation and the latest code can be checked out from clee-r7/nexpose_java_api · GitHub

The following are the examples of using the operations in java code.

1) Create operation

DiscoveryConnectionCreateRequest createConnectionRequest = new DiscoveryConnectionCreateRequest
(sessionID, // the session ID
"sync", // the sync id
"username", // the user name to connect the server.
"HTTPS", // the protocol to connect the server
"port number", //the port  to connect the server
"vcenter ", // the name of the server
"con1", // The name of the connection
"password"); // password to connect the server
APIResponse createConnectionResponse = session.executeAPIRequest(createConnectionRequest);
// Get the connection id from the response.
String connectionID = createConnectionResponse.grab("/DiscoveryConnectionCreateResponse/@id");

2) Update Operation

DiscoveryConnectionUpdateRequest updateConnectionRequest = new DiscoveryConnectionUpdateRequest
(sessionID, // the session ID
"sync", // the sync id
"username", // the user name to connect the server.
"HTTPS", // the protocol to connect the server
"port number",              //the port  to connect the server
"vcenter ", // the name of the server
"con1", // The name of the connection
"password" // password to connect the server
“connectionID”); // the id of the connection
APIResponse updateConnectionResponse = session.executeAPIRequest(updateConnectionRequest);
// get the sync id from the response.
String syncID = updateConnectionResponse.grab("/DiscoveryConnectionUpdateResponse/@sync-id");

3) Delete Operation

DiscoveryConnectionDeleteRequest deleteConnectionRequest = new DiscoveryConnectionDeleteRequest
(sessionID, // the session ID
"sync", // the sync id
“connectionID”); // the id of the connection
APIResponse deleteConnectionResponse = session.executeAPIRequest(deleteConnectionRequest);
// get the sync id from response
String syncID = deleteConnectionResponse.grab("/DiscoveryConnectionDeleteResponse/@sync-id");

4) List Operation

DiscoveryConnectionListingRequest connectionListingRequest = new DiscoveryConnectionListingRequest
(sessionID, // the session ID
"sync"); // the sync id
APIResponse connectionListingResponse = session.executeAPIRequest(connectionListingRequest);
// get the sync id from response
String syncID = connectionListingResponse.grab("/DiscoveryConnectionListingResponse/@sync-id");

So you can easily manage your virtual connections. Let the automation begin!