Modifying ZoneMinder to remember run state names

From ZoneMinder Wiki
Jump to navigationJump to search

Why do we need it?

Zone minder already supports run states. You can configure your monitors in specific modes, save then as "run states" and use cron to switch to them. For example, let's take this situation:

  • You have two cameras
  • You want to have them set in "modect" and "disabled" when you are in the house (say 6PM - 8AM)
  • You want to have them set in "modect" and "enabled" when you are out of the house (say 8:01AM - 5:59PM)

So let's say, you create two states, "in" and "out" and set up your cron to switch between them based on time of day. All great!

But now let's say you want to create a state called 'vacation' which is basically the same as "out" but you want to differentiate it from out because if you are in "vacation" mode, you don't want cron to change state back to "in" - you want to record all the time.

How do you do it? Well you can't because Zoneminder only remembers "monitor states". It does not remember the name of the state. And given that "out" is the same as "vacation" in terms of monitor states, there is nothing that differentiates them as far as zone minder goes.

You can of course work around this limitation by having some sort of check where you change cron files but that is not a clean solution. Plus, lets say you leave for vacation and then need to set your mode to vacation remotely - you likely have access to your ZM console but don't have access to ssh to your box - you'd like to set it to vacation via the ZM console and have cron respect it.

So wouldn't it be cool if we could modify ZM to remember run state names and display them like this?

159429902.bmlBefkq.ScreenShot20150313at1.39.35PM.png


To do this, we need to modify a few files. Here is the strategy:

  • The file that changes run states is called "zmpkg.pl" --> we will modify it to write the run state to a text file. That way we can check that file to know the current run state any time
  • When changing states in cron, we will use a wrapper shell script instead of directly calling zmpkg.pl that will change state only if the current state is not "vacation"
  • To make it more integrated, we will modify the web interface to display the current run state name (in addition to just "Running") just as we showed in the image above

The solution then provides a neat interface to make changes directly via the ZM web interface and check the state as well. No cron file swapping etc needed


Modifying /usr/bin/zmpkg.pl

Here is my modified zmpkg.pl. Look for code after comments starting with #ARC to see changes. PLEASE DO NOT OVERWRITE YOUR ZMPKG.PL without making a backup.

# ARC - variables to keep changed state
my $zm_run_state_file="/usr/share/zoneminder/zm_run_state.txt";
my $store_state="";