# Schedules

> Automate CIS compliance scans with cron-based schedules in SecureBaseline Cloud - recurring tasks, notifications, and execution logs

Source: https://opennix.org/en/docs/haas/schedules/

## Overview

Schedules automate recurring compliance scans and hardening jobs using cron expressions. Set up schedules to ensure regular security assessments.

## Navigation

**Menu**: Infrastructure > Schedules

## Page Layout

### Toolbar

| Button | Description |
|--------|-------------|
| Create Schedule | Create a new schedule |

### Schedule Table

| Column | Description |
|--------|-------------|
| Name | Schedule name |
| Schedule | Cron expression with human-readable description and clock icon |
| Task Type | Compliance Scan (blue tag) or Hardening (orange tag) |
| Host | Target server hostname |
| Last Run | Last execution timestamp |
| Next Run | Next scheduled execution timestamp |
| Enabled | Toggle switch to enable/disable schedule |
| Actions | Edit and Delete buttons |

### Pagination

- Default page size: 50 items
- Available sizes: 20, 50, 100, 200 items per page
- Shows range indicator (e.g., "1-50 / 100")

## Creating a Schedule

1. Click **Create Schedule** button
2. Fill in the schedule form:

### Schedule Form Fields

| Field | Description | Required |
|-------|-------------|----------|
| Name | Descriptive name for the schedule | Yes |
| Description | Optional notes about the schedule | No |
| Cron Expression | When to run (select preset or enter custom) | Yes |
| Task Type | Compliance Scan or Hardening | Yes |
| Host | Target server (shows hostname, IP, and OS) | Yes |
| SCAP Profile | Profile for compliance scan (shown only for compliance_scan type) | Yes (for scans) |
| Enabled | Toggle to enable/disable on creation | No (default: on) |

3. The form shows a human-readable preview of the cron schedule
4. Click **OK** to create

### SCAP Profile Selection

When creating a compliance scan schedule:
- First select the host
- The profile dropdown is filtered to show only profiles compatible with the host's OS
- If host has no detected OS, all profiles are shown

## Editing a Schedule

1. Click the **Edit** button (pencil icon) on a schedule row
2. Modify fields in the edit modal
3. Click **OK** to save changes

All fields are editable including the enabled status.

## Enabling/Disabling Schedules

Two ways to toggle schedules:

1. **Toggle Switch**: Click the switch in the Enabled column
2. **Edit Modal**: Change the Enabled field in the edit form

When a schedule is:
- **Enabled (On)**: Schedule will run at specified times
- **Disabled (Off)**: Schedule is paused, will not run

## Deleting a Schedule

1. Click the **Delete** button (trash icon) on a schedule row
2. Confirm deletion in the popup dialog
3. Schedule is removed from the system

## Cron Expression

Cron expressions define when schedules run. Format:

```
minute hour day month weekday
  0-59  0-23 1-31  1-12   0-6
```

### Preset Schedules

Select from common presets in the dropdown:

| Preset | Cron | Description |
|--------|------|-------------|
| Every hour | `0 * * * *` | At minute 0 of every hour |
| Daily at midnight | `0 0 * * *` | Every day at 00:00 |
| Daily at 2 AM | `0 2 * * *` | Every day at 02:00 |
| Every 6 hours | `0 */6 * * *` | At 00:00, 06:00, 12:00, 18:00 |
| Weekly (Sunday) | `0 0 * * 0` | Every Sunday at midnight |
| Monthly (1st) | `0 0 1 * *` | First day of month at midnight |

### Custom Expressions

To enter a custom cron expression:
1. Open the cron expression dropdown
2. Type the custom expression in the input field at the bottom
3. Press Enter to apply

Examples:

| Expression | Meaning |
|------------|---------|
| `30 4 * * *` | Daily at 4:30 AM |
| `0 9-17 * * 1-5` | Hourly 9AM-5PM, Monday-Friday |
| `0 0 * * 0,6` | Midnight on weekends |
| `0 */2 * * *` | Every 2 hours |
| `0 0 15 * *` | 15th of each month |

