#!/bin/sh ################################################################################ # This is a script which should take the string received from # # the alarm receiver application, give it a unique id and insert it # # into a MySQL table. # # # # Once the data is entered, it should call a second script with the # # unique id of this alarm. That script will then determine what to # # do about the alarm. # ################################################################################ ################################################################################ # Set some Global Variables # The MySQL command we'll use. mysql='/usr/bin/mysql -h hostname -u username -pPaSSw0rD ' # We'll log a bunch of stuff we do logfile='/var/log/alarmreceiver.log' ################################################################################ # Asterisk will create a file for each event it receives # The location where this file is written is defined in # /etc/asterisk/alarmreceiver.conf # We are going to do the next step on each file # that Asterisk has created. We could do this for only one file # by commenting out the next line and un-commenting out # the following line. for almfile in `ls -t /var/tmp/alarm ` #for almfile in `ls -t /var/tmp/alarm | head -1` do file="/var/tmp/alarm/$almfile" # Define the current time now=`date +%Y%m%d%H%M%S` # Create a unique ID for this alarm transaction uniqid=`echo $now-$RANDOM` # Grab the callerid number from the file CALLINGFROM=`grep CALLINGFROM $file | cut -f2 -d=` # Grap the callerid name from the file # I think this is broke, so I'll have to look at it later CALLERNAME=`grep CALLERNAME $file | cut -f2 -d=` # Grab the timestamp from the file. This is the time that Asterisk # received the alarm transaction TIMESTAMP=`grep TIMESTAMP $file | cut -f2 -d=` # Grab the actual alarm transaction from the file EVENT=`grep ^[0-9] $file ` # Make sure the log file exists touch $logfile echo "file = $file" # Split the fields into the Ademco/SIA ContactID fields ACCT=`echo $EVENT | cut -b1-4` MT=`echo $EVENT | cut -b5-6` Q=`echo $EVENT | cut -b7` XYZ=`echo $EVENT | cut -b8-10` GG=`echo $EVENT | cut -b11-12` CCC=`echo $EVENT | cut -b13-15` S=`echo $EVENT | cut -b16` ################################################################################ # Start Logging ################################################################################ echo "================================================================================" >> $logfile echo " Alarm Notification received at `date`" >> $logfile echo "================================================================================" >> $logfile echo Alarm String was $EVENT >> $logfile echo Account Number $ACCT >> $logfile echo Message Type $MT >> $logfile echo Event Qualifier $Q >> $logfile echo Event Code $XYZ >> $logfile echo Group $GG >> $logfile echo Zone $CCC >> $logfile echo Checksum $S >> $logfile echo "" >> $logfile ################################################################################ # Load the data into the database $mysql -vv -e "insert into alarms (alarmstring,acct,mt,q,event,gg,zone,cksm,received,uniqueid,callingfrom,callername) values ('$EVENT','$ACCT','$MT','$Q','$XYZ','$GG','$CCC','$S',NOW(),'$uniqid',$CALLINGFROM,'$CALLERNAME')" alarmreceiver >> $logfile echo "Our uniqid = $uniqid" >> $logfile # We have now logged this event to the log file and we have inserted # the data into a database. T ################################################################################ # Call external program with the unique ID we identified earlier /usr/local/bin/getalarm $uniqid # Optionall, you could pass the data directly to an external program to do something. # The following examples will display various elements of the alarm event on # the tv using the Tivo and Tivoweb. #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=++++++++++++++++++++++++++++++++++&fg=127&bg=13&delay=9&y=1" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Incoming+Alarm+Call++++++++++++++&fg=127&bg=13&delay=9&y=2" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Account Number: $ACCT+++++++++++++&fg=127&bg=13&delay=9&y=3" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Message Type: $MT+++++++++++++++++&fg=127&bg=13&delay=9&y=4" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Event Qualifier: $Q+++++++++++++++&fg=127&bg=13&delay=9&y=5" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Event Code: $XYZ++++++++++++++++++&fg=127&bg=13&delay=9&y=6" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Group: $GG++++++++++++++++++++++++&fg=127&bg=13&delay=9&y=7" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Zone: $CCC++++++++++++++++++++++++&fg=127&bg=13&delay=9&y=8" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=+Checksum: $S++++++++++++++++++++++&fg=127&bg=13&delay=9&y=9" #wget -q -O /dev/null "http://tivo.shaneyoung.com/displaytext?text=++++++++++++++++++++++++++++++++++&fg=127&bg=13&delay=9&y=10" # Take the file that Asterisk created and move it to a backup location # Some other process should be in place to archive these. mv $file /var/spool/alarms done