text
stringlengths
0
152
ful). If you get a message like Table 'asterisk.cdr' doesn't exist, that indicates
Alembic didn’t complete the configuration, and you need to review the messages
from the Alembic output to see what went wrong (credentials is usually what causes
grief here).
Well, that wasn’t too hard, eh? The next step is to tell Asterisk to use this new table for
CDR going forward.
$ sudo -u asterisk touch /etc/asterisk/cdr_adaptive_odbc.conf
$ sudo -u asterisk vim /etc/asterisk/cdr_adaptive_odbc.conf
Into this new file, paste the following:
[adaptive_connection]
connection=asterisk
table=cdr
This is almost too easy, wouldn’t you say? Alrighty, now we just have to reload the
ccdr_adaptive_odbc.so module in Asterisk:
$ sudo asterisk -rvvvvvvv
*CLI> module reload cdr_adaptive_odbc.so
You can verify that the Adaptive ODBC backend has been loaded by running the
following:10
*CLI> cdr show status
Call Detail Record (CDR) settings
----------------------------------
Logging: Enabled
Mode: Simple
Log unanswered calls: No
Log congestion: No
* Registered Backends
-------------------
cdr-syslog
Adaptive ODBC
cdr-custom
csv
cdr_manager
10 You may see different backends registered, depending on what configuration you have done with other com‐
ponents of the various CDR modules.
Storing Call Detail Records
|
283
Now place a call that gets answered (e.g., using Playback(), or Dial()ing another
channel and answering it). You should get some CDRs stored into your database. You
can check by running SELECT * FROM CDR; from your database console.
With the basic CDR information stored in the database, you might want to add some
additional information to the cdr table, such as the route rate. You can use the ALTER
TABLE directive to add a column called route_rate to the table:
sql> ALTER TABLE cdr ADD COLUMN route_rate varchar(10);
Now reload the cdr_adaptive_odbc.so module from the Asterisk console:
*CLI> module reload cdr_adaptive_odbc.so
and populate the new column from the Asterisk dialplan using the CDR() function,
like so:
exten => _NXXNXXXXXX,1,Verbose(1,Example of adaptive ODBC usage)
same => n,Set(CDR(route_rate)=0.01)
same => n,Dial(SIP/my_itsp/${EXTEN})
same => n,Hangup()
After the alteration to your database and dialplan, you can place a call and then look
at your CDRs. You should see something like the following:
+--------------+----------+---------+------------+
| src | duration | billsec | route_rate |
+--------------+----------+---------+------------+
| 0000FFFF0008 | 37 | 30 | 0.01 |
+--------------+----------+---------+------------+
In reality, storing rating in the call record might not be ideal (CDR is typically used as
a raw resource, and things such as rates are added downstream by billing software).
The ability to add custom fields to CDR is very useful, but be careful not to use your
call records to replace a proper billing platform. Best to keep your CDR clean and do
further processing downstream.
Additional Configuration Options for cdr_adaptive_odbc.conf
Some extra configuration options exist in the cdr_adaptive_odbc.conf file that may be
useful. The first is that you can define multiple databases or tables to store informa‐
tion into, so if you have multiple databases that need the same information, you can
simply define them in res_odbc.conf, create tables in the databases, and then refer to
them in separate sections of the configuration:
[mysql_connection]