Page 1 of 1

Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 12:53 pm
by Dan12345
Hi,

I'm trying to trigger a notification as soon as an alarm starts (i.e. immediately, and not once the event has finished).

So I set up a filter running in the background which has "monitor name equal to [name of monitor]". However this only fires when the event is finished. Is there a way I can trigger it immediately?

thanks,

Dan

Re: Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 1:37 pm
by asker
Google for zmeventserver

Re: Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 1:42 pm
by Dan12345
brilliant - thank you!

Re: Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 2:40 pm
by Dan12345
On second thoughts - ouch - much too complicated for me. I just want to run a simple script when an alarm is received, and zmeventserver looks like overkill. Using swatch to monitor syslog seems a lot easier...

Re: Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 4:45 pm
by asker
Sure. That seems reasonable for what you want too.

Re: Trigger notification as soon as alarm starts

Posted: Sat Sep 03, 2016 10:34 pm
by Dan12345
On third thoughts, even swatch is overkill - awk does the trick, run at reboot with cron:

tail -F /var/log/syslog | awk ‘/FireEscape.*alarm start/ { system("wget http://[openhab server]/CMD?CamFireEscape=ON -P /tmp") }'

(and that flicks a virtual switch in my openHAB setup to run notifications etc)

Re: Trigger notification as soon as alarm starts

Posted: Thu Sep 08, 2016 4:09 am
by JTheDoc
Hello Dan, you don't happen to know how to implement your method so I may run a simple .sh script? I'm attempting to have a PTZ camera look a certain direction when motion is detected on another camera.

The script I've got working perfectly fine, I believe putting the script in a folder that www-data has permissions for, and setting the .sh to executable should be enough, but I haven't been able to put this into practice, as filters don't work (Doesn't work, and would be too slow to respond), so having awk trail the logs for "alarm" should be enough for me. If you could help, I would be very grateful! Thank you, and I hope you've been getting along better with ZM much less awkwardly and stressful as I have!
Cheers,

Josh.

Re: Trigger notification as soon as alarm starts

Posted: Fri Aug 07, 2020 3:40 pm
by mangocats
So, what I found that's pretty easy (IMO) is the docker container dlandon/Zoneminder - which comes with zmeventserver ready to turn on.

I used that, and wrote this script:

#!/bin/bash
# my_event_start.sh
# to be installed in dlandon/Zoneminder /var/lib/zmeventnotification/bin
# remember to chown www-data:www-data and chmod +x
# in ZM Options System OPT_USE_EVENTNOTIFICATION check and Save
# for urlencode
# sudo apt install gridsite-clients
#
# takes a zmeventnotification and relays it to my webserver

p1=$(urlencode "$1")
p2=$(urlencode "$2")
p3=$(urlencode "$3")
p4=$(urlencode "$4")
data="monitorID=$p2&cause=$p4&monitorName=$p3&event=$p1"

wget --method=POST http://192.168.1.2:34567/play?"${data}"

# tell zoneminder to not do anything else with this event
exit 1


The cause parameter has a value of "Motion zoneA,zoneB,zoneC" where the zones are the zones that the motion was detected in. If you don't have a webserver setup to handle POST requests, you can change the wget line to send $p4 to whatever you've got that will handle those events.

I hope this helps someone, took me long enough to untangle all the crazy complex options.

Now - what I'd really like are individual notifications as soon as motion is detected in the individual zones, instead of a single Event notification that gloms all the zones together, but other than scraping the tail of the log file, I haven't found anything for that, yet.