Asterisk – храним CDR в БД MySQL

Должны быть установлены следующие компоненты:

— Mysql Server 5 and Client
— asterisk-1.4.22
— asterisk-addons-1.4.7

#Скачиваем Asterisk-addons с Digium:

 

1
2
3
4
5
6
cd /usr/src
wget <a title="http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.4.7.tar.gz" href="http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.4.7.tar.gz">http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.4.7....</a>
tar xvfz asterisk-addons-1.4.7.tar.gz
cd asterisk-addons-1.4.7/cdr/
vi cdr_addon_mysql.c
add #define MYSQL_LOGUNIQUEID after #define DATE_FORMAT “%Y-%m-%d  %T”

 

1
2
3
cd ..
./configure
make menuselect

Проверяем, загружен ли модуль:

1
2
3
4
5
6
7
8
9
10
11
—> 1. Applications
[*] 1. app_addon_sql_mysql
2. Call Detail Recording
[*] 1. cdr_addon_mysql
3. Channel Drivers
4. Format Interpreters
5. Resource Mod
then q (quit) and S (save)
make && make install

Редактируем файл /etc/asterisk/cdr.conf

1
2
3
4
vi /etc/asterisk/cdr.conf
[general]
enable=yes

Редактируем файл /etc/asterisk/cdr_mysql.conf

1
2
3
4
5
6
7
8
9
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=pass01234
user=asterisk
port=3306
;sock=/tmp/mysql.sock
;userfield=1

Редактируем файл /etc/asterisk/modules.conf

1
vi /etc/asterisk/modules.conf

добавляем следующие строки (если нет):

1
load => cdr_addon_mysql.so

Создаем БД, таблицы и разрешения.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ipbbx01:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.0.32-Debian_7etch5 Debian etch distribution
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> create database asterisk;
mysql> use asterisk;
mysql> 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 ”,
uniqueid varchar(32) NOT NULL default ”
);
ALTER TABLE cdr ADD INDEX ( calldate );
ALTER TABLE cdr ADD INDEX ( dst );
ALTER TABLE cdr ADD INDEX ( uniqueid );
You can add more indices if you want.
mysql> q
[/mysql]
Не забываем дать разрешения пользователю asterisk@localhost для  работы с БД MySQL:
[mysql]
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> on asterisk.*
-> to 'asterisk'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Проверяем соединение:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
ipbx01:~# mysql -h localhost -u asterisk -p asteriskmysql> show tables;
+——————–+
| Tables_in_asterisk |
+——————–+
| cdr |
+——————–+
1 row in set (0.00 sec)
mysql> desc cdr;
+————-+————–+——+—–+———————+——-+
| Field | Type | Null | Key | Default | Extra |
+————-+————–+——+—–+———————+——-+
| calldate | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| clid | varchar(80) | NO | | | |
| src | varchar(80) | NO | | | |
| dst | varchar(80) | NO | MUL | | |
| dcontext | varchar(80) | NO | | | |
| channel | varchar(80) | NO | | | |
| dstchannel | varchar(80) | NO | | | |
| lastapp | varchar(80) | NO | | | |
| lastdata | varchar(80) | NO | | | |
| duration | int(11) | NO | | 0 | |
| billsec | int(11) | NO | | 0 | |
| disposition | varchar(45) | NO | | | |
| amaflags | int(11) | NO | | 0 | |
| accountcode | varchar(20) | NO | | | |
| userfield | varchar(255) | NO | | | |
| uniqueid | varchar(32) | NO | MUL | | |
+————-+————–+——+—–+———————+——-+
16 rows in set (0.00 sec)
mysql>

Данный этап завершен! Теперь проверяем, загружен ли mysql модуль.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
ippbx01# asterisk -r
Asterisk 1.4.20, Copyright (C) 1999 - 2008 Digium, Inc. and others.
Created by Mark Spencer
Asterisk comes with ABSOLUTELY NO WARRANTY; type ‘core show  warranty’ for details.
This is free software, with components licensed under the GNU  General Public
License version 2 and other licenses; you are welcome to  redistribute it under
certain conditions. Type ‘core show license’ for details.
=========================================================================
Connected to Asterisk 1.4.20 currently running on asterisk88 (pid =  26648)
Verbosity is at least 3
ippbx01*CLI> stop now
ippbx01*CLI>
Disconnected from Asterisk server
ippbx01# safe_asterisk
ippbx01# asterisk -r
Asterisk 1.4.20, Copyright (C) 1999 - 2008 Digium, Inc. and others.
Created by Mark Spencer
Asterisk comes with ABSOLUTELY NO WARRANTY; type ‘core show  warranty’ for details.
This is free software, with components licensed under the GNU  General Public
License version 2 and other licenses; you are welcome to  redistribute it under
certain conditions. Type ‘core show license’ for details.
=========================================================================
Connected to Asterisk 1.4.20 currently running on asterisk88 (pid =  26880)
Verbosity is at least 3
ippbx01*CLI> cdr mysql status
<h2>Connected to asterisk@localhost, port 3306 using table cdr for 15  seconds.</h2>
Wrote 0 records since last restart.
ippbx01*CLI> quit

Вот и все, хранение CDR в БД MySQl у нас работает.

 

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *