Get trunk name on Monitor Trunk Failure callback

Hello,
I’m using Monitor Trunk Failure the detect when one trunk doesn’t work properly. On Edit Trunk section I set Monitor Trunk Failure to Yes and put the filename in the box test.agi.
Then I create this file under /var/lib/asterisk/agi-bin, set asterisk as owner and add execution privileges.
The file has the following code (that I paste from somewhere):

declare -a array
while read -e ARG && [ "$ARG" ] ; do
array=(` echo $ARG | sed -e 's/://'`)
export ${array[0]}=${array[1]}
done

EMAIL=you@your.domain

DATE=`date "+%m-%d-%Y %H:%M"`

HOST=`hostname`

CID=`echo $agi_callerid`
CIDNAME=`echo $agi_calleridname`
EXTENSION=`echo $agi_extension`
CHANNEL=`echo $agi_channel`
CONTEXT=`echo $agi_context`

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 For CONTEXT : $CONTEXT \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/trunkfailuretest.log
echo -e "$MSG" >> /var/log/asterisk/trunkfailuretest.log

# Send an email

echo -e "$MSG" | mail -s " - Failed call on host [$HOST] -" "$EMAIL"

I can see properly the message, what I need now is to get the name of the trunk that fail…how can I do?

Thanks

Paolo

I dont know that script, looks like you use the DIALSTATUS variale to evaluate your calls using that trunk, If you explain really with details what you want I can give you some advices how to write your on script using php or python I dont use batch, also this like might help

Thanks for your reply.
The aim is to intercept whenever a trunk fails (maybe the CID is blocked or we are doing too many calls at second). Automatically goes to backup trunks, but I need to know the one who failed (so I can contact the provider or do checks).
I see that the code above works but it doesn’t return me the name of the trunk who failed.
Do you suggest to do something different? For me python or php is the same.

If you need other infos please tell me.

Thanks

Paolo

Asterisk doesn’t have trunks, but what you probably mean by a trunk forms part of the channel name, and can also be found using functions to obtain the SIP peer.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.