I received a request a couple of days ago from someone who saw my posts on the Elk–Control perl library that I took over responsibility for. I had mentioned that I logged every Elk event into a MySQL database.
I am happy to report that I have this script running as a daemon, logging every ElkM1 event into my database. And it runs for months without issue.
I will keep these instructions brief. If you have detailed questions, please ask in the comments and I’ll help the best I can.
Download
You can download all the scirpts, just click here.
Notables
- If you don’t know a least a little perl and some MySQL basics, you may want to look elsewhere.
- The script and accompanying files are designed to work in concert as a daemonized process.
- Everything is logged into ‘elk_monitor.log’ in the same directory (or directory of your choosing) as the script. If you have a lot of passive infra-red motion detectors, you will want to monitor the log size.
Basic File Structure

elk_monitor.pl
This is the main script, it runs in a loop checking for new messages every second. You will need edit the %zonelist, %outputs, %areas near the top. Also, you will need to set some paths, look near the top of the file.
Required: ElkM1::Control, Log4perl
elk_monitor.sh
This is the shell script that controls elk_monitor.pl as a daemon. Setting up daemons can be complex as each system is different, so google around for some help.
elkm1.sql
A MySQL script to setup the tables and fields that the elk_monitor.pl script uses. You will need to add a database named ‘elkm1′. After that you can execute this script to create everything else for you.
lib/elkm1_db.pl
The database setting and basic sql commands are abstracted into this library. This is where you will need to set MySQL’s host, name, password, etc.
lib/file_tickler.pl
I use a custom ruby script to monitor the daemon. This library just touches a file every minute to let us know the elk_monitor.pl script is still running. Why? Well, I have had the script ‘freeze’ without exiting and most monitoring applications do not detect this. Obviously, this part is optional.
Conclusion
If you get all the settings right, she should run all day/week/month for you.
I and not a perl expert. Far from it. So I’m sure everything could use some tidying. If you do, please let me know and I’ll incorporate your changes.
Trying to get this running on a linux box (2.6.17-15mdv, arch=i686). Using perl 5.8.8.
Getting following error message:
Can’t call method “isOn” on an undefined value at ./elk_monitor.pl line 227, line 1.
Looks cool, hope you can help debug
@Tunaman:
I checked line 227 and there is no “isOn” on that line.
Are you sure this is what is giving you the error message?
Also, did you install the Elk-Control library first? You can find it here: http://blog.spoolz.com/2009/01/30/elk-m1-security-system-control-with-perl-script/
I have this question. It seems that the perl module is polling for events. If the event happens in between polling interval will it still be captured and logged in the database? For example, if someone quickly opens and closes the door. Thanks.
@Fa:
The Elk-M1 sends messages to the PC that is running the ElkM1::Control script. Your PC will buffer each message and ElkM1::Control simply reads the buffer. The polling is just reading the buffer every so often. You can adjust the polling rate in the perl script files, but I have not lost a single message in years of running the script.
Karl