Shared memory (real-time monitor status)
pyzm.zm.shm.SharedMemory reads ZoneMinder’s memory-mapped files
(/dev/shm/zm.mmap.<monitor_id>) for real-time monitor state without
API calls. This is the same shared memory that ZM’s internal processes use.
Supports ZM 1.36.x, 1.36.34+, and 1.38+ struct layouts (auto-detected).
from pyzm.zm.shm import SharedMemory
# Context manager ensures cleanup
with SharedMemory(monitor_id=1) as shm:
print(shm.is_valid()) # True if mmap can be read
print(shm.is_alarmed()) # True if currently in ALARM state
print(shm.alarm_state()) # {"id": 0, "state": "STATE_IDLE"}
print(shm.last_event()) # last event ID (int)
print(shm.cause()) # {"alarm_cause": "...", "trigger_cause": "..."}
print(shm.trigger()) # trigger text, showtext, cause, state
# Raw data dicts
sd = shm.get_shared_data() # all SharedData fields
td = shm.get_trigger_data() # all TriggerData fields
# Full dump (both shared + trigger)
data = shm.get()
SharedData fields include: state, capture_fps, analysis_fps,
last_event, alarm_x, alarm_y, valid, signal,
imagesize, last_frame_score, startup_time, heartbeat_time,
alarm_cause, and more (varies by ZM version).
Note
SharedMemory requires read access to /dev/shm/zm.mmap.* files.
On a typical ZM installation, run as www-data or with appropriate
permissions.