Asterisk time based routing

Here is an example of routing calls over time in Asterisk.
Assume that the /etc/asterisk/extensions.conf file has a configured context for the trunk with the following parameters:

[Trunk_2]
exten => s,1,DIAL(SIP/6004&SIP/6003,19)
exten => s,2,Hangup()

And to resolve the time calls to different phones, we will point out for the context of this trunk only nested contexts:

[Trunk_2]
include => daytime,8:00-18:00,mon-sat,*,*
include => nighttime,18:00-8:00,mon-sun,*,*
include => sunday,8:00-22:00,sun,*,*

In fact, daytime, nighttime, sunday are only the names of contexts for which the time is written in the context of [Trunk_2], they can be called anything.

And then in these separate contexts we will already add the necessary extensions.
That is, in the afternoon:

[daytime]
exten => s,1,DIAL(SIP/6004&SIP/6003,19)
exten => s,2,Hangup()

At night:

[nighttime]
exten => s,1,DIAL(SIP/6002,19)
exten => s,2,Hangup()

And on Sunday:

[sunday]
exten => s,1,DIAL(SIP/6002,19)
exten => s,2,Hangup()

You can also, for example, create a holiday context with holidays:

include => holiday,*,*,1,jan
include => holiday,*,*,8,mar

etc.

For those who want to paint more in detail by day, I’ll give you a list of days in English:
mon – Monday
tue – Tuesday
wed – Wednesday
thu – Thursday
fri – Friday
sat – Saturday
sun – Sunday

Similarly, up to three letters and names of months are shortened.

Configuring Automatic Calls in Asterisk

Asterisk can automatically make a call if you put a .call file in the (default) /var/spool/asterisk/outgoing/ directory. If the date of the file change is greater than the current one, the call will be made on or after this time.

For automatic calls, the pbx_spool.so module must be loaded, it must be registered in modules.conf or autoload=yes must be specified.

Continue reading “Configuring Automatic Calls in Asterisk”

Asterisk warning “leave_voicemail: No more messages possible”

I noticed the following error on one of the servers:

WARNING[21992][C-00000b27]: app_voicemail.c:6559 leave_voicemail: No more messages possible

It turned out that the mailbox was full of voice messages and they ceased to exist, in response the caller was informed “The subscriber’s voice box is full”.

To solve this problem there are several options:

1) Delete the messages in the voice mailbox by calling the voice mail number.

2) Increase the value of maxmsg in the voicemail.conf file, thereby increasing the maximum number of messages in the mailbox, but again it may be full. After the changes in the voicemail.conf file, you need to apply them:

sudo asterisk -rvv
voicemail reload
quit

3) In the context of the voice mailbox, add delete=yes, for example:

[voicemailcontext]
207 => 1111,Username,test@example.com,,attach=yes|tz=ua|delete=yes

In this case, voice messages will be sent to e-mail, and they will be immediately deleted from the server, that is, they can not be listened to by calling to the voice mail number and accordingly the mailbox will never be full. I consider this option the best.

See also:
Setting up voicemail in Asterisk

Adding SIP clients to Asterisk

SIP clients in Asterisk are specified in the sip.conf file, so open it for example in the nano text editor (Ctrl+X to exit the editor, y or n to save or discard changes):

sudo nano /etc/asterisk/sip.conf

First we specify the following parameter, forbidding anonymous calls:

allowguest=no

Now at the very end of the file, add the client:

[6000]
type=friend
secret=PASSWORD
nat=no
host=dynamic
dtmfmode=rfc2833
disallow=all
allow=ulaw
context=sip-dialout
callerid=6000
deny=0.0.0.0/0
permit=192.168.0.10/32

Briefly describe the parameters that I indicated:
type – type of client, can be user (authentication by password), peer (identification by host address), fried (either by password or by host).
secret – user password.
nat=no – indicates that the client may be behind NAT, see my article about this – Solution to the Asterisk problem – no sound when calling via NAT.
host=dynamic – there is no client binding to the host address.
dtmfmode=rfc2833 – method of transmitting dtmf dialing tones.
disallow=all – ban all codecs.
allow=ulaw – Let’s solve only the ulaw codec.
context=sip-dialout — the name of the dialplan (it is described in extensions.conf)
callerid=6000 – customer’s internal phone number.
deny=0.0.0.0/0 – we forbid connection from all IP addresses.
permit=192.168.0.10/32 – we only allow connection from the specified IP address.

After adding the client, we will connect to Asterisk and update the sip configuration:

sudo asterisk -r
sip reload

