Anti-Malware: JavaScript Examples

AntiMalwarePolicyExtension example

Create an AntiMalwarePolicyExtension and set property values to configure the state, identify the malware scan configurations to use, and the schedule for real-time scans:

const antiMalwarePolicyExtension = new api.AntiMalwarePolicyExtension();
antiMalwarePolicyExtension.state = api.AntiMalwarePolicyExtension.StateEnum.on;
antiMalwarePolicyExtension.realTimeScanConfigurationID = realTimeScanConfigID;
antiMalwarePolicyExtension.realTimeScanScheduleID = scheduleID;

Modify Anti-Malware policy example

Add the AntiMalwarePolicyExtension object to a Policy object, and then use a PoliciesApi object to modify a policy on Deep Security Manager.

const policy = new api.Policy();
policy.antiMalware = antiMalwarePolicyExtension;

const policiesApi = new api.PoliciesApi();

return policiesApi.modifyPolicy(policyID, policy, apiVersion, { overrides: false });

The policy_id (or policyID) parameter of modifyPolicy identifies the actual policy on Deep Security Manager that is to be modified. This policy is modified according to the policy object that is used as the policy parameter. Any properties of the policy parameter that are not set remain unchanged on the actual policy.

Complete policy configuration example

The following example creates an AntiMalwarePolicyExtension object and uses it to turn on the Anti-Malware module, set the real-time scan configuration to use, and specify the scan schedule for real-time scans.

View source

const policy = new api.Policy();
const policiesApi = new api.PoliciesApi();

// Create and configure the AntiMalwarePolicyExtension object
const antiMalwarePolicyExtension = new api.AntiMalwarePolicyExtension();
antiMalwarePolicyExtension.state = api.AntiMalwarePolicyExtension.StateEnum.on;
antiMalwarePolicyExtension.realTimeScanConfigurationID = realTimeScanConfigID;
antiMalwarePolicyExtension.realTimeScanScheduleID = scheduleID;

// Add to the policy
policy.antiMalware = antiMalwarePolicyExtension;

// Send the change to Deep Security Manager
policiesApi
  .modifyPolicy(policyID, policy, apiVersion, { overrides: false })
  .then(data => {
    resolve(data);
  })
  .catch(error => {
    reject(error);
  });

Example malware scan configuration

The following example sets the directory exclusions for a malware scan configuration and modifies the scan configuration on Deep Security Manager.

View source

// Create a malware scan configuration
const realtimeConfig = new api.AntiMalwareConfiguration();

// Set the exclusion
realtimeConfig.excludedDirectoryListID = dirListID;

// Modify the scan configuration on Deep Security Manager
const amConfigurationsApi = new api.AntiMalwareConfigurationsApi();
amConfigurationsApi
  .modifyAntiMalware(scanConfigID, realtimeConfig, apiVersion)
  .then(scanConfig => {
    resolve(scanConfig.ID);
  })
  .catch(error => {
    reject(error);
  });

To use an HTTP client to interact with a malware scan configuration, use the /api/antimalwareconfigurations endpoint. (See the Anti Malware Configurations operations in the API Reference.)