Дано:
- FreeBSD 8.1-RELEASE
- Asterisk 1.8.17.0
Полученные от CEL данные будем складывать в csv и MySQL.
Using MySQL for Channel Event records is supported by using ODBC and the cel_odbc module.
Ставим порты для ODBC
- /usr/ports/databases/unixODBC
- /usr/ports/databases/mysql-connector-odbc
# pkg_info | grep ODBC
mysql-connector-odbc-unixodbc-mysql55-5.1.9 ODBC driver for MySQL55 / unixodbc
unixODBC-2.3.1 ODBC library suite for Unix
# ls -la /usr/local/lib/libmyodbc*
-rwxr-xr-x 1 root wheel 260880 18 сен 09:21 /usr/local/lib/libmyodbc5.so
Смотрим расположение конфиг файлов:
# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2
Правим /usr/local/etc/odbcinst
.ini
[MySQL]
Description=ODBC for MySQL
Driver=/usr/local/lib/libmyodbc5.so
UsageCount=20001
Инсталим драйвер:
# odbcinst -i -d -f /usr/local/etc/odbcinst.ini
Правим /usr/local/etc/odbc.ini:
[mysql-odbc-ini-asterisk]
Driver=MySQL
SERVER=127.0.0.1
PORT=3306
DATABASE=asterisk
USER=asterisk
PASSWORD=password
OPTION=4194304
Проверяем список доступных DSN:
# odbcinst -s -q
[mysql-odbc-ini-asterisk]
Настраиваем конфиги в Asterisk
/usr/local/etc/asterisk/cel.conf:
[general]
enable=yes
;apps=dial,park
;events=APP_START,CHAN_START,CHAN_END,ANSWER,HANGUP,BRIDGE_START,BRIDGE_END
apps=all
events=all
dateformat = %F %T
[manager]
enabled=no
[radius]
В /usr/local/etc/asterisk/cel_custom.conf раскомментируем секцию [mappings].
Проверим наличие директории /var/log/asterisk/cel-custom, если её нет то создадим ей и не забываем установить необходимые права, чтобы asterisk смог осуществить запись.
/usr/local/etc/asterisk/res_odbc.conf:
[asterisk-res-odbc]
enabled => yes
dsn => mysql-odbc-ini-asterisk
username => asterisk
password => password
pre-connect => yes
/usr/local/etc/asterisk/cel_odbc.conf:
[first]
connection=asterisk-res-odbc
table=cel
loguniqueid=yes
Создаем таблицу в базе:
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`)
);
Перезапускаем:
# asterisk -r
asterisk*CLI> module reload res_odbc.so
— Reloading module ‘res_odbc.so’ (ODBC resource)
== Parsing ‘/usr/local/etc/asterisk/res_odbc.conf’: == Found
[Sep 18 10:05:59] NOTICE[84181]: res_odbc.c:1531 odbc_obj_connect: Connecting asterisk-res-odbc
[Sep 18 10:05:59] NOTICE[84181]: res_odbc.c:1563 odbc_obj_connect: res_odbc: Connected to asterisk-res-odbc [mysql-odbc-ini-asterisk]
[Sep 18 10:05:59] NOTICE[84181]: res_odbc.c:920 load_odbc_config: Registered ODBC class ‘asterisk-res-odbc’ dsn->[mysql-odbc-ini-asterisk]
[Sep 18 10:05:59] DEBUG[84181]: res_odbc.c:1504 odbc_obj_disconnect: Database handle 0x2a9a6000 deallocated
asterisk*CLI> module reload cel_odbc.so
— Reloading module ‘cel_odbc.so’ (ODBC CEL backend)
== Parsing ‘/usr/local/etc/asterisk/cel_odbc.conf’: == Found
— Found CEL table cel@asterisk-res-odbc.
asterisk*CLI> module reload cel_custom.so
— Reloading module ‘cel_custom.so’ (Customizable Comma Separated Values CEL Backend)
== Parsing ‘/usr/local/etc/asterisk/cel_custom.conf’: == Found
Проверяем:
asterisk*CLI> cel show status
CEL Logging: Enabled
CEL Tracking Event: ALL
CEL Tracking Event: CHAN_START
CEL Tracking Event: CHAN_END
CEL Tracking Event: HANGUP
CEL Tracking Event: ANSWER
CEL Tracking Event: APP_START
CEL Tracking Event: APP_END
CEL Tracking Event: BRIDGE_START
CEL Tracking Event: BRIDGE_END
CEL Tracking Event: CONF_START
CEL Tracking Event: CONF_END
CEL Tracking Event: PARK_START
CEL Tracking Event: PARK_END
CEL Tracking Event: BLINDTRANSFER
CEL Tracking Event: ATTENDEDTRANSFER
CEL Tracking Event: TRANSFER
CEL Tracking Event: HOOKFLASH
CEL Tracking Event: 3WAY_START
CEL Tracking Event: 3WAY_END
CEL Tracking Event: CONF_ENTER
CEL Tracking Event: CONF_EXIT
CEL Tracking Event: USER_DEFINED
CEL Tracking Event: LINKEDID_END
CEL Tracking Event: BRIDGE_UPDATE
CEL Tracking Event: PICKUP
CEL Tracking Event: FORWARD
CEL Tracking Application: all
CEL Event Subscriber: ODBC CEL backend
CEL Event Subscriber: CEL Custom CSV Logging
asterisk*CLI> odbc show
ODBC DSN Settings
——————
Name: asterisk-res-odbc
DSN: mysql-odbc-ini-asterisk
Last connection attempt: 1970-01-01 03:00:00
Pooled: No
Connected: Yes
После чего при прохождении вызовов должна будет заполняться таблица cel в БД asteriskб так же файл /var/log/asterisk/cel-custom/Master.csv.
Описание: CEL Events and Fields
Существует возможность генерить свои event`ы: CELGenUserEvent Application:
asterisk*CLI> core show application CELGenUserEvent -= Info about application 'CELGenUserEvent' =- [Synopsis] Generates a CEL User Defined Event. [Description] A CEL event will be immediately generated by this channel, with the supplied name for a type. [Syntax] CELGenUserEvent(event-name[,extra]) [Arguments] extra Extra text to be included with the event.
Ссылки:
- Channel Event Logging (CEL)
- Setting up Channel Event Logging (CEL) on Asterisk 1.8 or up with MySQL
- Asterisk™: The Definitive Guide: Chapter 24. System Monitoring and Logging
- Using MySQL through ODBC on FreeBSD
З.Ы. При копировании статьи ссылка на источник ОБЯЗАТЕЛЬНА !
Автор: Николаев Дмитрий (virus (at) subnets.ru
Добавить комментарий
Вам следует авторизоваться для размещения комментария.