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 :
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.
Asterisk security thread
Few days ago, the FBI send a confusing alert about asterisk and security.
Here is more information about the clarification
On Monday, the Federal Bureau of Investigation (FBI) issued an updated notice regarding the use of Digium’s Asterisk IP PBX for vishing. Now, if they could get the date of posting (Dec.
to match the date listed within the notice (Dec. 5), we might actually have a “case closed.”
http://www.fiercevoip.com/story/fbi-clarifies-digium-asterisk-ip-pbx-vishing-bolo/2008-12-09
Make your dialplan readable using priority labels
When you start asterisk or run ‘reload’ or ‘extensions reload’ from asterisk cli, the asterisk process will parse your /etc/asterisk/extensions.conf file and build a list of extensions with priorities starting with 1.
You can give any priority a name and make your extension file easy to write, read and modify.
Here is the syntax for each extension priority
exten => <extension_number>,<priority_number>(<label_name>),<application>(<application_data>)
You can then use the label number into a Goto application instead of an explicit priority number. You can then change your priority number, the label name will be the same and you don’t have to change all Goto places that point to that priority.
Example
exten => 5140000000,1,Noop(New caller from ${CALLERID(all)})
exten => 5140000000,n(playwelcome),Background(welcome-message)
exten => t,1,Noop(User didn’t enter anything… Retry…)
exten => t,n,Goto(5140000000,playwelcome)
In this specific example, the user is asked to enter an extension number. If you don’t enter anything
and reach the t (timeout) extension, we transfer again to extension 5140000000 at priority labelled playwelcome.
Asterisk dialplan : random naviguation
Sometimes, you want your callers to go randomly to a place.
For example, you have 5 extensions and you want inbound calls to be send randomly to those extensions.
You may want a equal distribution or distribution based on a certain probability.
Another case where this can be usefull is if you have multiple carriers and want to send your outbound calls randomly to them.
To do so, you can use the asterisk RAND function.
[Syntax]
RAND([min][|max])[Synopsis]
Choose a random number in a range[Description]
Choose a random number between min and max. Min defaults to 0, if not
specified, while max defaults to RAND_MAX (2147483647 on many systems).
Example: Set(junky=${RAND(1|8)});
Sets junky to a random number between 1 and 8, inclusive.
Action
In the following example, we receive a call to DID number 5140000000 and want to send 60% to SIP extension 2200 and the rest to extension 3300. The dialplan the looks like
exten => 5140000000,1,Noop(New call received from ${CALLERID(all)})
exten => 5140000000,n,GotoIf($[${RAND(1,100)} > 40]?labelagt1)
exten => 5140000000,n(labelagt2),Dial(SIP/3300)
exten => 5140000000,n,Hangup
exten => 5140000000,n(labelagt1),Dial(SIP/2200)
exten => 5140000000,n,Hangup
So, basicly, when we receive the call, we generate a random number between 0 and 100.
If that number is more than 40 (should happen 60% of the time), we go to priority with label ‘labelagt1′ and we dial SIP/2200.
If not (should happen 40% of the time), we go the next priority and dial SIP/3300.