Page 302 - Asterisk™: The Future of Telephony
P. 302
If Asterisk is already running, from the Asterisk CLI execute module reload
cdr_odbc.so. You can also just type reload, to reload everything.
*CLI> reload
Verify the status of CDR by entering the following command and looking for
CDR registered backend: ODBC:
*CLI> cdr status
CDR logging: enabled
CDR mode: simple
CDR registered backend: cdr-custom
CDR registered backend: cdr_manager
CDR registered backend: ODBC
Now, perform a call through your Asterisk box and verify you have data in the aster-
isk_cdr table. The easiest way to test a call is with the Asterisk CLI command console
dial (assuming that you have a sound card and chan_oss installed). However, you can
utilize any method at your disposal to place a test call:
*CLI> console dial 100@default
-- Executing [100@default:1] Playback("OSS/dsp", "tt-weasels") in new stack
-- <OSS/dsp> Playing 'tt-weasels' (language 'en')
Then connect to the database and perform a SELECT statement to verify you have data
in the asterisk_cdr table. You could also do SELECT * FROM asterisk_cdr;, but that
will return a lot more data:
# psql -U asterisk -h localhost asterisk
Password:
asterisk=> SELECT id,dst,channel,uniqueid,calldate FROM asterisk_cdr;
id | dst | channel | uniqueid | calldate
----+-----+---------+----------------------+------------------------
1 | 100 | OSS/dsp | toronto-1171611019.0 | 2007-02-16 02:30:19-05
(1 rows)
Getting Funky with func_odbc: Hot-Desking
The func_odbc dialplan function is arguably the coolest and most powerful dialplan
function in Asterisk. It allows you to create and use fairly simple dialplan functions that
retrieve and use information from databases directly in the dialplan. There are all kinds
of ways in which this might be used, such as managing users or allowing sharing of
dynamic information within a clustered set of Asterisk machines.
What func_odbc allows you to do is define SQL queries to which you assign function
names. In effect, you are creating custom functions that obtain their results by executing
queries against a database. The func_odbc.conf file is where you specify the relationship
between the function names you create and the SQL statements you wish them to
perform. By referring to the named function in the dialplan, you can retrieve and update
values in the database.
274 | Chapter 12: Relational Database Integration