QUESTION Monitor-Trunk-Failures option delays drop through to 2nd trunk.

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
I am trying to get a script working properly to report a failed trunk so I set all my trunks to call this script in the Monitor-Trunk-Failures option.

I then discovered that I was getting delays/failures when using the Trunk-Balance module to alternate calls between two trunk lines.

I tracked this to what looks like a 50 second or so delay whenever an outbound route has two trunks defined and the first trunk fails. The 2nd trunk does not take over immediately.

Disabling the Monitor-Trunk-Failures option removes the delay.

Further tests showed that it was the final line in the script, which was sending the notification email, that caused the delay. If that was commented out then there was no noticeable delay. I have not checked the logs but it seems obvious that the drop through to the next trunk does not happen till the script finishes and it is waiting for the email to be 'sent' before it ends.

So unless some better way to send an email is found it seems that the Monitor-Trunk-Failures option should never be used for Trunk-Balance trunks.

Its use on trunks used in outbound routes using multiple trunks is also suspect if frequent failures are expected.

The script being used can be found at <http://pbxinaflash.com/community/in...ert-on-trunk-failure.1968/page-3#post-100993>

Edit: The use of the Monitor-Trunk-Failures option with Trunk-Balance is anyway not possible as it triggers the script every time it sends the call to the 2nd trunk as it does that be 'failing' the first trunk.
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
I have now checked the logs and it clear from there that the script does not return till the email has actually been sent.

Code:
[2014-09-17 15:12:31] VERBOSE[1383] res_agi.c:    -- Launched AGI Script /var/lib/asterisk/agi-bin/trunk_monitor.agi
[2014-09-17 15:13:13] VERBOSE[1383] res_agi.c:    -- <SIP/210-00001c7e>AGI Script trunk_monitor.agi completed, returning 0

So it took 42 seconds for the script to run.

The line doing the emailing, and causing the delay is

Code:
echo -e "$MSG" | mail -s " VITELITY - Failed call on host [$HOST] - dialing [$DNID] - " "$EMAIL"
Is there some other way to send an email that will allow it to be sent asynchronously and not hold up the script?
 

CoinTos

Member
Joined
Jan 5, 2012
Messages
34
Reaction score
7
Code:
echo -e "$MSG" | mail -s " VITELITY - Failed call on host [$HOST] - dialing [$DNID] - " "$EMAIL"
Is there some other way to send an email that will allow it to be sent asynchronously and not hold up the script?

Well, my shell scripting is real rusty so they might be completely wrong but if I remember correctly putting an & on the end causes to run in "background" and should let the script continue.

Code:
echo -e "$MSG" | mail -s " VITELITY - Failed call on host [$HOST] - dialing [$DNID] - " "$EMAIL" &
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
Tried that but it made no difference.

Need some WD40 on the rust!

Actually, after some Googling, the & at the end of the line is a documented option for asynchronous running of 'shell scripts'.

I have seen reference to using it but there is a warning I have seen that if it is used within a script (assuming it works) and the script ends then the child processes are also killed.
 

CoinTos

Member
Joined
Jan 5, 2012
Messages
34
Reaction score
7
Tried that but it made no difference.

Need some WD40 on the rust!

Actually, after some Googling, the & at the end of the line is a documented option for asynchronous running of 'shell scripts'.

I have seen reference to using it but there is a warning I have seen that if it is used within a script (assuming it works) and the script ends then the child processes are also killed.

Ok then disown or nohup it then.

Code:
echo -e "$MSG" | mail -s " VITELITY - Failed call on host [$HOST] - dialing [$DNID] - " "$EMAIL" &
disown -h
 
or
 
(echo -e "$MSG" | mail -s " VITELITY - Failed call on host [$HOST] - dialing [$DNID] - " "$EMAIL" &) | nohup

Refernece:
Disown / Nohup
 

LesD

Member
Joined
Nov 8, 2009
Messages
408
Reaction score
15
WD40 worked first time!

Using your 2nd example there is now zero delay and the email still arrives.

I do not understand your first example. From your reference I understand that 'disown' kills processes, so I do not see its relevance here. Or does "Purpose: Remove jobs from the table of active job." mean something else?

Anyway, thank you very much for the fix. I will pass it on to the other thread.
 

CoinTos

Member
Joined
Jan 5, 2012
Messages
34
Reaction score
7
To explain the first example. I had to edit the post 20mins after posting as I forgot the -h switch. Here's the man quote for the reason for the switch.
By default, removes each JOBSPEC argument from the table of active jobs. If the -h option is given, the job is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all jobs from the job table; the -r option means to remove only running jobs.
 
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