Trunk Monitoring


#1

I have been running a php script via cron for many years (PIAF forum) to alert me when a trunk is not registered.

One of the trunks (from Voipfone in UK) occasionally fails and the only way to get it back is to disable the trunk for 2+ minutes and then enable it again.

I want to modify the script to disable the trunk, sleep for 130 seconds and then enable it again.

I would like to avoid hard-coding the exact IDs as these may change.

As far as I know I need to use “fwconsole trunks --disable x” to temporarily disable the trunk but for that I need to know the value of x for the trunk that has failed.

asterisk -rx “sip show registry” shows the Host which includes the name Voipfone but then I need a way to determine the trunk ID.

In short, I need to determine which Trunk ID has failed to register.

Any guidance most welcome.


#2

This is usually caused by a ‘poisoned’ NAT association in the router or firewall that is being kept alive by aggressive retries by Asterisk.

If you have a static IP address and Voipfone supports ‘IP authentication’, set that up and don’t use registration at all. That’s most robust and you can still use qualify to detect trunk outages.

Next, if your router/firewall has separate UDP timeouts for ‘unreplied’ and ‘assured’ states, set the unreplied timeout shorter than the retry interval and recovery should be automatic.

Otherwise, assuming a reasonably updated system (FreePBX 15, Asterisk 16), switch to pjsip trunks. Set all three Retry Intervals to e.g. 180 seconds.

If you must use chan_sip, set registertimeout to 180 and registerattempts to 0 (see https://www.voip-info.org/asterisk-config-sipconf/ )

If none of the above are applicable or don’t help, please provide some details: Router/firewall make/model? Does it have a public IP on WAN interface? If not, why (ISP supplied gateway, ISP does NAT, etc.)? FreePBX and Asterisk versions? Why do you have / how do you use multiple trunks with the same provider?

IMO you should implement a recovery script only if you understand what is wrong when registration stays lost and why changing router/firewall or Asterisk timing parameters can’t fix it.


#3

Thank you for your prompt and detailed response. Your diagnosis of the problem is spot on.

I have spoken in the past to Voipfone and they did ‘blame’ Asterisk for the issue - too many retries.

(They did suggest using IP authentication but we have a backup line so did not want to go down that route).

I did look for some settings that would make Asterisk back-off from retries for two minutes but did not find any. So your suggestion to use pjsip with its extra options is the obvious thing to try. I have never used it for trunks, but will give it a go now.

Thank you again.


(Lorne Gaetz) #4
 fwconsole trunks --list

will provide the ID. If coding you will prob want to use it as

fwconsole trunks --list --json

#5

I have created the pjsip trunk. I cannot find any up to date meaningful guidance in the wiki. I found a couple contradictory ones from some providers but it actually looked quite simple to set up.

The trunk is showing as registered. I have disabled the old sip trunk and tried an incoming call. It goes straight to voicemail at the trunk provider. So I am a bit stuck. Have I forgotten something?

In the Advanced section I changed some of the default numbers and set Contact User and From User to same as Username and From Server to Sip Server and left all else unchanged.


#6

Thank you Lorne.

Listing the trunks gives the ID number and the Channel ID (name of the trunk).

“sip show registry” shows Host (domain/IP + port) and Username.

There is nothing in common between the two to allow me to obtain the trunk’s ID from the registry list. This leaves me with the only option of hard-coding the script to a specific Host entry - unless there is something else that can link the two.

Hopefully @Stewart1’s suggestion of using pjsip will work, in which case there is no need for the script.


#7

Your NAT association may be timing out – try setting Expiration to e.g. 120 and retest. If it still fails:

If something appears in the Asterisk log for an attempted incoming call, post that.

If not, but something appears in sngrep on an attempt, post that.

If also nothing in sngrep, at the Asterisk command prompt, type
pjsip set logger on
and wait for the next registration. Paste the section of the Asterisk log showing both a REGISTER request and the 200 OK response at pastebin.freepbx.org and post the link here.


#8

Yet there is a one to one relation ship between trunks and sip show peers the absence of OK for the peer would show a problem and allow you to fwconsole trunks --disable=badone for 130 seconds


#9

I did see an old post of yours making this suggestion and I tried it. I have changed a character in the password so it fails to register - registries shows No authentication.

Despite that ‘sip show peers’ shows Status as: OK (96 ms)

Does not make sense but I have tried several times.


#10

waig a few for a call. . .


#11

Did you get the pjsip trunk working? If not, what have you found so far?

Alternatively, for the chan_sip trunk, have you tried changing Registration Timeout to 180 and Registration Attempts to 0 in Asterisk SIP Settings-> SIP Legacy Settings?


#12

Last night I sent an email to Voipfone. They responded with a query - apparently not actually changed anything. However, trying it out again this morning - it is all working on pjsip!

Many thanks to you all.


#13

Noun
waig

  1. small stream; brook; creek :grinning:

#14

That sounds like what I was looking for and assumed it would be an attribute of the trunk. I do have an other system still running an old version before pjsip. I will definitely try it there. Thank you.


#15

I do have a general question on setting up a pjsip trunk. The wiki is not really helpful on this subject (as well as being out of date).

I found a page here from Zadarma where they populate the fields on the pjsip Advanced tab.

After some testing I have found that the trunk seems to work fine even without filling in the fields that are initially blank.

Is this the correct thing to?

(Some of the field’s help text explicitly say that the field can be left blank and default values will be assumed but others do not).


#16

Writing to confirm that your suggestion seems to have worked. I got a single warning email and then the trunk got registered without any manual intervention. Thanks again.


(system) closed #17

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