To see the list of clients you can use the command:

sip show users

To exit the Asterisk console, type:

quit

Now it is already possible to connect the added client to the Asterisk server using for example the X-Lite, Zoiper or VoIP phone program, but there is nowhere to call, so we will add the second client to sip.conf for the test:

[6001]
type=friend
secret=PASSWORD
nat=no
host=dynamic 
dtmfmode=rfc2833
disallow=all
allow=ulaw
context=sip-dialout
callerid=6001
deny=0.0.0.0/0
permit=192.168.0.10/32

Open the extensions.conf file in the editor:

sudo nano /etc/asterisk/extensions.conf

And we will indicate the following lines at the end of it, so that users can call each other:

[sip-dialout]
exten => 6000,1,Dial(SIP/6000)
exten => 6001,1,Dial(SIP/6001)

Restart Asterisk to apply the changes:

sudo service asterisk restart

Done, we added two users and they can call each other.

See also:
Adding a SIP client to FreePBX

Adding a SIP client to FreePBX

To add a SIP client to FreePBX, open the menu “Applications” – “Extensions“, choose for example “Generic CHAN SIP Device” and we indicate the main parameters:

User Extension: 6000 (SIP number)
Display Name: Operator (any name to display)
Secret: PASSWORD
and click “Submit“.

Done, SIP is added, it can already be registered at the specified number and password.

How to add SIP in the configuration file I described in this article – Adding SIP clients to Asterisk

Installing the Digium Asterisk GUI

Digium Asterisk GUI – web-management interface Asterisk.

Today I’ll sculpt it to Asterisk 11 on Ubuntu Server 14.04 LTS.
Switch directly to the root user:

sudo -i

Download it:

apt-get install subversion
mkdir -p ~/asterisk-gui
cd ~/asterisk-gui
svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0/

We compile and install:

cd 2.0
./configure
make
make install

Just in case, we’ll make a copy of the Asterisk configuration files:

cp -r /etc/asterisk /etc/asterisk.original

Open the configuration file manager.conf for example in the editor nano (Ctrl+X to exit the editor, y/n to save or cancel changes):

nano /etc/asterisk/manager.conf

The main parameters that must be configured in the manager.conf configuration file are:

[general]
enabled = yes
webenabled = yes
bindaddr = 0.0.0.0
[USERNAME]
secret = PASSWORD
read = system,call,log,verbose,command,agent,user,config
write = system,call,log,verbose,command,agent,user,config

At the very end of the file, replace the symbol # with; otherwise you can not enter under the login and password specified above.

Now edit http.conf:

nano /etc/asterisk/http.conf

In it we will specify the following parameters of the web server:

enabled=yes
enablestatic=yes
bindaddr=0.0.0.0
prefix=asterisk

Let’s check the settings:

make checkconfig

Delete the empty folder and specify a link to the real one with the files of the web server:

rmdir /usr/share/asterisk/static-http/
ln -s /var/lib/asterisk/static-http/ /usr/share/asterisk/

Restarting Asterisk:

/etc/init.d/asterisk restart

Now Digium Asterisk GUI should open by link http://192.168.56.102:8088/asterisk/static/config/index.html, where 192.168.56.102 this is the IP or Server domain with Asterisk.

To log in, we’ll specify the username and password you wrote earlier in the manager.conf file

Done.

Solution to the Asterisk problem – no sound when calling via NAT

I noticed recently that there is no sound when calling from IP-phone to another IP-phone which were both behind the same NAT (router).

Therefore, in the sip.conf configuration for these accounts, you need to specify that they are behind NAT, specifying the parameter:

nat=force_rport,comedia

I want to note that the value of “yes” for nat is already obsolete since version Asterisk 11, so it will be correct as mentioned above.

And also point at no to the directmedia parameter, so that Asterisk does not send packets to the same port from which it was received (which in my case happened, both phones connected to Asterisk from the same IP, with the same ports):

directmedia=no

Done.

Asterisk Error Solution “Context ‘local’ tries to include nonexistent context ‘parkedcalls'”

I screwed the DAHDI board somehow and noticed the following error when I dialed the call from the analog line:

WARNING[7238]: pbx.c:12314 ast_context_verify_includes: Context ‘local’ tries to include nonexistent context ‘parkedcalls’

The error occurred because the res_parking module was not loaded to load it, open the asterisk console and execute the command:

sudo asterisk -vvr
module load res_parking

To automatically load it when starting Asterisk, in the file /etc/asterisk/modules.conf, in the [modules] block, add the line:

load => res_parking.so