#!/bin/bash # trunkwatch.agi v2.1 2022 - noelb@ausics.net # agi script for trunk failure alert via email in freepbx # Before you enact this AGI, set your EMAIL for whomever gets the alerts. # I'll use trunkwatch.agi as the file name for use in monitoring trunk errors # edit as /var/lib/asterisk/agi-bin/trunkwatch.agi and chmod 755 # Lastly in freepbx=> trunk=> select your trunk=> select enable for Monitor Trunk Failures, and enter trunkwatch.agi ##################################################################################################################### EMAIL="foo@emample.com" DATE=`date "+%d.%m.%Y. %H:%M"` HOST=`hostname` declare -a array while read -e ARG && [ "$ARG" ] ; do array=(` echo $ARG | sed -e 's/://'`) export ${array[0]}=${array[1]} done MESSAGE="Trunk Alert $DATE.\n$agi_calleridname [$agi_callerid] tried to dial $agi_dnid.\nThe call could not be established on channel $agi_channel." echo "$DATE Call could not be established. $agi_calleridname [$agi_callerid] --> $agi_dnid" >> /var/log/asterisk/trunk echo -e "$MESSAGE" | mail -s "Trunk Down $HOST IP-PBX" $EMAIL