Repository navigation
feat(api): ZoneMinder 1.39.42-57 features: cron jobs, scheduled actions, new columns - #291
Open
SteveGilvarry wants to merge 2 commits into
Open
SteveGilvarry wants to merge 2 commits into
SteveGilvarry wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #290 (the schema mirror). Until #290 merges, this diff shows both commits; only
77a69e6is 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::crontabis a port of ZoneMinder'sCronTab.php,Command.phpand thecronLine()methods:ZM_ALLOWED_COMMANDS: an empty list means no restriction; otherwise the program must be on the list and the command may not chain another.Endpoints and behaviour:
/api/v3/cron-jobs: CRUD behindFeature::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.installed/skipped/failed, plus a message).ZM_ALLOWED_COMMANDSgets a 403 that names what is allowed.POST /api/v3/cron-jobs/crontabrebuilds on demand, for example after changingZM_ALLOWED_COMMANDS.trigger_on: "Schedule"with a validated five-fieldschedule. 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.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 asskipped.The other new columns
go2rtc_disable_back_channel(1.39.45),onvif_event_tags(1.39.57)object_coords(1.39.54), checked with ZoneMinder's zone-editor pattern; anything else is a 400auto_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 rulealiases(1.39.57), comma-separated wordslanguageup to 16 characters (1.39.56)The entities gain these fields, plus a
CronJobsentity.openapi.jsonis 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_tagsyet. ZoneMinder implements the tagging inzmc; porting it into zm-api's listener is a follow-up.Testing
cargo fmt --check,cargo clippy --all-targets --all-features -D warnings: cleancargo test --all-features: 1447 passedAPP_PROFILE=test-db --include-ignored, test database loaded at 1.39.57): 611 passed. That includes the newit_cron_jobs(round trip, validation, System permissions,ZM_ALLOWED_COMMANDS),it_zm_1_39_57_fields, and a scheduled-action case init_monitor_actions.🤖 Generated with Claude Code