Create a Shared Ruleset

Shared rulesets allow you to apply and manage your rules across multiple different computers. Generally, use the following steps to create a shared ruleset:

  1. Create and configure a SoftwareInventory object for the computer you wish to base the ruleset on.
  2. Use aSoftwareInventoryApi object to create the software inventory on Deep Security Manager. Once it's created, an inventory build begins on the specified computer.
  3. Use theSoftwareInventoryApi object to confirm that the inventory build has completed successfully.
  4. Create a Ruleset object.
  5. Use a RulesetApi object to create the Ruleset on Deep Security Manager.
  6. Use a ComputerApi object or a PolicyApi object to assign the shared ruleset to your computer(s).

For more information about shared rulesets, see the Deep Security Help Center.

The following example creates a software inventory and uses that software inventory to create a Shared Ruleset.

Python
source
software_inventory = api.SoftwareInventory()
software_inventory.computer_id = computer_id

# Build software_inventory
software_inventories_api = api.SoftwareInventoriesApi(api.ApiClient(configuration))
new_inventory = software_inventories_api.create_software_inventory(software_inventory, api_version)

while new_inventory.state != "complete":
  # check status every 30 seconds
  time.sleep(30)
  new_inventory = software_inventories_api.describe_software_inventory(new_inventory.id, api_version)

# Create ruleset
ruleset = api.Ruleset()
ruleset.name = ruleset_name
rulesets_api = api.RulesetsApi(api.ApiClient(configuration))
return rulesets_api.create_ruleset(ruleset, new_inventory.id, api_version)
JavaScript
source
// Create a software inventory
const softwareInventory = new api.SoftwareInventory();
softwareInventory.computerID = computerID;

const softwareInventoryApi = new api.SoftwareInventoriesApi();
softwareInventoryApi.createSoftwareInventory(softwareInventory, apiVersion)
  .then(softwareInventory => {
    // Wait until the software inventory is done building
    function waitForInventoryBuild() {
      softwareInventoryApi.describeSoftwareInventory(softwareInventory.ID, apiVersion)
        .then(softwareInventory => {
          if (softwareInventory.state === api.SoftwareInventory.StateEnum.complete) {
            // Create a ruleset
            const ruleset = new api.Ruleset();
            ruleset.name = rulesetName;

            const rulesetApi = new api.RulesetsApi();
            rulesetApi.createRuleset(ruleset, softwareInventory.ID, apiVersion)
              .then(ruleset => {
                return resolve(ruleset);
              })
              .catch(error => {
                return reject(error);
              });
          } else {
            // Check every 30 seconds
            setTimeout(waitForInventoryBuild, 30000);
          }
        })
        .catch(error => {
          return reject(error);
        });
    }
    waitForInventoryBuild();
  })
  .catch(error => {
    reject(error);
  });
Java
source
// Create software inventory
SoftwareInventory softwareInventory = new SoftwareInventory();
softwareInventory.setComputerID(computerId);

SoftwareInventoriesApi softwareInventoriesApi = new SoftwareInventoriesApi();

SoftwareInventory newInventory = softwareInventoriesApi.createSoftwareInventory(softwareInventory, apiVersion);
Long inventoryId = newInventory.getID();

// Wait for software inventory to build
while (!newInventory.getState().equals(StateEnum.COMPLETE)) {

    // Check status every 30 seconds
    try {
        // System.out.println("Waiting 30 seconds...");
        Thread.sleep(30000L);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    newInventory = softwareInventoriesApi.describeSoftwareInventory(inventoryId, apiVersion);
}

// Create shared ruleset
Ruleset ruleset = new Ruleset();
ruleset.setName(rulesetName);

RulesetsApi rulesetApi = new RulesetsApi();
return rulesetApi.createRuleset(ruleset, inventoryId, apiVersion);

Also see the Create a Shared Ruleset operation in the API Reference.