Skip to content

Instantly share code, notes, and snippets.

@ambiorixg12
Last active January 6, 2024 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ambiorixg12/79805c7d25c7ca7d6a1cc0c009002b6d to your computer and use it in GitHub Desktop.
Save ambiorixg12/79805c7d25c7ca7d6a1cc0c009002b6d to your computer and use it in GitHub Desktop.
CDR ODBC MYSL Centos 7
Install dependencies
yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
yum install mysql-connector-odbc
/etc/odbc.ini
[asterisk-mysql]
Description = MySQL connection to 'asterisk' database
Driver = MySQL
Database = asterisk
Server = localhost
UserName = root
Password = 7891
Port = 3306
Socket = /var/lib/mysql/mysql.sock
/etc/odbcinst.ini
# Example driver definitions
# Driver from the postgresql-odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
/etc/asterisk/res_odbc.conf
[asterisk-mysql]
enabled => yes
dsn => asterisk-mysql
username => root
password => 7891
pre-connect => yes
/etc/asterisk/cdr_adaptive_odbc.conf
[asterisk-mysql]
connection=asterisk-mysql
table=cdr
alias start => calldate
Load on asterisk
module reload res_odbc.so
Module 'res_odbc.so' reloaded successfully.
-- Reloading module 'res_odbc.so' (ODBC resource)
== Parsing '/etc/asterisk/res_odbc.conf': Found
== Parsing '/etc/asterisk/res_odbc_custom.conf': Found
== Parsing '/etc/asterisk/res_odbc_additional.conf': Found
[2015-09-04 14:48:27] NOTICE[10623]: res_odbc.c:1528 odbc_obj_connect: Connecting asterisk-mysql
[2015-09-04 14:48:27] NOTICE[10623]: res_odbc.c:1567 odbc_obj_connect: res_odbc: Connected to asterisk-mysql [asterisk-mysql]
[2015-09-04 14:48:27] NOTICE[10623]: res_odbc.c:923 load_odbc_config: Registered ODBC class 'asterisk-mysql' dsn->[asterisk-mysql]
[2015-09-04 14:48:27] NOTICE[10623]: res_odbc.c:1528 odbc_obj_connect: Connecting asteriskcdrdb
[2015-09-04 14:48:27] WARNING[10623]: res_odbc.c:1560 odbc_obj_connect: res_odbc: Error SQLConnect=-1 errno=0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
[2015-09-04 14:48:27] WARNING[10623]: res_odbc.c:1370 _ast_odbc_request_obj2: Failed to connect to asteriskcdrdb
[2015-09-04 14:48:27] NOTICE[10623]: res_odbc.c:923 load_odbc_config: Registered ODBC class 'asteriskcdrdb' dsn->[MySQL-asteriskcdrdb]
ibx2*CLI>
ibx2*CLI> module reload cdr_adaptive_odbc.so
Module 'cdr_adaptive_odbc.so' reloaded successfully.
-- Reloading module 'cdr_adaptive_odbc.so' (Adaptive ODBC CDR backend)
== Parsing '/etc/asterisk/cdr_adaptive_odbc.conf': Found
-- Found adaptive CDR table cdr@asterisk-mysql.
-- Found alias start for column calldate in cdr@asterisk-mysql
> Found calldate column with type 93 with len 19, octetlen 19, and numlen (0,10)
> Found clid column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found src column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found dst column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found dcontext column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found channel column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found dstchannel column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found lastapp column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found lastdata column with type 12 with len 80, octetlen 80, and numlen (0,0)
> Found duration column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found billsec column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found disposition column with type 12 with len 45, octetlen 45, and numlen (0,0)
> Found amaflags column with type 4 with len 10, octetlen 10, and numlen (0,10)
> Found accountcode column with type 12 with len 20, octetlen 20, and numlen (0,0)
> Found uniqueid column with type 12 with len 32, octetlen 32, and numlen (0,0)
> Found userfield column with type 12 with len 255, octetlen 255, and numlen (0,0)
> Found did column with type 12 with len 50, octetlen 50, and numlen (0,0)
> Found recordingfile column with type 12 with len 255, octetlen 255, and numlen (0,0)
> Found cnum column with type 12 with len 40, octetlen 40, and numlen (0,0)
> Found cnam column with type 12 with len 40, octetlen 40, and numlen (0,0)
> Found outbound_cnum column with type 12 with len 40, octetlen 40, and numlen (0,0)
> Found outbound_cnam column with type 12 with len 40, octetlen 40, and numlen (0,0)
> Found dst_cnam column with type 12 with len 40, octetlen 40, and numlen (0,0)
ibx2*CLI>
ibx2*CLI> odbc show all
ODBC DSN Settings
-----------------
Name: asterisk-mysql
DSN: asterisk-mysql
Last connection attempt: 1969-12-31 19:00:00
Pooled: No
Connected: Yes
Name: asteriskcdrdb
DSN: MySQL-asteriskcdrdb
Last connection attempt: 2015-09-04 14:48:27
ibx2*CLI> cdr show status
Call Detail Record (CDR) settings
----------------------------------
Logging: Enabled
Mode: Simple
Log unanswered calls: No
Log congestion: No
* Registered Backends
-------------------
cdr-custom
Adaptive ODBC
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html
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 '',
uniqueid varchar(32) NOT NULL default '',
userfield varchar(255) NOT NULL default ''
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment