Knowledge Base

Checking registered SIP peers

We got a call recently from a customer who uses skype trunks for some international incoming numbers. We have found that these lose registration on a regular basis, We could let them be set try and register indefinitely but this can have performance effects on the server.

This is not our only customer with this problem, We have also of late noticed a similar problem with Voip-unlimited where registration times out every day at 8pm, we have noted this on ours and other dealers servers.

So what to do?

Well we have written a quick script to check registration details and reload if not correct.


HITS=`asterisk -r -x “sip show registry” | grep Registered |grep $1| wc -l`

if [ $HITS != $2 ]; then

echo “Incorrect number of $1 trunks are registered, we wanted $2  ”

echo “We will now reload asterisk ”

asterisk -r -x “reload”

exit 0


echo “$HITS $1 trunks are registered, we wanted $2  ALL OK”

exit 0



the syntax for running the script is hostname 2

with hostname being part of the string you get when doing a sip show registry.

and the number is the number of registered trunks you expect with that name.

if all is well:”2 sipgate trunks are registered, we wanted 2 :-) ALL OK”and nothing happens

if not correct number then:

“Incorrect number of sipgate trunks are registered, we wanted 2

“We will now reload asterisk”

we only relaod the sip channel driver as this is enough to sort the problem normally

Knowledge Base Technical

Nagios plugin for reading the Asterisk Database

