Your requirement

You have an entry in sip.conf that you can use to make phone calls via the Internet, for example, [1und1]. You want to check in the dial plan (extensions.conf) whether Asterisk can reach the SIP server online, that is, whether Internet access exists and the SIP server is available. If so, you want to dial out via SIP, if not, alternatively via ISDN.

The procedure

Test with ping

If (with the known IP does not respond to ping, the number is dialed in the [ISDNout] context (the application System jumps +101 if the shell command was not successful).

exten => _0.,1,System('ping -w 1 -c 1 > /dev/null')
exten => _0.,2,Dial(SIP/${EXTEN}@1und1,,Tr)
exten => _0.,102,Goto(ISDNout,${EXTEN},1)

The -w 1 -q -c 1 options make ping wait for only one second and send only one ping.

By the way: local calls

With VoIP you need the area code even for local calls. The following line automatically puts the area code in front of all numbers that do not start with a 0:

/etc/asterisk/extensions.conf:exten => _N.,1,Goto(SIPout,089${EXTEN},1)

Linux knowledge

These articles were written by the founder of Checkmk many years ago.
They are still valid though and thus we keep them on our website.
Mathias has since then developed a monitoring software called Checkmk

Find out more