cdr_sqlite
Asterisk can store CDR records in a SQLite database, as an alternative to CSV text files and other database formats.
Compiling cdr_sqlite.so
The module will automatically compile if you have the SQLite library and header files installed.
Create the database
The database table ‘cdr’ will be automatically created in /var/log/asterisk/cdr.db. There is only one (implicit) key in this table, on the auto-incrementing AcctId. If you need indizes to speed up your queries, you can create them manually like in the following example:
$ sqlite /var/log/asterisk/cdr.db
SQLite version 2.8.14
Enter “.help” for instructions
sqlite> create index cdr_src on cdr (src);
sqlite> create index cdr_dst on cdr (dst);
Edit the configuration file
There is no config file for SQLite. It’s so simple, that you won’t need one.
Database Location
Unless you modified the source code, the database can be found at
/var/log/asterisk/cdr.db
If you have sqlite installed, you can query the database by typing
sqlite /var/log/asterisk/cdr.db
Database Structure
The database contains a single table called “cdr”.
Field Name | Type |
---|---|
AcctId | INTEGER PRIMARY KEY |
clid | VARCHAR(80) |
src | VARCHAR(80) |
dsst | VARCHAR(80) |
dcontext | VARCHAR(80) |
channel | VARCHAR(80) |
dstchannel | VARCHAR(80) |
lastapp | VARCHAR(80) |
lastdata | VARCHAR(80) |
start | CHAR(19) |
answer | CHAR(19) |
end | CHAR(19) |
duration | INTEGER |
billsec | INTEGER |
disposition | INTEGER |
amaflags | INTEGER |
accountcode | INTEGER |
Enable Userfield and uniqueid database fields if you need them
Userfield and uniqueid are sometime useful fields but i realized that they are not enabled by default (at least in asterisk-cvs), so in order to have them written to the cdr table you have to
edit the file cdr_sqlite.c like in the following aexample:
- define LOG_UNIQUEID 1
- define LOG_USERFIELD 1
and recompile asterisk. Also, if autoload is not enabled in your modules.conf you should add the line:
load => cdr_sqlite.so
to your modules.conf.
Related Software
astCDRview: