Page 1 of 1

run command when an even ocurrs / trigger event with command

Posted: Wed Mar 12, 2008 2:00 am
by schweini
Hi!

Is there a way to configure ZoneMinder, or a specific Monitor to run a linux command when an event occurs? The reverse would be very interesting, too: triggering an event by calling some command from outside of zoneminder. I seem to remember that there was a comamnd for the latter, but can't find it in the docs anymore.

Posted: Wed Mar 12, 2008 7:54 pm
by schweini
Ok. It seems that zmtrigger.pl can be used to trigger events from outside of ZM (although i still haven't got it to work - the docs are a bit lacking, i think. can zmtrigger read from STDIN?)

But the more important part of my question (for me) was how to get ZM to call some external command when an event occurs - the exact opposite of zmtrigger.pl

Thanks for any help.

Posted: Wed Mar 12, 2008 8:18 pm
by cordel
You can use filters as described in the documentation to run your own scripts or write your own and use the zoneminder perl modules to interface with zm.

External events

Posted: Wed Mar 12, 2008 11:38 pm
by coke
You can send events to ZoneMinder fairly easily via TCP port 6802, I've successfully tried that so far. There are other connection options (Unix?) I haven't experimented with that might work as well.

Posted: Wed Mar 26, 2008 3:48 pm
by igor
Hi,
I have configured a filter that runs a command when an event occurs but it doesn't work. I need it for run gnokii that sends me an sms:

$ echo 'message here' | gnokii --config /etc/gnokiirc --sendsms PhoneNumber

I tried to run other command and it doesn't work yet but if I select the "Email details of all matches" it works perfectly.

Can someone help me?
tnx

Posted: Wed Mar 26, 2008 4:13 pm
by azir
From zoneminder documentation
http://www.zoneminder.com/wiki/index.ph ... ing_Events :
Finally you can also specify a script which is run on each matched event. This script should be readable and executable by your web server user. It will get run once per event and the relative path to the directory containing the event in question. Normally this will be of the form <MonitorName>/<EventId> so from this path you can derive both the monitor name and event id and perform any action you wish. Note that arbitrary commands are not allowed to be specified in the filter, for security the only thing it may contain is the full path to an executable. What that contains is entirely up to you however.
So your command

echo 'message here' | gnokii --config /etc/gnokiirc --sendsms PhoneNumber

must be written to a script eg. /var/www/htdocs/zm_sendsms.sh and and set it as executable

Code: Select all

chmod 755 /var/www/htdocs/zm_sendsms.sh
zm will use its full path /var/www/htdocs/zm_sendsms.sh , when an even occured (eg. from camera 1)
zm will call it as /var/www/htdocs/zm_sendsms.sh 1/nnn, where 1 is camera Id and nnn is the occuring Event Id
[/b]

Posted: Wed Mar 26, 2008 5:57 pm
by igor
I created /usr/share/zoneminder/zm_sendsms.sh
that contains

Code: Select all

 
echo 'message here' | gnokii --config /etc/gnokiirc --sendsms 38070xxxxx 
with 755 permissions

and created a filter:
images in alarm >= 1,
command to execute: "zm_sendsms.sh"

I tried also the full path /usr/share/zoneminder/zm_sendsms.sh but it doesn't work. Where is the mistake?
tnx

Posted: Wed Mar 26, 2008 7:00 pm
by schweini
could you check /tmp/zmfilter.log for errors?

in my case there were some errors there, which i still couldn't get to work. maybe we have the same problem, and could work this out together.

Posted: Thu Mar 27, 2008 8:49 am
by azir
Just to make sure that zm handle execute filter properly, could you please use simple script that write somethig to a file eg.

Code: Select all

#!/bin/sh
date > /tmp/somefile.log
echo "I was called as $@" >> /tmp/somefile.log
to replace zm_sendsms.sh temporaryly.
if /tmp/somefile.log really exists and contain the output of script above, then
maybe there something wrong with the zm_sendsms.sh or any commands in it.
Check /tmp/zmfilter.log when the Event triggering the filter, try

Code: Select all

tail -f /tmp/zmfilter.log

Posted: Thu Mar 27, 2008 9:30 am
by schweini
all i get with a test script is:

Code: Select all

03/16/08 23:32:15.654832 zmfilter[22022].ERR [Auto execute script '/tmp/zoneminderScript.pl' not found, skipping filter '_TempFilter1205731933']
and the script is chmod 777, runnable by apache (and any other) user under shell and cgi.

and i triple-checked that i specified the command correctly various times. i put it in /tmp/ , in /, in zoneminders home, etc.

Posted: Thu Mar 27, 2008 6:28 pm
by igor
Created /tmp/somefile.log chmod 777

Code: Select all

#!/bin/sh
/usr/bin/gnokii --config /etc/gnokiirc --dialvoice 38070xxxxx
date > /tmp/somefile.log
echo "I was called as $@" >> /tmp/somefile.log
When an the event occurs it writes somefile.log correctly and exit normally. This is the log output:

03/27/08 19:09:04.581008 zmfilter[12060].DBG [Checking filter 'call', execute]
03/27/08 19:09:04.586316 zmfilter[12060].DBG [Checking event 1151]
03/27/08 19:09:04.586635 zmfilter[12060].INF [Executing '/usr/share/zoneminder/zm_sendsms.sh 8/1151']
03/27/08 19:09:04.589702 zmfilter[12060].DBG [Output: ]

But gnokii doesn't call me or send sms. Zoneminder requires a certain exit status?

Posted: Thu Mar 27, 2008 6:44 pm
by azir
From igor's zmfilter.log file, I am now sure that his zm installation is OK and as I presume before
that maybe some commands inside the script failed to run properly.
is webserver-user has access to the /etc/gnokiirc ?
Try to run the script as webserver-user (mine apache)

Code: Select all

root ~# su - apache
apache ~$ /usr/bin/gnokii --config /etc/gnokiirc --dialvoice 3807016441 
Is there any error messages ?

Posted: Thu Mar 27, 2008 8:45 pm
by igor
Thanks azir, you were right. www-data (my webserver user) had no access to /dev/ttyACM0, now I set the correct chmod and it works. :D