Skip to content

feat(api): ZoneMinder 1.39.42-57 features: cron jobs, scheduled actions, new columns - #291

Open
SteveGilvarry wants to merge 2 commits into
ZoneMinder:masterfrom
SteveGilvarry:feat/zm-1.39.57-api
Open

SteveGilvarry wants to merge 2 commits into
ZoneMinder:masterfrom
SteveGilvarry:feat/zm-1.39.57-api

Conversation

@SteveGilvarry

Copy link
Copy Markdown
Member

Stacked on #290 (the schema mirror). Until #290 merges, this diff shows both commits; only 77a69e6 is new here.

This exposes what ZoneMinder 1.39.42–57 added, and makes the two scheduling features actually run.

Scheduled tasks and scheduled monitor actions (1.39.42 / 43)

ZoneMinder runs both from a marked block in the web user's crontab, and rebuilds that block whenever its web UI saves a job or action. A row that is only written to the database never runs. So zm-api has to do the same rebuild.

service::crontab is a port of ZoneMinder's CronTab.php, Command.php and the cronLine() methods:

  • It checks schedules and commands exactly as ZoneMinder does.
  • It enforces ZM_ALLOWED_COMMANDS: an empty list means no restriction; otherwise the program must be on the list and the command may not chain another.
  • It rewrites only ZoneMinder's block, keeping every other crontab line byte for byte.
  • Its unit tests are ZoneMinder's own PHP test cases, so the two implementations agree.

Endpoints and behaviour:

  • /api/v3/cron-jobs: CRUD behind Feature::System. Reading needs View and changing needs Edit, because a job runs its command as the web user; ZoneMinder gates its own page the same way.
    • Create and update return the job together with the crontab outcome (installed / skipped / failed, plus a message).
    • A command outside ZM_ALLOWED_COMMANDS gets a 403 that names what is allowed.
    • POST /api/v3/cron-jobs/crontab rebuilds on demand, for example after changing ZM_ALLOWED_COMMANDS.
  • Monitor actions: they accept trigger_on: "Schedule" with a validated five-field schedule. For other triggers the schedule is stored empty, as ZoneMinder does. A change to a scheduled action rebuilds the crontab, and so does deleting a monitor that a scheduled action involves.
  • Account check: the crontab is only written when zm-api runs as ZM_WEB_USER. Running as any other account, zm-api would write a second block into that account's crontab and every item would run twice. So in that case the rebuild is skipped with a warning and reported as skipped.

The other new columns

Resource Field
Monitors go2rtc_disable_back_channel (1.39.45), onvif_event_tags (1.39.57)
Zones object_coords (1.39.54), checked with ZoneMinder's zone-editor pattern; anything else is a 400
Filters auto_tag, auto_tag_id (1.39.55). The tag must exist, and a tagging filter counts as an automatic action for the every-monitor permission rule
AI object classes aliases (1.39.57), comma-separated words
Users language up to 16 characters (1.39.56)

The entities gain these fields, plus a CronJobs entity. openapi.json is refreshed; the compatibility check reports only new endpoints and optional fields.

Not in this PR

zm-api's own ONVIF event listener doesn't honour onvif_event_tags yet. ZoneMinder implements the tagging in zmc; porting it into zm-api's listener is a follow-up.

Testing

  • cargo fmt --check, cargo clippy --all-targets --all-features -D warnings: clean
  • cargo test --all-features: 1447 passed
  • DB-backed suite (APP_PROFILE=test-db --include-ignored, test database loaded at 1.39.57): 611 passed. That includes the new it_cron_jobs (round trip, validation, System permissions, ZM_ALLOWED_COMMANDS), it_zm_1_39_57_fields, and a scheduled-action case in it_monitor_actions.

🤖 Generated with Claude Code

