Tuesday, June 9, 2009

Asterisk Installation and configuration

Hi,
I have installed and configured asterisk on centos 5.1. I am sharing it here. May be someone find it helpful and useful. I had to configure my server for running Value added services for local telco. I had to configure ISDN PRI's. The document contain links from where the asterisk tools and libraries can be downloaded (I uploaded themon different site because they can not be uploaded here) . So below are the steps which I followed:-


Install libpri:-
--------------------------------------------------------------------------------
1- Download libpri-1.4.9.tar.gz fromthe link http://www.ziddu.com/download/5112566/libpri-1.4.9.tar.gz.html
2- Move the file to usr-src
mv libpri-1.4.9.tar.gz to /usr/src

3- Unpack
tar -zxvf libpri-1.4.9.tar.gz

4- Install
cd libpri-1.4.9
make clean
make
make install

Install Zaptel :-
--------------------------------------------------------------------------------
1- Download zaptel-1.4.12.1.tar.gz from link http://www.ziddu.com/download/5112642/zaptel-1.4.12.1.tar.gz.html
2- Move zaptel-1.4.12.1.tar.gz to usr-src
mv zaptel-1.4.12.1.tar.gz to /usr/src

3- Unpack
tar -zxvf zaptel-1.4.12.1.tar.gz
cd zaptel-1.4.12.1

4- Verify pre-requisites
./install_prereq test


5- Prepare installation
./configure

6- Ensure required components are included
make menuselect
*** unselect all in firmware,
*** and select ztdummy in modules

7- Install
make clean
make
make install
make config

Install Asterisk:-
--------------------------------------------------------------------------------

1- Download asterisk-1.4.18.tar.gz from the link http://www.ziddu.com/download/5112614/asterisk-1.4.18.tar.gz.html
2- Move the file to usr-src
mv asterisk-1.4.18.tar.gz to /usr/src

3- Unpack
tar -zxvf asterisk-1.4.18.tar.gz
cd asterisk-1.4.18

4- Prepare installation
./configure

5- Ensure required components are included
make menuselect
*** select meetme in applications

6- Install
make
make install
make samples

7- Run
asterisk -vvvvc
*** press tab, to list available commands.
*** make sure 'zap' is available
*** run 'show applications', and make sure 'MeetMe' is listed

Asterisk Addons:- (I installed it for cdr logging into mysql db)
-------------------------------------------------------------------------
1- Download asterisk-addons-1.4.8.tar.gz from the link http://www.ziddu.com/download/5112658/asterisk-addons-1.4.8.tar.gz.html
2- copy asterisk-addons-1.4.8.tar.gz to /usr/src
mv asterisk-addons-1.4.8.tar.gz /usr/src
3- unzip and untar asterisk-addons-1.4.8.tar.gz
tar -xzvf asterisk-addons-1.4.8.tar.gz
cd asterisk-addons-1.4.8
4- Execute following commands 1 by 1
- For asterisk to log uniqueid to mysql cdr ,add the following line to the Makefile
CFLAGS+=-DMYSQL_LOGUNIQUEID
Also add the following to cdr/dr_addon_mysql.c
#define MYSQL_LOGUNIQUEID
5- Now run following commands
make clean
./configure
make
make install
make samples

6- To enable cdr logging in Mysql DB:-
- Login to mysql server
mysql -u username -p password
Execute following queries
-> CREATE DATABASE asterisk;
-> GRANT INSERT ON asterisk.* TO asterisk@localhost IDENTIFIED BY 'asterisk';
-> flush privileges;

-> USE asterisk;

-> CREATE TABLE `cdr` (
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`userfield` varchar(255) NOT NULL default ''
);

-> ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL DEFAULT '' AFTER `accountcode`;
-> ALTER TABLE `cdr` ADD INDEX ( `uniqueid` );
-> ALTER TABLE `cdr` ADD INDEX ( `calldate` );
-> ALTER TABLE `cdr` ADD INDEX ( `dst` );
-> ALTER TABLE `cdr` ADD INDEX ( `accountcode` );

7- cdr_mysql.conf should look like this:-
nano /etc/asterisk/cdr_mysql.conf
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=asterisk
user=asterisk
port=3306
sock=/var/lib/mysql/mysql.sock
userfield=1

8- Add following lines to cdr.conf
nano /etc/asterisk/cdr.conf
[mysql]
usegmtime=no ; log date/time in GMT. Default is "no"
loguniqueid=yes ; log uniqueid. Default is "no
loguserfield=yes ; log user field. Default is "no

Asterisk Perl:-
--------------------------------------------------------------------
1- Download asterisk-perl-0.10.tar.gz from the link http://www.ziddu.com/download/5112641/asterisk-perl-0.10.tar.gz.html
2- Move the file to usr-src
mv asterisk-perl-0.10.tar.gz to /usr/src

3- Unpack and unzip
tar -zxvf asterisk-perl-0.10.tar.gz
cd asterisk-perl-0.10