This is a simple plugin that is based on one by Jason Rivers We have changed it now to read the ASTDB (Asterisk internal Database and then based on ok and Critical keys it will report OK or Critical staus reports to Nagios.

This was written for reporting if an Elastix system is in Day or Night mode.

You can define the Database Family, Key, Critical value and OK value. This means you can cutomise it to what ever you need to report.


The Code is below, make you may need to change /usr/bin/nc for what ever you use for netcat.

any issues email us, but dont forget this is given for free not supported for free.

# Program : check_asterisk_ami
# :
# Author : Original code by Jason Rivers < >
# : Modified by for checking the asterisk Database
# :
# Purpose : Nagios plugin to return Information from an Asterisk host using AMI
# :
# Parameters : --help
# : --version
# :
# Returns : Standard Nagios status_* codes as defined in
# :
# Licence : GPL
# Notes : See --help for details
PROGNAME=`basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\/][^\/][^\/]*$,,'`
REVISION=`echo '$Revision: $' | sed -e 's/[^0-9.]//g'`
print_usage() {
echo "Usage: $PROGNAME [-H hostname] [-u username] [-p password] [-P port] [-k DBkey] [-c critical] [-o ok] [-f family]"
echo " -H Hostname"
echo " -u AMI Username"
echo " -p AMI Password"
echo " -P (optional) AMI PORT"
echo " -k Database key"
echo " -f Database family"
echo " -c Critical Key"
echo " -o OK KEY"
echo ""
echo "SupportedCommands:"
echo " Most DB familiys that toggle such as DayNight in elastix"
echo "Usage: $PROGNAME --help"
echo "Usage: $PROGNAME --version"
print_help() {
print_revision $PROGNAME $REVISION
echo ""
echo "Nagios Plugin to check Asterisk ASTDB using AMI"
echo ""
echo ""
echo "Asterisk Call Status Check. orignal version by © Jason Rivers 2011 changes to do ASTDB by"
echo ""
exit 0
# support
# If we have arguments, process them.
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
case "$1" in
exit $STATE_OK
exit $STATE_OK
print_revision $PROGNAME $REVISION
exit $STATE_OK
print_revision $PROGNAME $REVISION
exit $STATE_OK
-u) AMIUSER=$2;
-p) AMIPASS=$2;
echo "Unknown argument: $1"
if [ "${AMIPORT}" = "" ]; then
if [ "${FAMIL}" = "" ]; then
echo="CRITICAL: Unknown KEY"
## Checking Astdb
CHANNELS=`/bin/echo -e "Action: login Username: ${AMIUSER} Secret: ${AMIPASS} Events: off Action: DBGet Family: ${FAMIL} Key: ${DBKEY} Action: Logoff " | /usr/bin/nc $REMOTEHOST ${AMIPORT} | awk '/Val/ {print $2}'|tr -d " "`
if [ "$CHANNELS" = "" ]; then
echo "UNKNOWN: Unable to get ASTDB status"
if [ "$CHANNELS" = "${OKNAME}" ]; then
MSG="OK: ${DBKEY} Asterisk Emergency message not active"
elif [ "$CHANNELS" = "" ]; then
MSG="WARNING: Asterisk Unknown status"
elif [ "$CHANNELS" = "$CRITICALNAME" ]; then
MSG="CRITICAL: ${DBKEY} Asterisk Emergency message active"
echo $MSG
exit $exitstatus

Knowledge Base Technical

Installing Webdav on Centos with untrusted ssl certificates

Webdav (Web-based Distributed Authoring and Versioning) is a set of methods based on the Hypertext Transfer Protocol (HTTP) that facilitates collaboration between users in editing and managing documents and files stored on World Wide Web servers.This can be useful to allow backing up of data between servers. In Linux there is a command line client called cadaver that in theory allows you to script its use.

This isnt as staight forward as it could have been and we spent half a day and a lot of Googling to get to the bottom of common problems, Such as auto loging in, Untrusted ssl certificates and scripting.

So here is a simple run down on what you have to do to script with webdav and cadaver

Install cadaver

yum install cadaver

once installed you will need to install the certificate for the untrusted ssl site

for example
wget http://website/
now convert this to a .pem file
openssl x509 -inform der -in -out

now add this to your cert.pem file.

in centos this seems to be in the  /usr/share/ssl/ directory
cat >> /usr/share/ssl/cert.pem

you now need to edit the ./netrc file with the server and logon details
vi ~/.netrc

login   user
password        secret

save the file.

now when you connect you wont be promted for accepting the certificate or a username and password

cadaver -et

Ok now we want to script the actions.
This is as simple as creating a script file.

for example

vi ~/.cadavscript

will give the following output

cadaver -et < ~/.cadavscript
dav:/> Listing collection `/’: succeeded.
test.txt                              35  Aug 19 15:04
dav:/> Current collection is `’.
dav:/> Connection to `’ closed.

So create a script to do what you want and your done

Knowledge Base

Asterisk Music on Hold

Music on hold is always an issue, We get asked many times “can we put such and such mp3 on as hold music” Well the answer is always the same, Yes and no.

Yes in that we can convert any mp3 to be played as MOH as long as you have the relevent PRS licence.

So the answer is then normaly No we wont do it then, Just look at the costs detailed here and you will see why.

So why are we mentioning it here.

Well Asterisk has Music files loaded for MOH and it was always assumed these were licenced correctly and required no additional licence or agreement. Well it seems that some countries are challenging this.

See the following from Digium..

Open Source Asterisk has had for quite some time the ability to play Music On Hold (MOH) to callers as an optionally configured call feature.  Of course, as soon as the code had the ability to play music, there was a general request and obvious concept that Asterisk should include a few default music-on-hold files.  At that point, several people within Digium looked around at the possible files we could use, but all of them had some type of license issues, which is understandable.  We found a company which sold rights to music, and we discussed in specific, painstaking detail what we wanted to do with the files and how they were going to be used.  They agreed that we could do what we wanted and distribute the files with Asterisk and that they were able to provide to us the appropriate license, so we paid our fee and proceeded to pick some likely music.  We then included them in Asterisk in the hopes that the community would find them useful as part of the system without having to search out selections which complied with various copyright issues.  This was a good-faith gesture on our part, and we had a quite reasonable expectation that the vendor from whom we purchased the license was authorized to provide to us a global right-to-use and redistribution capability to the Asterisk community for these sound files.

Apparently, that assumption is now being questioned.  In some nations (Australia and France, to pick two that have been brought to our attention) there are some who are claiming that we do not have the rights outlined above, and that our users therefore are in a similar situation where they may be in violation of license terms.

In the interests of space here I will not outline the exact organizations, laws, and claims in question.  Suffice it to say they are complex and unclear with a broad range of possible interpretations. Currently, at least two organizations disagree that we are complying with a set of license terms.  This is very far outside of Digium’s ability or interest to manage, nor do we wish to become involved in the protracted series of legal proceedings required to sort out this licensing issue.  So we have chosen another path that is more clear to us: we will eliminate the files of questionable license from Asterisk, and replace them with music that has  clearly defined and more acceptable licensing terms which are compatible with both the Asterisk license, and with any reasonable redistribution methods that might be used by others who re-package Asterisk.

So how can we be assured this won’t happen again?  The new music we’ve included is under the Creative Commons 2.5 license – which quite frankly didn’t have much of a following for media back when we first were looking for a set of MOH files.  Certainly, the selection of good-quality music files that would suffice did not exist in an easy-to-obtain fashion, or we would have gone this route in the first place.  Hopefully you’ll like the new music on hold, and will be customers of the artists who have so graciously given their work out under such a reasonable license.   We found the new music on Opsound for those of you who are looking for an even wider selection of freely available music.

We apologize for putting people through this aggravation – we sincerely wish that the recording industry would standardize license terms and avoid treating customers like enemies.  Perhaps there is a silver lining here –  this may be a good opportunity for you to freshen up your hold music – maybe “Calm River” was getting under people’s skin after the thousandth time you put them on hold.

The Gory Tech Details:

The new files can be found here:

The new files have names that contain “opsound” replacing the term “freeplay” in the file names.  It’s really that simple.  We’ve removed the old “freeplay” files and symlinked the old names to the new “opsound” versions, just in case.  The contents of the .tar archives are different, but Asterisk should “just work” when the file contents are put in place unless you’ve extensively modified your music on hold configurations.

If you have an existing Asterisk system it is our suggestion that you delete any and all copies of the existing “freeplay” music on hold set on your system(s) and replace them with the new “opsound” module sets.  The good news is that this is very simple – very little configuration is required on your system – just a simple file copy and then restart Asterisk to see the new files.

What happens if you don’t update your music on hold?  The state of the FreePlay license currently is in question, and even if it is determined that the Freeplay files were not provided under the necessary license terms,  it’s unlikely that enforcement actions will be brought against end-users for using unlicensed hold music.  However, we would encourage all administrators to update their instances of Asterisk to the new sound files.  This is really a distasteful process for all of us, and in order to protect ourselves from any future liability we’re going to suggest that everyone remove the older files entirely.

Knowledge Base

General Configuration Guide Skype for SIP and Asterisk


If you are new to SIP, Asterisk is a useful, open-source (GPL) platform with which to test and experiment with the Skype for SIP. This is a guide on how to install Skype for SIP on a system agnostic or “vanilla” Asterisk server.


To install Asterisk on your server, please see the Digium documentation here


This configuration guide is based on Debian Linux (Lenny 64bit). With a basic installation of Debian you can install Asterisk by issuing the following APT command at the command line:-

apt-get install asterisk



Configuration Files for Vanilla Asterisk


In configuring Skype for SIP on a vanilla Asterisk system we are primarily concerned with two configuration files:-


  1. sip.conf (located in the /etc/asterisk/ directory)
    The sip.conf file holds the registration details for the Skype for SIP channel
  2. extensions.conf (located in the /etc/asterisk/ directory)The extensions.conf holds the dial plan telling Asterisk what to do with incoming and outgoing calls.-


Let’s do a walkthrough of the configuration steps.


Configuring the sip.conf File


Step 1


The sip.conf file has two sections that need to be completed. The “General” section (denoted in the file with the [general] heading) and peer section denoted in the file with the [peers] heading.


In the General section we need to add a “register” line. This tells Asterisk to register with Skype at the Skype local point of presence.


Add the following, under the “[general]” section in the file, substituting your 9905xxxx number and password with your actual credentials for the Skype for SIP profile you wish to use. Your SIP Profile details can be found in the Skype Business Control Panel (BCP):-


register => 99051000xxxxxx: /99051000xxxxxx


Step 2

To ensure that we also receive the callerID from Skype clients we also should add:-


trustrpid = no

sendrpid = yes



Step 3

Next, we add a section for the peer, in the “[peers]” section of the sip.conf file. Again we substitute the 9905xxxxx number and password with the SIP Profile credentials from the Skype Business Control Panel (BCP):-



type = peer

username = 99051000xxxxxx

fromdomain =

fromuser = 99051000xxxxxx

realm =

host =

dtmfmode = rfc2833

secret = PaSsW0rD

nat = no ;This should be set to reflect your network NAT configuration

canreinvite = no

insecure = invite

qualify = yes

disallow = all

allow = alaw

allow = ulaw

;allow = g729 ; Uncomment this if you have G729 licences

amaflags = default

trustrpid = no

sendrpid = yes

context = skype_in


Please Note:

If your Asterisk PBX is behind a NAT device, you should set “nat = yes” in this section.


If your Asterisk PBX has a dedicated internet IP address, set this to “nat = no”.


Step 4

After setting these changes, reload the Asterisk’s SIP module by typing:-


asterisk -rx “reload”


…….at the command line.


Step 5

After the SIP Module has reloaded enter asterisk -rx “sip show peers” at the command line, which should return:


pbx*CLI> sip show peers

Name/username Host Dyn Nat ACL Port Status

99051000xxxxxx/99051000xx 5060 OK (52 ms)


Then enter asterisk -rx sip show registry” which should return:


pbx*CLI> sip show registry

Host Username Refresh State Reg.Time 99051000xxxx 105 Registered day, dd mmm yyyy hh:mm:ss


If you see output similar to the above, then you are registered to the Skype SIP gateway and ready to make and receive calls.


We now need to setup the extensions.conf so that we have a dialplan setup and Asterisk knows how to deal with incoming and outgoing calls.


Configuring the extensions.conf File


The extensions.conf file requires a “context” and an “extension” to be added for incoming Skype calls, plus an extension to be added to the context that users use for outgoing calls.


Incoming “context”


Add the following lines to the [context] section of extensions.conf, substituting 9905xxxxxxx with the 9905 number for the SIP Profile. Again you can find the details of your Skype SIP Profiles in the Skype BCP:-



exten => 99051xxxxxxxx,Noop(${CALLERID(name)} , ${CALLERID(num)})

exten => 99051xxxxxxxx,n,Dial(SIP/100,30,t,r)

exten => 99051xxxxxxxx,n,voicemail(100|u)


This is a simple “vanilla” context that shows us the callerID name and number, dials extension 100 for 30 seconds and finally, if unanswered, goes to voicemail. This sequence will need to be amended to suit your requirements. If you are planning on having many SIP Profiles or Online Numbers that all need to end up at the same destination, or the destination is decided by the Skype Business Account that the online number is registered against, a more complicated Dialplan can be used. For example:-



exten => 99051xxxxxxxx,1,Noop(${CALLERID(name)} , ${CALLERID(num)})

exten => 99051xxxxxxxx,n,Queue(sfs|r|||40)

exten => 99051xxxxxxxx,n,voicemail(100|u)



Outgoing “Context”


The outgoing context must be included in the context for your user’s phones. Usual security measures apply. Do not include this in a context for incoming calls.




exten => _90Z.,1,Set(CALLERID(num)= 99051xxxxxxxx)

exten => _90Z.,n,Dial(SIP/0044${EXTEN:2}@99051xxxxxxxx)


exten => _900.,1,Set(CALLERID(num)= 99051xxxxxxxx)

exten => _900.,n,Dial(SIP/${EXTEN:1}@99051xxxxxxxx)



In the sip.conf add the following to create user 100





callerid=”myskypetrunk” <100>

















in the extensiosn.conf add the following to the default context


exten => _XXX,1,Dial(SIP/${EXTEN},20)


Also create a context called international



include => default

include => skype_out