I have tried the above and it is sort of working.
Recap:
The script at the moment stands as follows:
Code:
#!/bin/bash
declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done
[email protected]
DATE=`date "+%m-%d-%Y %H:%M"`
HOST=`PIAF-DA`
CID=`echo $agi_callerid`
CIDNAME=`echo $agi_calleridname`
EXTENSION=`echo $agi_extension`
CHANNEL=`echo $agi_channel`
REPORT=$EXTENSION
if [ "$EXTENSION" = "s-CHANUNAVAIL" ]
then
REPORT="Channel Unavailable"
fi
# Message Formating
MSG="\n\n A call from channel [$CHANNEL] \n"
MSG="$MSG With CID : [$CIDNAME] - [$CID] \n\n"
MSG="$MSG has failed on host [$HOST] at $DATE \n\n"
MSG="$MSG with error : [$REPORT] \n\n"
# log
echo >> /var/log/asterisk/trunkfailure.log
echo -e "$MSG" >> /var/log/asterisk/trunkfailure.log
# Send an email
echo -e "$MSG" | mail -s " - Failed call on host [$HOST] -" "$EMAIL"
I installed that in </var/lib/asterisk/agi-bin> as <trunk_monitor.agi> and I set '
Monitor Trunk Failures' in the trunk to just the name of the file.
I also had to do:
Code:
chmod +x /var/log/asterisk/trunkfailure.log
chown asterisk:asterisk /var/log/asterisk/trunkfailure.log
before it would work.
I failed the trunk by changing the secret and tried a call and immediately got an email
Code:
Subject: - Failed call on host [] -
A call from channel [SIP/210-00001750]
With CID : [unknown] - [0208802yyyy]
has failed on host [] at 09-14-2014 02:39
with error : [continue]
So it is sort of working but the information coming through is not very useful. I would like to address the following shortcomings.
1. The HOST ID is not coming through. I would anyway have preferred the script to determine and report the machine's hostname or something similar to automatically identify the system from which it originates.
2. The CID being reported is that of my outgoing trunk but it does not uniquely identify which of several trunks it is - they all have the same CID. I really need the name of the trunk.
3. It would also be useful to see the number being called.
4. The reported error is wrong.
5. I need to be able to differentiate between the trunk failing and a call failing due to an invalid number. At the moment both are resulting in an email.
The log shows the following when the trunk fails to authenticate
Code:
[2014-09-14 13:23:50] VERBOSE[6486] app_dial.c: -- Called SIP/BestVoip/0044208802xxxx
[2014-09-14 13:23:51] WARNING[6458] chan_sip.c: Received response: "Forbidden" from '"0208802xxxx" <sip:[email protected]>;tag=as718056c8'
[2014-09-14 13:23:51] VERBOSE[6486] app_dial.c: == Everyone is busy/congested at this time (1:0/0/1)
[2014-09-14 13:23:51] VERBOSE[6486] pbx.c: -- Executing [s@macro-dialout-trunk:23] NoOp("SIP/210-0000178a", "Dial failed for some reason with DIALSTATUS = CHANUNAVAIL and HANGUPCAUSE = 21") in new stack
[2014-09-14 13:23:51] VERBOSE[6486] pbx.c: -- Executing [s@macro-dialout-trunk:24] GotoIf("SIP/210-0000178a", "1?continue,1:s-CHANUNAVAIL,1") in new stack
[2014-09-14 13:23:51] VERBOSE[6486] pbx.c: -- Goto (macro-dialout-trunk,continue,1)
[2014-09-14 13:23:51] VERBOSE[6486] pbx.c: -- Executing [continue@macro-dialout-trunk:1] GotoIf("SIP/210-0000178a", "0?noreport") in new stack
[2014-09-14 13:23:51] VERBOSE[6486] pbx.c: -- Executing [continue@macro-dialout-trunk:2] AGI("SIP/210-0000178a", "trunk_monitor.agi") in new stack
[2014-09-14 13:23:51] VERBOSE[6486] res_agi.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/trunk_monitor.agi
For an invalid number, the log shows
Code:
[2014-09-14 13:08:20] VERBOSE[5380] app_dial.c: -- Called SIP/BestVoip/00442000000000
[2014-09-14 13:08:21] VERBOSE[5380] app_dial.c: -- SIP/BestVoip-00001778 is making progress passing it to SIP/210-00001777
[2014-09-14 13:08:32] VERBOSE[6458] chan_sip.c: -- Got SIP response 480 "Temporarily not available" back from 77.72.174.129:5060
[2014-09-14 13:08:32] VERBOSE[5380] app_dial.c: -- SIP/BestVoip-00001778 is circuit-busy
[2014-09-14 13:08:32] VERBOSE[5380] app_dial.c: == Everyone is busy/congested at this time (1:0/1/0)
[2014-09-14 13:08:32] VERBOSE[5380] pbx.c: -- Executing [s@macro-dialout-trunk:23] NoOp("SIP/210-00001777", "Dial failed for some reason with DIALSTATUS = CONGESTION and HANGUPCAUSE = 19") in new stack
[2014-09-14 13:08:32] VERBOSE[5380] pbx.c: -- Executing [s@macro-dialout-trunk:24] GotoIf("SIP/210-00001777", "1?continue,1:s-CONGESTION,1") in new stack
[2014-09-14 13:08:32] VERBOSE[5380] pbx.c: -- Goto (macro-dialout-trunk,continue,1)
[2014-09-14 13:08:32] VERBOSE[5380] pbx.c: -- Executing [continue@macro-dialout-trunk:1] GotoIf("SIP/210-00001777", "0?noreport") in new stack
[2014-09-14 13:08:32] VERBOSE[5380] pbx.c: -- Executing [continue@macro-dialout-trunk:2] AGI("SIP/210-00001777", "trunk_monitor.agi") in new stack
[2014-09-14 13:08:32] VERBOSE[5380] res_agi.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/trunk_monitor.agi