Add Computers

You can use the API to add computers to Deep Security Manager as part of the process of protecting new assets.

Before using the API, consider using the following types of scheduled tasks to automatically discover and add computers:

  • Discover Computers
  • Synchronize Cloud Account
  • Synchronize Directory
  • Synchronize VMware vCenter

For more information, see Maintain Protection Using Scheduled Tasks or Schedule Deep Security to perform tasks in the Help Center.

Use the following general procedure to add a computer:

  1. Create a Computer object and set the hostname. The hostname is the only required property. The value must be the hostname or IP address that resolves to the computer.
  2. Configure any other properties as required.
  3. Create a ComputersApi object and use it to create the computer on Deep Security Manager.

To see the properties that you can configure, see the Create a Computer operation in the API Reference.

You can also use the Deep Security Manager console to create a task that automatically configures computers when they are added. See Automatically perform tasks when a computer is added or changed in the Help Center.

You can use the legacy REST API to enable the relay on a computer that is running an activated agent. The Deep Security Git repository contains scripts that accomplish this task:

For background information, see Distribute security and software updates with relays on the Help Center.

Example: Add a computer to Deep Security Manager

Python
def add_computer (api, configuration, api_version, api_exception, hostname):
    """ Adds a computer to Deep Security Manager.

    :param api: The Deep Security API modules.
    :param configuration: Configuration object to pass to the api client.
    :param api_version: The version of the API to use.
    :param api_exception: The Deep Security API exception module.
    :param hostname: The hostname or IP address that resolves to the computer.
    :return: An Integer that contains the ID of the computer.
    """

    # Create the computer object
    computer = api.Computer()
    computer.host_name = hostname

    try:
        # Add the computer to Deep Security Manager
        computers_api = api.ComputersApi(api.ApiClient(configuration))
        new_computer = computers_api.create_computer(computer, api_version)
        return new_computer.id

    except api_exception as e:
        return "Exception: " + str(e)
JavaScript
/*
 * Creates a computer on Deep Security Manager.
 * @param {String} hostname The hostname or IP address that resolves to the computer.
 * @param {object} api The api module.
 * @param {String} apiVersion The api version to use.
 * @returs {Promise} A promise that contains the ID of the computer.
 */
exports.addComputer = function(hostname, api, apiVersion) {
  return new Promise((resolve, reject) => {= new api.Computer();
    computer.hostName = hostname;= new api.ComputersApi();
    computersApi
      .createComputer(computer, apiVersion, { overrides: false })
      .then(returnedComputer => {
        resolve(returnedComputer.ID);
      })
      .catch(error => {
        reject(error);
      });
  });
};
Java
/*
 * Adds a computer to Deep Security Manager.
 * @param hostname The hostname or IP address that resolves to the computer.
 * @return The ID of the computer.
 */	
public static Integer addComputer(String hostname) {= new Computer();
	computer.setHostName(hostname);= new ComputersApi();
	try {
	computer = computersApi.createComputer(computer, false, "v1");
	} catch (ApiException e) {
		e.printStackTrace();
	}
	return computer.getID();
}