4- Install
perl Makefile.PL
make
make install

Wanpipe:- (I installed wanpipe for Sangoma A101)
--------------------------------------------------------------------------------
1- Download wanpipe-3.3.16.tgz from the link http://www.ziddu.com/download/5112671/wanpipe-3.3.16.tgz.html
2) move wanpipe-3.3.16.tgz to /usr/src
mv wanpipe-3.3.16.tgz /usr/src
3) unzip and untar
tar -xvf wanpipe-3.3.16.tgz
cd wanpipe-3.3.16
4) Execute following commands 1 by 1
shell> ./Setup install
Would you like to install WANPIPE now? [y] (y/n) y
Press [Enter] to continue... Enter
Would you like build wanpipe kernel drivers? [y] (y/n) y
Enter (for default)
Press [Enter] to continue...
Proceed to build WANPIPE kernel modules ? [y] (y/n) y
Please Select Compilation Mode ---- Please select (1,2,3,4,5,6 or 7) [Default: 1]: 2 for TDM Voice only
Please select working zaptel directory [1-1][m]: 1
Press [Enter] to continue... Enter
Would you like to add UDEV rules for Zaptel devices ? (y/n) y
Press [Enter] to continue... Enter
Press [Enter] to continue... Enter
Press [Enter] to continue... Enter
Press [Enter] to continue... Enter
Visually Confirm that driver compilation was successful! (y/n) y
Would you like to install WANPIPE start-up scripts? (y/n) y
Would you like to auto-execute ztcfg after wanrouter start? (y/n) y
Press [Enter] to continue... Enter
Please specify a desired location for WANPIPE configuration files. ---- Enter
Please specify a desired location for WANPIPE interface files. ---- Enter
Please specify a location for WANPIPE binary, firmware files. ---- Enter
WANPIPE UTILITIES SETUP ---- Press [Enter] to continue... Enter
WANPIPE Environment Setup Complete !!! ---- Press [Enter] to continue...
Installing WANPIPE Files ... ! ---- Press [Enter] to continue...
Would you like to configure wanpipe devices for ZAPTEL? (y/n) y
Would you like to generate /etc/asterisk/zapata.conf 1
Select media type for AFT-A101 on port A [slot:11 bus:1 span:1] 2 for E1
Configuring port A on 101 as E1, line coding:HDB3, framing:CRC4 ---- [1-2, ENTER='YES']: 1 for keep these settings
Select clock for AFT-A101 on port A [slot:11 bus:1 span:1] ---- [1-2]: 1 for NORMAL

Select signalling type for AFT-A101 on port A [slot:11 bus:1 span:1] --- [1-10]: 1 for PRI CPE
------------------------
1. PRI CPE
2. PRI NET
3. E & M
4. E & M Wink
5. FXS - Loop Start
6. FXS - Ground Start
7. FXS - Kewl Start
8. FX0 - Loop Start
9. FX0 - Ground Start
10. FX0 - Kewl Start
[1-10]: 1 for PRI CPE
------------------------

Select switchtype for AFT-A101 on port A ----- [1-7]: 5 for EuroISDN
-----------------------------------
1. National ISDN 2
2. Nortel DMS100
3. AT&T 4ESS
4. Lucent 5ESS
5. EuroISDN
6. Old National ISDN 1
7. Q.SIG
[1-7]: 5 for EuroISDN
-----------------------------------

Configuring port 1 on 101 as a full E1 ---- [1-2, ENTER='YES']: 1 for Use all channels
Select dialplan context for AFT-A101 on port A --- [1-3]: 3 for Custom
-- Input the context for this port: default
input the group for this port --- 1
Port A on AFT-A101 configuration complete... --- Press any key to continue: Enter
T1/E1 card configuration complete. --- Press any key to continue: Enter
Press any key to continue: --------- Enter
Zaptel and Wanpipe configuration complete: choose action --- [1-5]: 1 for Save cfg: Restart Asterisk & Wanpipe now

Would you like wanrouter to start on system boot? 1


=================================================

I hope you will find this document helpful.
Thanks

Monday, June 8, 2009

Nagios Asterisk channels plugin

I have downloaded the plugin check_ast_chan from internet. This plugin checks the total number of active calls on asterisk. When i ran it from command line , it worked but was not working from nagios server. Nagios server was not showing the channle count. So I modified it liitle and it is working now. The modified code is below:


#!/bin/bash

# Polls the asterisk server and returns active channel information


echo `/usr/sbin/asterisk -rx "show channels" | tail -3 | grep active | sed '$!N;s/\n/ /'` > /home/astchannels
rc=0
if [ "$?" -ne 0 ]
then
mesg="Error in Asterisk check"
rc=3
fi
cat /home/astchannels
exit $rc



This code works 100%. I have checked it with nagios-3.0.6, nagios-plugins-1.4.13, nrpe-2.12 on centos 5.1