Play sound on alarm From the ZM server it's self

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
Alan87i
Posts: 116
Joined: Sun Jul 27, 2008 9:58 am

Play sound on alarm From the ZM server it's self

Post by Alan87i »

I had a lot of help over at LQ.org So First off big thanks from this newb to the folks on that board.

This will setup your ZM box to play a wav file on it's local speakers every time the desired monitor goes into alarm.
I use it for the monitor on my driveway and on the front door monitor . My office is in the back side of the house so I sometimes don't know when a car pulls in let alone hear someone knocking at the door.

What it does is watch the system message log for the name of the monitor and alarm state, and executes a wav file when it matches any new entries.
I'm running ZM on Ubuntu 8.04.1 lts so this may need to be modified for different distro's .

First off I did all of this as root.
Put the .wav files you want to use in the ./ filesystem directory.
Create a new text document save it with a ( .sh ) extension check the permissions and enable it to be executable. Add the text below to the file sub out (signal ) for the name of the monitor you wish to use it on, and (ping).wav for the name of your wav file.

Code: Select all

#!/bin/bash 
tail -f /var/log/messages | grep --line-buffered 'signal.*Gone into alarm state' | while read line; do aplay /ping.wav; done
Make another .sh file with this code in it. This is run to kill the tail process ( if you have other Tail scripts running it will most likely kill those as well!

Code: Select all

#!/bin/bash
 pkill -9 tail
Now so I can get some sleep I setup cron to stop the tail at 9:30 PM and start at 6:30 AM

/etc/crontab
Mine looks like this with my added scripts at the bottom.

Code: Select all

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
30 21 * * * root /killalarm.sh
30 6 * * * root /zmalarm.sh
30 6 * * * root /zmalarm2.sh
#
I found some cool wav files while searching / my front door plays a dog barking.

Allan
Post Reply