Write your own asterisk application

Maybe you want to do something that does not exist on asterisk or you want to write your own asterisk applicaiton.

if so, you may read this sample provide in asterisk source code under apps/app_skel.c

Basicly, what you need to know, is at startup, asterisk will load your application by running the load_module function. That function will register your new application with it’s name and execute function (app_exec in this case). When that application will be call from the dialplan for example, app_exec will be execute.

You can see the code here

http://svn.digium.com/svn/asterisk/trunk/apps/app_skel.c

“sip show peers” for asterisk realtime

You may have notice that even if your sip peers is connected, when you run sip show peers, no see nobody.

To see it, just enable in sip.conf (section general)

rtcachefriends=yes

asterisk 1.4 vs 1.6 (PBX Core)

On our weekly topic, we will today discuss what is the difference between asterisk 1.4 and 1.6 and what you should be aware of if you want to upgrade.

So, if you need to upgrade from 1.4 to 1.6, int the pbx core :

* The ‘languageprefix’ option in asterisk.conf is now deprecated, and
the default sound file layout for non-English sounds is the ‘new
style’ layout introduced in Asterisk 1.4 (and used by the automatic
sound file installer in the Makefile).

* The ast_expr2 stuff has been modified to handle floating-point numbers.
Numbers of the format D.D are now acceptable input for the expr parser,
Where D is a string of base-10 digits. All math is now done in “long double”,
if it is available on your compiler/architecture. This was half-way between
a bug-fix (because the MATH func returns fp by default), and an enhancement.
Also, for those counting on, or needing, integer operations, a series of
‘functions’ were also added to the expr language, to allow several styles
of rounding/truncation, along with a set of common floating point operations,
like sin, cos, tan, log, pow, etc. The ability to call external functions
like CDR(), etc. was also added, without having to use the ${…} notation.

* The delimiter passed to applications has been changed to the comma (’,'), as
that is what people are used to using within extensions.conf.  If you are
using realtime extensions, you will need to translate your existing dialplan
to use this separator.  To use a literal comma, you need merely to escape it
with a backslash (’\').  Another possible side effect is that you may need to
remove the obscene level of backslashing that was necessary for the dialplan
to work correctly in 1.4 and previous versions.  This should make writing
dialplans less painful in the future, albeit with the pain of a one-time
conversion.  If you would like to avoid this conversion immediately, set
pbx_realtime=1.4 in the [compat] section of asterisk.conf.  After
transitioning, set pbx_realtime=1.6 in the same section.

* For the same purpose as above, you may set res_agi=1.4 in the [compat]
section of asterisk.conf to continue to use the ‘|’ delimiter in the EXEC
arguments of AGI applications.  After converting to use the ‘,’ delimiter,
change this option to res_agi=1.6.

* The logger.conf option ‘rotatetimestamp’ has been deprecated in favor of
‘rotatestrategy’.  This new option supports a ‘rotate’ strategy that more
closely mimics the system logger in terms of file rotation.

* The concise versions of various CLI commands are now deprecated. We recommend
using the manager interface (AMI) for application integration with Asterisk.

asterisk billing : Insert account code in call detail records (CDR)

So, in asterisk, you already have your CDR in a file or in a database.

Now, you have customers with different customer id or account code and you want to have a way to know which call belong to which customer.

You can set a channel CDR account field. At the end of the call,  when the cdr will be post in your file or database, the accountcode field will be fill.

To do so, call the following in your dialplan or agi script

exten => 1,n,Set(CDR(accountcode)=XXXXX)

Where XXXXX  should be replace by the customer account code.

You can then join that information to the one you already have in your client table or crm

Agi : check channel status

When using an agi, you may run into situations where neither AGI or DeadAGI command fills your needs.

You may want to continue running your scripts no matter what happened.

At the same time, you may also want to check the channel status to know if the user already hanged up and take decisions based on the channel status then.

You can run the agi command :

Usage: CHANNEL STATUS [<channelname>]
If channelname is not provide, you will get the current channel status.
Here are the returns :
failure: 200 result=-1
success: 200 result=<status>

<status> values:
0 Channel is down and available
1 Channel is down, but reserved
2 Channel is off hook
3 Digits (or equivalent) have been dialed
4 Line is ringing
5 Remote end is ringing
6 Line is up
7 Line is busy

Customize asterisk with “make menuselect”

Since asterisk 1.4.0, a new build system autoconf was implemented.

After running ./configure, you can run “menu makeselect”, to select your modules and

check customize your build options.

Protect asterisk again hackers (fail2ban)

If your asterisk box has a public interface or you receive Ip call from the outside world,

you will have to make sure that an unautorized user does reach your pbx and tries to make calls.

To do so, of course, you should start making sure that your sip.conf or iax.conf file has strong password and policies.

You can also use fail2ban. This process will parse any log file, detect IP addresses that failed to connect to a specific services (asterisk, ssh, ftp etc…). After a certain number of failure, fail2ban will automaticly add that adresss in your firewall and block the user for the next ‘x’ minutes.

Here is how you can configure fail2ban to protect your asterisk box.

http://www.voip-info.org/wiki/view/Fail2Ban+(with+iptables)+And+Asterisk

Quick install asterisk on Ubuntu

Check this excellent wiki on how to install asterisk on ubuntu from the sources.

http://www.voip-info.org/tiki-index.php?page=Asterisk+Linux+Ubuntu

Asterisk : share variable between multiple channels [ImportVar]

Some times, you can have multiple live channels running on your asterisk dialplan

and you want to, in the channel 1 thread, read another channel variable.

You can use asterisk ImportVar application.

[Description]
ImportVar(newvar=channelname|variable): This application imports a variable
from the specified channel (as opposed to the current one) and stores it as
a variable in the current channel (the channel that is calling this
application). Variables created by this application have the same inheritance
properties as those created with the Set application. See the documentation for
Set for more information.

Generate very unique asterisk tracknumber

This asterisk trick can be usefull if you have multiple asterisk servers getting calls and sending them on the same database or on the same log file.

In some rare cases, when you have a lot of calls, you can find your self with two different calls on two servers with the same unique id or tracknumber.

You can set asterisk to prepend a string to the unique id.

To do so :

vi /etc/asterisk/asterisk.conf

[directories]

….

[options]

systemname = mypbx1; prefix uniqueid with a system name for global uniqueness issues

Then reload and see what you have in ${UNIQUEID} field of your channels and in you CDR files.

← Previous PageNext Page →