Automatically Adding Monitors

From ZoneMinder Wiki
Jump to navigationJump to search

I recently had cause to want to add monitors to Zoneminder automatically. This is how I did it. It's probably not the correct way - I got it working through trial and error (never the most compatible method) and I'm a somewhat cavalier coder, and others are welcome to edit this page and improve the procedure, but it does work.

DISCLAIMER! This could hose your database. If Zoneminder's schema changes in the future, it almost certainly will. Use at your own risk!


Reason: I manage over a 100 CCTV cameras across five sites via bespoke perl cgi software. This display and arrange direct mjepg feeds (described in IpCamMontage ), and I wanted to be able to control my various remote zoneminder servers using that. Managing this directly is time consuming, and should a server go down it's a right faff to set up again. This way would allow me to re-configure a server instantly. I could also use it to set various configurations.

Firstly, add a user to mysql with write permissions to the ZM database and if your software isn't local, allow them to connect from anywhere/your control server using a decent password.

Then simply issue a mysql INSERT such as;

INSERT INTO Monitors SET name = 'Camera_Name', type='Remote', Port='80', host='10.10.10.5', path = '/videostream.cgi?user=username&pwd=password', width='640', height='480', Function = 'Mocord', MaxFPS = '5.00', AlarmMaxFPS = '5.00', Protocol = 'http', Method = 'simple', Palette = '3'

The above is enough (with ZM 1.25) to add a new monitor to Zoneminder. In this case, for a Foscam-compatible camera at 10.10.10.5, using mjpeg with a camera user/pass of username/password in VGA colour - using Mocord at 5fps.

If you also want to use motion detection (modect/mocord) then you'll need to add a zone too. First you'll need to find the monitorId of the event you've just added, then use something like this, which is for a 640x480 image

INSERT INTO Zones SET MonitorId = '$monitorID', Name = 'All', Type = 'Active', Units='Percent', NumCoords=4, Coords='0,0 639,0 639,479 0,479', Area = 307200, AlarmRGB=16711680, CheckMethod='Blobs', MinPixelThreshold=25, MinAlarmPixels=9216, MaxAlarmPixels=230400, FilterX=3, FilterY=3, MinFilterPixels=9216, MaxFilterPixels=230400, MinBlobPixels=6144, MinBlobs=1


If you happen to have Zoneminder's console open, nothing will happen until it refreshes, or you force a refresh, then the new monitor will show. Zoneminder won't immediately activate it, but after a minute or so will notice this monitor and that it's not doing anything, and start it.

And of course, by directly manipulating the database, you can set statuses and delete monitors too. (I find the Zoneminder way of automatically setting statuses for day/night rather clunky and tiresome to keep up to date with changing monitors). By issuing db commands directly, you can of course control it as much as you like.


If you're a strict coder and the above fills you with horror, well, I do understand. :)