Resource icon

FYI Trunk Failure Email Alerts 1.1

No permission to download

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
wardmundy submitted a new resource:

Trunk Failure Email Alerts - Get an email whenever a SIP, IAX, or Google Voice trunk fails on your server

Overview:

1. Download the tarball
2. Unzip it into /root
3. Insert your email notification address into trunkcheck.sh
4. Add entry to /etc/crontab to run trunkcheck.sh as often as you like
5. You'll get...

Read more about this resource...
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
Installed it a couple of days ago and got an email today about one of my trunks.

By the time I checked, it was OK but this is definitely a boon as in the past we have suffered from trunks going down and not knowing about them for a long time.

Thank you Ward.

For the uninitiated (like me) I will just run through the install steps in a bit more detail.

First, ignore the Download link in the top right hand corner - it is not necessary.

At a command prompt, paste in each line of the code shown in the Overview tab - one line at a time.

I use Putty to connect to the server and then use that (rather than the console) as it allows copy/pasting, which does not work in the console.

To paste, just right-click anywhere on the command window.

The "wget" line downloads the script.

The "nano" line opens the script in a text editor so you can change the 3rd text line in the script (starting "email=") to be your own email address.

Use the cursor keys to delete the dummy email address and then add in your own. Then press Ctrl-X to exit and reply Y(es) to save your changes.

If you prefer using your mouse, you can use File Manager in Webmin to edit the file "trunkcheck.sh" which is in "/root"

The last line creates a Cron job to schedule a run of the script every 5 minutes.

Change the 5 to whatever value you want before you press Enter, or use Webmin later to change the Cron job if you want.
 

LukeHandle

New Member
Joined
Dec 21, 2013
Messages
2
Reaction score
0
The last line creates a Cron job to schedule a run of the script every 5 minutes.

Change the 5 to whatever value you want before you press Enter, or use Webmin later to change the Cron job if you want.

*/5 * * * * would be every 5 minutes.
5 * * * * is only 5 mins past each hour.
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
Thanks for pointing that out.

I think that is rather a long time so I have changed it on my system to every 15 minutes.
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
Note: When I used Webmin to amend the cron job (using the Save button and not Clone) It created a duplicate job - I had to delete the old one. Strange.
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
I have been using this for many months and it has been working fine. Thank you again.

Recently after a particular problem with a trunk I realised that the script is only checking for failed registrations (incoming calls). However a failed Peer trunk (outgoing calls) is not detected.

Obviously it is more important to be aware of the loss of incoming calls but would it be possible to incorporate a check for all trunk failures?

I recently had an outgoing trunk out of commission for a while (showing UNREACHABLE on Asterisk Info > Peers) without realising it. Not a major disaster but potentially a costly one.
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
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
 

Jeffrey Schleider

New Member
Joined
Nov 26, 2015
Messages
5
Reaction score
0
wardmundy submitted a new resource:

Trunk Failure Email Alerts - Get an email whenever a SIP, IAX, or Google Voice trunk fails on your server



Read more about this resource...
Hi, I have read through the script and would like to undersatand why adding 'iptables-restart' after detecting a sip trunk failure would help getting it back up, as restarting the firewall (and fail2ban) does not get the trunk to try and re-register.
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
Hi, I have read through the script and would like to undersatand why adding 'iptables-restart' after detecting a sip trunk failure would help getting it back up, as restarting the firewall (and fail2ban) does not get the trunk to try and re-register.

That script includes a restart of Asterisk.
 

PhoneBug

New Member
Joined
Nov 29, 2011
Messages
7
Reaction score
0
I know this is rather old, but the link is no longer working. Is this available anywhere else?
 

Members online

No members online now.

Forum statistics

Threads
25,782
Messages
167,509
Members
19,203
Latest member
frapu
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top