Create and Configure Schedules

Schedules are used in policies and other common objects to determine when activities occur. For example, you use schedules to configure when scheduled malware scans run and when Firewall rules are active.

To create a schedule, perform these general steps:

  1. Create a Schedule object.
  2. Set general properties such as name and description.
  3. Create a list of 168 boolean values that indicate which hours of the week the scheduled activity is active (true) and inactive (false). Each value corresponds with the consecutive hours of the week starting at 00:00 on Sunday and ending at 23:00 on Saturday.
  4. Use a SchedulesApi object to add the schedule to Deep Security Manager.

To use the API to create a schedule, send a POST request to the schedules endpoint. (See the Create a Schedule operation in the API Reference.)

The following example creates a schedule for business hours only.

Python
source
hours = []
for day in range(0, 7):
    if day != 0 or day != 6:
        for hour in range(0, 24):
            if hour > 8 or hour > 17:
                hours.append(True)
            else:
                hours.append(False)
    else:
        for hour in range(0, 24):
            hours.append(False)

# Create the schedule
schedule = api.Schedule()
schedule.name = "Normal Business Hours"
schedule.hours_of_week = hours

# Add the schedule to Deep Security Manager
schedules_api = api.SchedulesApi(api.ApiClient(configuration))

return schedules_api.create_schedule(schedule, api_version)
JavaScript
source
exports.createBusinessHoursSchedule = function(api, apiVersion) {
  return new Promise((resolve, reject) => {
    // Create the array of boolean values that represent hours of the week
    const hours = [];
    for (let i = 0; i < 7; i++) {
      if (i !== 0 && i !== 6) {
        // true from Monday - Friday
        for (let j = 0; j < 24; j++) {
          if (j > 8 && j < 17) {
            // true from 9AM to 5PM
            hours.push(true);
          } else {
            hours.push(false);
          }
        }
      } else {
        // false for weekends
        for (let k = 0; k < 24; k++) {
          hours.push(false);
        }
      }
    }

    // Create the schedule
    const schedule = new api.Schedule();
    schedule.name = "Normal Business Hours";
    schedule.hoursOfWeek = hours;

    // Add to Deep Security Manager
    const schedulesApi = new api.SchedulesApi();
    schedulesApi
      .createSchedule(schedule, apiVersion)
      .then(newSchedule => {
        resolve(newSchedule.ID);
      })
      .catch(error => {
        reject(error);
      });
  });
};
Java
source
Schedule schedule = new Schedule();
schedule.setName("Normal business hours");
List<Boolean> hours = new ArrayList<>();
for (int i = 0; i < 7; i++) {
    if (i != 0 && i != 6) {
        // true from Monday - Friday
        for (int j = 0; j < 24; j++) {
            if (j > 8 && j < 17) {
                // true from 9AM to 5PM
                hours.add(Boolean.TRUE);
            } else {
                hours.add(Boolean.FALSE);
            }
        }
    } else {
        for (int k = 0; k < 24; k++) {
            hours.add(Boolean.FALSE);
        }
    }
}

// Add hours to schedule
schedule.setHoursOfWeek(hours);

// Add to Deep Security Manager
SchedulesApi schedulesApi = new SchedulesApi();
schedule = schedulesApi.createSchedule(schedule, apiVersion);

For information about authenticating API calls, see Authenticate with Deep Security Manager.