Repository navigation
feat(onvif): event notes and tags from what the camera detected (zmc 1.39.57) - #292
Open
SteveGilvarry wants to merge 3 commits into
Open
SteveGilvarry wants to merge 3 commits into
SteveGilvarry wants to merge 3 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>
…1.39.57)
Ports ZoneMinder #7712 (fec099942) to zm-api's own ONVIF listener.
onvif::event_words is ONVIFEventNote, ONVIFAddTagNames and ONVIFEventTags:
- The note names the detection instead of quoting the raw topic: namespace
prefixes stripped, a leading RuleEngine/ dropped, inactive / empty /
per-object-id items left out, active items reduced to their name, the
Source Rule in parentheses ("TPSmartEventDetector/TPSmartEvent IsPeople
(MyTPSmartEventDetectorRule)").
- On monitors with ONVIF_Event_Tags on, the event is tagged with every object
class the alarm names, matched case-insensitively against AI_Object_Classes
names and aliases (an alias wins over a class name), else with the topic's
last segment. Words come from active item names (IsPeople -> People), item
values (ClassTypes "Human Vehicle") and the topic's last segment.
Its tests are ZoneMinder's tests/zm_onvif_event_note.cpp cases.
The listener loads the names and aliases once when it starts, as zmc does
(falling back to topic tags on a database without Aliases), tags an event
when it opens and again when a later "still active" message for it names
something new, each tag once per event. repo::events_tags::tag_event_by_name
finds or creates the tag (cut to 64 characters) and links it once, as zmc's
Event::AddTag does, tolerating a writer that got there first.
Fix: the listener's event insert left out Events.StateId (NOT NULL, no
default), so on a strict-mode MySQL, ZoneMinder's default, every ONVIF
alarm event failed to save. It now records the active run state or 0, as
zmc and the events API do. The insert moves to insert_alarm_event so the
DB test exercises it.
spawn_monitor_event_listener takes a ListenedMonitor instead of separate
monitor arguments.
Tests: 1452 passed (cargo test --all-features); 613 DB-backed passed on a
1.39.57 test database, including it_onvif_event_tags. Not driven end to
end over the network: the ONVIF transport refuses loopback targets.
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 #291, which is stacked on #290. Only
e2e1a93is new here; the diff will show all three until those merge.This ports ZoneMinder #7712 (
fec099942, "ONVIF event notes and tags from what the camera detected") to zm-api's own ONVIF event listener. It also fixes a bug that stopped that listener from recording any events on standard ZoneMinder databases.Notes and tags
onvif::event_wordsportsONVIFEventNote,ONVIFAddTagNamesandONVIFEventTagsfromsrc/zm_monitor_onvif.cpp. Its tests are ZoneMinder's own cases fromtests/zm_onvif_event_note.cpp, and they all pass.MyRuleDetector/PeopleDetectpersonTPSmartEventDetector/TPSmartEvent IsPeople (MyTPSmartEventDetectorRule)personObjectDetection/Object ClassTypes=Human Vehicle (AjaxObjectRule)person,vehicleCellMotionDetector/MotionMotion(no object named: the topic's last segment)How the listener uses them:
onvif_event_tagson. Words are matched case-insensitively againstAI_Object_Classesnames andaliases, which are seeded by feat(db): mirror ZoneMinder 1.39.42-57 #290'scamera_classes.sqland editable through feat(api): ZoneMinder 1.39.42-57 features: cron jobs, scheduled actions, new columns #291.zmcdoes. On a database withoutAliases, it falls back to tagging with the topic.Human, thenHuman Vehicle). Each tag goes on an event only once.repo::events_tags::tag_event_by_namefinds or creates the tag, with the name cut to 64 characters, and links it once, asEvent::AddTagdoes. It tolerates another writer, such aszmc, having created the tag or link first.Fix: the listener never saved events on strict-mode MySQL
The listener's event insert left out
Events.StateId, which is NOT NULL with no default. On a strict-mode MySQL, which is ZoneMinder's default, every ONVIF alarm event failed with error 1364 ("Field 'StateId' doesn't have a default value"). It now records the active run state, or 0, aszmcand zm-api's events API already do. The insert moves intoinsert_alarm_eventso that a database test exercises it.Testing
cargo fmt --check,cargo clippy --all-targets --all-features -D warnings: cleancargo test --all-features: 1452 passed, including ZoneMinder's note and tag cases plus tracker and Rule unit tests.it_onvif_event_tagstakes a Tapo-style alarm throughinsert_alarm_event, checks the note, matches tags against the seeded aliases, and checks that tags and links are each created once.🤖 Generated with Claude Code