feat(scheduled-jobs): the cron jobs of config.xml over the REST API (#43)
driver / standard (pull_request) Successful in 25s
driver / lint (pull_request) Successful in 26s
driver / types (pull_request) Failing after 35s
driver / test (3.13) (pull_request) Failing after 18s
driver / test (3.12) (pull_request) Failing after 21s
driver / lowest (pull_request) Failing after 17s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Failing after 40s
CI / driver (pull_request) Failing after 1m25s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 25s
driver / lint (pull_request) Successful in 26s
driver / types (pull_request) Failing after 35s
driver / test (3.13) (pull_request) Failing after 18s
driver / test (3.12) (pull_request) Failing after 21s
driver / lowest (pull_request) Failing after 17s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Failing after 40s
CI / driver (pull_request) Failing after 1m25s
driver / publish (pull_request) Skipped
OPNsense keeps its cron jobs in its configuration and runs each as a configd action, so the POSIX implementation does not fit: the driver has no shell, and a job's command is not a shell line. The cron API reads and writes them instead. get_scheduled_jobs reads every job in one request (/api/cron/settings/get, which carries the selected action rather than its display text). A job another component registered is platform, one written by put_scheduled_job carries the napalm-scheduled-job marker in its description and is application, the rest admin. Every job can be enabled and disabled; only an application's job is edited or deleted. put_scheduled_job takes a configd action as command and refuses one configd does not offer; get_scheduled_job_commands lists them. Running a job now is refused: the API cannot run a configd action. Every write reads the job again and refuses one whose digest changed. Parameters are written one per line and only without blanks, quotes or backslashes: OPNsense up to 26.1 splits them as a shell would, 26.7 takes a line per argument, and only such arguments mean the same to both. Requires napalm-device-types 4.26.0. Closes #43
This commit is contained in:
1 parent
80d6b8cb71
commit
c4ff19ac20
8 files changed
+1091
-5
No files matched your search
@@ -16,7 +16,7 @@ NAPALM community driver for **OPNsense** firewalls (read-only, via REST API).
|
||||
|---|---|
|
||||
| Python | 3.12 |
|
||||
| NAPALM | 4.0 |
|
||||
| napalm-device-types | 4.21.1 |
|
||||
| napalm-device-types | 4.26.0 |
|
||||
| requests | 2.28 |
|
||||
|
||||
## Installation
|
||||
@@ -92,10 +92,15 @@ arguments.
|
||||
| `get_listening_sockets` | ✅ | `GET /api/diagnostics/interface/get_socket_statistics` + `/api/core/service/search` + `/api/wireguard/service/show` (WireGuard's kernel sockets by listen port) |
|
||||
| `get_virtual_ips` | ✅ | `GET /api/interfaces/overview/export`: every address bound to a CARP VHID (CARP address and IP aliases on it), with this node's CARP state. `interfaces/vip_settings` is not read: it carries the CARP passwords |
|
||||
| `ping_sweep` | ✅ ³ | same endpoints, one batch of parallel jobs at a time |
|
||||
| `get_scheduled_jobs()` | ✅ ⁴ | `GET /api/cron/settings/get`: every cron job of config.xml |
|
||||
| `manage_scheduled_job(key, action, digest=)` | ✅ ⁴ | enable, disable: `POST /api/cron/settings/toggle_job/<uuid>/1` (or `/0`) + `/api/cron/service/reconfigure`; run now is refused |
|
||||
| `put_scheduled_job(spec)` / `delete_scheduled_job(key, digest=)` | ✅ ⁴ | an application's own job: `add_job`, `set_job/<uuid>`, `del_job/<uuid>` + `reconfigure` |
|
||||
| `get_scheduled_job_commands()` | ✅ ⁴ | `GET /api/cron/settings/get_job`: the configd actions a job can run |
|
||||
|
||||
> ¹ Requires the `os-lldpd` plugin. Returns empty dict if the plugin is not installed.
|
||||
> ² Requires the `os-frr` (FRR/Quagga) plugin. Returns empty dict if the plugin is not installed or FRR is not running.
|
||||
> ³ Overrides the generic per-host loop from `napalm-device-types`.
|
||||
> ⁴ See [Scheduled jobs](#scheduled-jobs).
|
||||
|
||||
### Ping
|
||||
|
||||
@@ -120,6 +125,29 @@ statistics line lands in the log slightly after the request that triggered it.
|
||||
`ttl` and `vrf` are accepted for NAPALM compatibility and ignored — the API
|
||||
has no equivalent.
|
||||
|
||||
### Scheduled jobs
|
||||
|
||||
OPNsense keeps its cron jobs in config.xml (System → Settings → Cron), and each
|
||||
runs a **configd action**, not a shell line. `key` is `opnsense:<uuid>`, `kind`
|
||||
`cron`, `source` `config.xml`, `run_as` `root`. A job another component
|
||||
registered (its origin is not `cron`, such as the intrusion detection's rule
|
||||
update) is `platform`; one whose description starts with
|
||||
`napalm-scheduled-job: <name>` was written by `put_scheduled_job` and is the only
|
||||
kind that can be edited or deleted; every other job is `admin`. Every job can be
|
||||
enabled and disabled.
|
||||
|
||||
`put_scheduled_job` takes a configd action as `command`, with its parameters as
|
||||
the words after it: the actions are what `get_scheduled_job_commands()` lists,
|
||||
anything else is refused (`ScheduledJobRefused`), and so is `@reboot` and a
|
||||
parameter with blanks, quotes or backslashes, which OPNsense releases before and
|
||||
after 26.7 would split differently. The schedule is written as its five fields,
|
||||
month and weekday names as numbers.
|
||||
|
||||
Not covered: the API cannot run a configd action now, so no job takes `run`;
|
||||
what OPNsense writes into the crontab beyond config.xml (`periodic`, the
|
||||
plugins' system jobs) cannot be read over the API; the time zone is not read
|
||||
(`None`).
|
||||
|
||||
## Config management
|
||||
|
||||
OPNsense does not expose a single generic "push config" endpoint. Config is
|
||||
|
||||
Reference in new issue
Block a user