Friday, July 13, 2007

SIPp

SIPp is a free Open Source test tool / traffic generator for the SIP protocol.
http://sipp.sourceforge.net/

Run:
sipp -sn type -d duration(sec) -s test number SIP Server -l calls -i Local IP
sipp -sn uac -d 30000 -s 500 192.168.10.229 -l 5 -i 192.168.10.5

Building Apache + PHP4

Apache2:
./configure --enable-module=so
make
make install

PHP:
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pgsql --with-mysql --with-zlib --enable-calendar
make
make install

Set up environment and apache:
cp php.ini-dist /usr/local/lib/php.ini
cd /usr/local/apache2/conf
vi httpd.conf

add:
AddType application/x-httpd-php .php

Unique ID in asterisk & mySQL

Storing the Unique ID

Q: It would appear that the "uniqueid" field is not being populated in the MySQL CDR DB. Is this an obsolete field or is a bug?

A: You need to define MYSQL_LOGUNIQUEID at compile time for it to use that field.

You have two options in /usr/src/asterisk-addons:
1. Add CFLAGS+=-DMYSQL_LOGUNIQUEID to the Makefile.
2. Add a #define MYSQL_LOGUNIQUEID to the top of cdr_addon_mysql.c.

Finally perform the usual make clean, make, make install. Be sure to check the Makefile for the presence of this flag after having done a CVS update! You will most probably also want to index the uniqueid field in your cdr table to improve performance.

You will also have to add a `uniqueid` column in your mysql database after the `accountcode` column:
ALTER TABLE `cdr` ADD `uniqueid` VARCHAR(32) NOT NULL default '' after `accountcode`;

What would I need all this for? For example you are running an AGI script and would like to be able to related AGI data with the CDR table. The problem is that the AGI script will lose connection to the call as soon as the caller hangs up, so you'll need a way to find the correct cdr entry (that'll also be created only after the call has been completed).

Wednesday, July 11, 2007

Asterisk + MySQL

http://www.voip-info.org/wiki-Asterisk+cdr+mysql

Asterisk can store CDR records in a MySQL database, as an alternative to CSV text files and other database formats.

Due to Mysql client libraries licensing, the Mysql billing application is no longer an integrated part of the Asterisk standard distribution. It is now located in the asterisk-addons CVS directory.

You must have mysql and mysql-devel packages installed.

Compile

# cd asterisk-addons-1.2
# make clean
# make
# make install


A sample configuration file, can be found on the cdr_mysql.conf page.

Copy the sample configuration file to /etc/asterisk/cdr_mysql.conf and edit it according to your requirements. Then edit your modules.conf to load cdr_addon_mysql.so and finally restart asterisk; before the restart you should, however, check that your cdr table has been created correctly and is accessible to the username and password you specified.

Table definitions for Asterisk cdr_mysql

Create the database
mysql --user=root --password=password -h dbhost

CREATE DATABASE asterisk;

GRANT INSERT
ON asterisk.*
TO asterisk@localhost
IDENTIFIED BY 'yourpassword';

(Remote MySQL server permissions)
GRANT INSERT
ON asterisk.*
TO asterisk@localhost
IDENTIFIED BY 'yourpassword';

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 INDEX ( `calldate` );
ALTER TABLE `cdr` ADD INDEX ( `dst` );
ALTER TABLE `cdr` ADD INDEX ( `accountcode` );


/etc/asterisk/cdr_mysql.conf
[global]
hostname=192.168.10.5
dbname=asterisk
table=cdr
password=asterisk
user=asterisk
port=3306
sock=/var/lib/mysql/mysql.sock
;userfield=1

/etc/asterisk/modules.conf
load => cdr_addon_mysql.so
[global]