Asterisk 1.8 write CDR using ODBC.

In Asterisk 1.8 and above are recommended as the backend for the CDR, use the ODBC driver. This driver is a layer between the Asterisk and the database. This allows connection between Asterisk and unify the various databases, I easily. Consider the record CDR log files using ODBC.
Install the required packages

1
yum install mysql-server mysql mysql-devel mysql-connector-odbc unixODBC unixODBC-devel -y
Add to the file “/etc/odbc.ini, the following lines
1
2
3
4
5
6
7
8
9
10
11
12
;
; DSN definitions
;
[asterisk-cdr]
Description = Asterisk CDR Backend ODBC
Driver = MySQL
Socket = /var/lib/mysql/mysql.sock
Server = localhost
User = asterisk
Pass = Your-Password
Database = asterisk
Option = 3
At the end of the file /etc/asterisk/res_odbc.conf Add line
1
2
3
4
5
6
7
8
9
10
11
12
;
; CDR ODBC Backend
; Environment variables
[ENV]
; Connections
[asterisk-cdr]
enabled => yes
dsn => asterisk-cdr
username => asterisk
password => Your-Password
pre-connect => yes
idlecheck => 600
Check the file “/etc/asterisk/cdr_odbc.conf” that he was of this type. It only changes the DSN.
1
2
3
4
5
6
7
[global]
dsn=asterisk-cdr
loguniqueid=yes
dispositionstring=yes
table=cdr               ;"cdr" is default table name
usegmtime=no             ; set to "yes" to log in GMT
hrtime=yes              ;Enables microsecond accuracy with the billsec and duration fields
Create a base under the CDR.
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
create database asterisk default charset utf8;
use asterisk;
CREATE TABLE cdr (
  id int(11) unsigned NOT NULL AUTO_INCREMENT,
  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 '',
  peeraccount varchar(20) NOT NULL DEFAULT '',
  linkedid varchar(32) NOT NULL DEFAULT '',
  sequence int(11) NOT NULL DEFAULT '0',
  userfield varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (id),
  KEY calldate (calldate),
  KEY accountcode (accountcode),
  KEY uniqueid (uniqueid),
  KEY dst (dst),
  KEY src (src)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
grant all on asterisk.cdr to asterisk@'localhost' identified by 'Your-Password';
flsuh priveleges;
Now, Reboot your Astersik
1
service asterisk restart
Make the call and look at how to form the base of the CDRs.