agi script for trunk failure alert via email in freepbx

  Asterisk
1.go to agi dir  cd  /var/lib/asterisk/agi-bin
2.create a agi file  for eg:  alert.agi
3.copy the below script to the alert.agi
4.give permission  chmod 755 alert.agi
5.now go to freepbx => trunk=>select your trunk=>select enable for Monitor Trunk Failures:

script

#!/bin/bash

DATE=`date “+%d.%m.%Y. %H:%M”`
HOST=`hostname`
# initializing agi variables
declare -a array
while read -e ARG && [ “$ARG” ] ; do
array=(` echo $ARG | sed -e ‘s/://’`)
export ${array[0]}=${array[1]}
done

MESSAGE=”Incident happend $DATE.\n$agi_calleridname [$agi_callerid] tried to dial number $agi_dnid.\nCall could not be established on channel $agi_channel.”
# write log
echo “$DATE Call could not be established. $agi_calleridname [$agi_callerid] –> $agi_dnid” >> /var/log/asterisk/trunk
# send email
echo -e “$MESSAGE” | mail -s “PRI DOWN AT SYNERGY $HOST IP-PBX” yourname@gmail.com — -F “AsteriskPRIAlert”

note:  change the yourname@gmail.com with you emailid

LEAVE A COMMENT