### Cron Field Values

| Field | Values |
|-------|--------|
| Minute | 0-59 |
| Hour | 0-23 |
| Day of Month | 1-31 |
| Month | 1-12 |
| Day of Week | 0-6 (0=Sunday) |

### Special Characters

| Character | Meaning | Example |
|-----------|---------|---------|
| `*` | Any value | `* * * * *` = every minute |
| `,` | List | `0,30 * * * *` = :00 and :30 |
| `-` | Range | `0 9-17 * * *` = 9AM to 5PM |
| `/` | Step | `*/15 * * * *` = every 15 min |

### Human-Readable Preview

When you enter a valid cron expression, an info alert appears below the field showing the human-readable schedule description. This helps verify the schedule is correct before creating.

### Cron Validation

The form validates cron expressions:
- Must have exactly 5 parts separated by spaces
- Each part must be within valid ranges
- Invalid expressions show error messages

## Schedule Types

### Compliance Scan Schedule

Runs automated CIS compliance scans:

1. Select **Compliance Scan** as task type
2. Choose target host
3. Select SCAP profile (filtered by host OS)
4. Set cron schedule

Use cases:
- Weekly security assessments
- Daily compliance monitoring
- Pre-audit verification

### Hardening Schedule

Runs automated hardening jobs:

1. Select **Hardening** as task type
2. Choose target host
3. Set cron schedule

**Warning**: Automated hardening should be used carefully. Ensure servers are tested before enabling automated hardening in production.

## Schedule Execution

### How It Works

1. Scheduler checks for due schedules every minute
2. When a schedule is due, it creates a job
3. Job is added to the queue
4. Worker processes the job
5. Last run time is recorded
6. Next run time is calculated

### Viewing Execution History

- **Compliance Scans**: Go to Compliance page, filter by host
- **Hardening Jobs**: Go to Jobs page, view by host
- **Last/Next Run**: Check the schedule table columns

### Timestamps

- **Last Run**: Shows when the schedule last executed
- **Next Run**: Shows when the schedule will next execute
- Times are displayed in your browser's local timezone

## Best Practices

### Compliance Scanning

- Weekly scans for most environments
- Daily scans for high-security environments
- Schedule during low-usage periods

### Hardening

- Avoid automated hardening in production without testing
- Use for development/test environments first
- Always have monitoring in place
- Consider manual hardening for production

### Schedule Naming

Use descriptive names:
- `Weekly Compliance - Web Servers`
- `Daily Security Scan - Production`
- `Monthly Hardening - Dev Environment`

### Time Selection

- Avoid business hours for resource-intensive scans
- Consider server time zones
- Stagger schedules to avoid overload
- Use off-peak hours (2 AM, 3 AM)

## Troubleshooting

### Schedule Not Running

1. Verify schedule is enabled (toggle is on)
2. Check cron expression is valid
3. Verify scheduler service is running
4. Check worker is processing jobs
5. Review scheduler logs for errors

### Jobs Queued But Not Running

1. Check worker service status
2. Verify Redis connection
3. Review worker logs
4. Check Jobs page for stuck jobs

### Wrong Execution Time

1. Verify cron expression in the schedule
2. Check server timezone
3. Note: All times are in server timezone
4. Use the human-readable preview to verify

### Schedule Shows Old Next Run Time

1. Check if schedule is enabled
2. Refresh the page
3. Verify scheduler service is running
4. Next run time updates after each execution

### Too Many Jobs Queued

1. Reduce schedule frequency
2. Stagger schedules across hours
3. Consider disabling low-priority schedules
4. Check if previous jobs are completing

## Related Pages

- [Compliance Scanning](/en/docs/haas/compliance-scanning/) - View scan results
- [Jobs](/en/docs/haas/jobs/) - View hardening job history
- [Hosts](/en/docs/haas/hosts/) - Manage target servers

