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: https://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
Is this hosted on GitHub anywhere? I’ve been playing with it and have some changes that would be beneficial if anyone wanted them. Things like logging the ArmUp status of an area, a Redhat init.d sevice wrapper, and a bug fix when logging to zone_log.
If it’s not anywhere hosted, mind if I start a github repo for it?
@Jason:
It is on github! Been there for years. Right here: https://github.com/threadhead/elkm1–control
Karl
I meant your mysqlmonitor stuff =) I didn’t see that any of that had been added or referenced in the elkm1–control stuff
@Jason:
Sorry, here you go: https://github.com/threadhead/elk_monitor
LOVED this idea – I do not have the need to log things to a database but I do want this to goto a text file – I took sections of your perl script and modified it for my own needs – also added in handling of all elk messages (not in detail but just to know what the message type is) – figured this might help someone else or someone might be able to expand on this:
http://pastebin.com/zJNA8k9S
@Mike
Nice! Glad this could be of help.
@Karl – you seem to have the most “up to date” version of ElkM1::Control that I can find – do you know if anyone else has continued to expand on it? I am really interested in expanding it to support the entire Elk RS232 Protocol – however this is a serious undertaking and was hopeful that maybe someone else may have already done this? It seems like this perl module is the farthest anyone has ever gotten at fully communicating/automating with the Elk M1 – is that correct? Just curious if you or anyone else has found other options to talk to their Elk…
@Mike
I’m not very active in the Elk community any more, but I know the last time I googled-around I didn’t find much that was open source.
If anyone want to make changes or updates, everything is in GitHub. Just fork, modify, add some tests if possible, and send me a pull request.
To be honest, if I was going to rewrite this I would do it in something like Ruby or Python. Those languages are much more suited for metaprogramming.
@Karl – appreciate the info – thanks! One last question… do you know if its possible with the ElkM1::Control “API” to send a raw message to the Elk using the sendCommand function? If so, could you should a 1 or 2 line perl example of that? As a test I am currently trying to request the version number with “my $rq_ver = $elk->sendCommand(’06vn0056′);” but I am not sure if I am using that correctly or if that is even allowed… any advice on this is much appreciated!
@Karl – managed to figured it out – if I wanted to send ’06vn0056′ to the elk I would just write $elk->sendCommand(‘vn’); MessageFactory adds in the length, future zeros, and checksum value automatically. I figured I would share this in case anyone else runs into this problem.
Hi there folks – is anyone aware of a way to log all rules activation on the M1 Gold ( Newbie – no SQL/ Perl programming experience – just love playing in ELK RP etc) thx