Asterisk: логируем cel и cdr в mysql через odbc

Автор | 18.08.2014

Устанавливаем недостающие пакеты unixODBC

apt-get install unixODBC unixODBC-dev libmyodbc

Настройки ODBC:

cat /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage = 1
cat /etc/odbc.ini
[asterisk-connector]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = ast
Server = localhost
UserName = user
Password = pass
Port = 3306

Настраиваем подключение Asterisk к odbc драйверу
cat /etc/asterisk/res_odbc.conf

[ast13]
enabled => yes
dsn => asterisk-connector
username => user
password => pass
pre-connect => yes

Указываем какое подключение использовать для логирования CDR

cat cdr_adaptive_odbc.conf
[mysql_connection]
connection=ast13
table=cdr

и соответственно CEL

cat cel_odbc.conf
[ast13]
connection=ast13
table=cel

Создаем таблицы в которые будут писаться логи звонков

CREATE TABLE cdr (
    accountcode VARCHAR(20),
    src VARCHAR(80),
    dst VARCHAR(80),
    dcontext VARCHAR(80),
    clid VARCHAR(80),
    channel VARCHAR(80),
    dstchannel VARCHAR(80),
    lastapp VARCHAR(80),
    lastdata VARCHAR(80),
    start DATETIME,
    answer DATETIME,
    end DATETIME,
    duration INTEGER,
    billsec INTEGER,
    disposition VARCHAR(45),
    amaflags VARCHAR(45),
    userfield VARCHAR(256),
    uniqueid VARCHAR(150),
    linkedid VARCHAR(150),
    peeraccount VARCHAR(20),
    sequence INTEGER
);


CREATE TABLE IF NOT EXISTS `cel` (
`id` int(11) NOT NULL auto_increment,
`eventtype` varchar(30) NOT NULL,
`eventtime` datetime NOT NULL,
`cid_name` varchar(80) NOT NULL,
`cid_num` varchar(80) NOT NULL,
`cid_ani` varchar(80) NOT NULL,
`cid_rdnis` varchar(80) NOT NULL,
`cid_dnid` varchar(80) NOT NULL,
`exten` varchar(80) NOT NULL,
`context` varchar(80) NOT NULL,
`channame` varchar(80) NOT NULL,
`src` varchar(80) NOT NULL,
`dst` varchar(80) NOT NULL,
`channel` varchar(80) NOT NULL,
`dstchannel` varchar(80) NOT NULL,
`appname` varchar(80) NOT NULL,
`appdata` varchar(80) NOT NULL,
`amaflags` int(11) NOT NULL,
`accountcode` varchar(20) NOT NULL,
`uniqueid` varchar(32) NOT NULL,
`linkedid` varchar(32) NOT NULL,
`peer` varchar(80) NOT NULL,
`userdeftype` varchar(255) NOT NULL,
`eventextra` varchar(255) NOT NULL,
`userfield` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `uniqueid_index` (`uniqueid`),
KEY `linkedid_index` (`linkedid`)
);

Залишити відповідь