SteveGilvarry and others added 2 commits November 29, 2026 19:10
Thirteen upstream updates (1.39.42-46, 49, 51-57; the other versions in
that range changed no schema) are mirrored as SeaORM migrations, vendored
into db/legacy for the bridge's raw chain, and the cutover moves to
1.39.57. zm_create.sql.in, controls.sql, AI_Models.sql and the new
camera_classes.sql come from ZoneMinder fc2bb717f; zm_config.sql is
regenerated from the same commit.

Schema: MonitorActions.Schedule and a Schedule trigger (42), CronJobs (43),
Monitors.Go2RTCDisableBackChannel (45), Tags.Name to utf8mb4_bin on MySQL
(51), Zones.ObjectCoords (54), Filters.AutoTag/AutoTagId (55),
Users.Language varchar(16) (56), Monitors.ONVIF_Event_Tags and
AI_Object_Classes.Aliases (57). Data: HeroSpeed controls (44), the stock
Update DiskSpace filter removed (46), preset url and control fixes (49,
53), the Camera dataset and starter aliases (57). 1.39.52's clean-up of
upgraded schemas is mirrored with its guards; on a schema this crate
creates every step is already true.

Postgres needed two things MySQL does not: MonitorPresets.ControlId is a
varchar, so 1.39.53's control-id subqueries are cast there; and the
AI_Datasets sequence is resynced before the Camera insert, because the
COCO seed's explicit id left it behind. New helpers: mysql_column_type,
resync_sequence. The "schema already current" stamp now also requires the
1.39.43/55/57 markers.

The API does not expose the new columns yet; the entities and endpoints
follow separately.

Verified locally: schema-parity (57 tables, seeds), upgrade-parity from
1.34.26, 1.36.35 and 1.38.3, postgres-schema (756 columns); the 13
mirrors re-run on an already-migrated schema change nothing, and run
cleanly with no change on a copy of a database ZoneMinder's own zmupdate.pl
brought to 1.39.57. cargo test: 1434 passed; schema_gate DB tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns, new columns

Follows the schema mirror (ZoneMinder#290) with what the new columns are for.

Scheduled tasks and scheduled monitor actions (1.39.42/43). ZoneMinder runs
both from a marked block of the web user's crontab, rebuilt from the tables
whenever its web UI saves one; a row saved only to the database never runs.
service::crontab ports CronTab.php, Command.php and the cronLine() methods:
the same schedule and command checks, ZM_ALLOWED_COMMANDS (no list: no
restriction; a list: the program must be on it and nothing may chain), and
a splice that rewrites only ZoneMinder's block and keeps every other line
byte for byte. Its unit tests are ZoneMinder's own PHP cases.

- /api/v3/cron-jobs: CRUD behind Feature::System (View to read, Edit to
  change: a job runs its command as the web user). Create and update answer
  with the job and the crontab outcome; POST /api/v3/cron-jobs/crontab
  rebuilds on demand. A command outside ZM_ALLOWED_COMMANDS is a 403 naming
  what is allowed.
- Monitor actions take trigger_on Schedule with a validated five-field
  schedule (stored empty otherwise, as ZoneMinder does); a change to a
  scheduled action rebuilds the crontab, and so does deleting a monitor that
  scheduled actions involve.
- The rebuild only writes when zm-api runs as ZM_WEB_USER. As another account
  it would write a second block into its own crontab and every item would run
  twice, so it is skipped with a warning and reported as skipped.

New columns through the API: monitors go2rtc_disable_back_channel and
onvif_event_tags; zones object_coords (ZoneMinder's zone-editor pattern, a 400
otherwise); filters auto_tag/auto_tag_id (the tag must exist; counts as an
automatic action for the every-monitor rule); AI object classes aliases
(comma-separated words); user language up to 16. Entities gain the fields and
a CronJobs entity.

openapi.json refreshed: new endpoints and optional fields only.

Tests: 1447 passed (cargo test --all-features), 611 DB-backed passed
(APP_PROFILE=test-db, --include-ignored) on a test database loaded at
1.39.57, including new it_cron_jobs, it_zm_1_39_57_fields and a scheduled
action case in it_monitor_actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant