#!/bin/sh ################################################################################ # Set some Global Variables # The MySQL command we'll use. mysql='/usr/bin/mysql -h hostname -u username -pPaSSw0rD ' # The unique ID that was passed to us uniqueid=$1 # This is a badly formated SQL query, we should be selecting just the fields we want, even if we # want all of them. If we re-ordered the fields in the database, this would get messed up. alarm=`$mysql -B --skip-column-names -e "select * from alarms where uniqueid ='$uniqueid'" alarmreceiver | tr '\t' '|'` # Take the data we got back from the SQL query and split it into individual # fields to be used later: alarmstring=`echo $alarm | cut -f1 -d\|` acct=`echo $alarm | cut -f2 -d\|` mt=`echo $alarm | cut -f3 -d\|` q=`echo $alarm | cut -f4 -d\|` event=`echo $alarm | cut -f5 -d\|` gg=`echo $alarm | cut -f6 -d\|` zone=`echo $alarm | cut -f7 -d\|` cksm=`echo $alarm | cut -f8 -d\|` received=`echo $alarm | cut -f9 -d\|` uniqueid=`echo $alarm | cut -f10 -d\|` callingfrom=`echo $alarm | cut -f11 -d\|` callername=`echo $alarm | cut -f12 -d\|` # Now, figure out what we should do with the alarm that we just received # We have a database table which has commands for various alarm types # # This is the Best Match, we have everything # (Account, Group, Qualifier, Event and Zone) # command=`$mysql -B --skip-column-names -e "select command from actions where acct = $acct and gg = $gg and qualifier = $q and event = $event and zone = $zone " alarmreceiver` if [ "$command" = "" ] then echo "No Best match found" > /dev/null else echo "Command is $command" $command $uniqueid & exit 0 fi # This is the next best match, we don't look for the zone. # (Account, Group, Qualifier, Event) # command=`$mysql -B --skip-column-names -e "select command from actions where acct = $acct and gg = $gg and qualifier = $q and event = $event and zone is NULL " alarmreceiver` if [ "$command" = "" ] then echo "No 2nd Best Match" > /dev/null else echo "Command is $command" $command $uniqueid & exit 0 fi # user type stuff # account,NULL,q,event,NULL command=`$mysql -B --skip-column-names -e "select command from actions where acct = $acct and gg is NULL and qualifier = $q and event = $event and zone is NULL " alarmreceiver` if [ "$command" = "" ] then echo "No 3rd Best Match" > /dev/null else echo "Command is $command" $command $uniqueid & exit 0 fi # This is the last guess. We look for a command with # No Zone and No Event type. This is the default for account,group,qualifier # account,NULL,q,NULL,NULL command=`$mysql -B --skip-column-names -e "select command from actions where acct = $acct and gg is NULL and qualifier = $q and event is NULL and zone is NULL " alarmreceiver` if [ "$command" = "" ] then echo "No 4rd Best Match" > /dev/null else echo "Final Try" echo "Command is $command" $command $uniqueid & exit 0 fi #$command $uniqueid