On a previous opportunity we configured our Asterisk installation to connect with MariaDB (or MySQL) database through ODBC, using unixODBC. Well, this is a sample of the res_odbc.conf and cdr_odbc.conf files that would work just out of the box with that configuration:
This is the /etc/asterisk/res_odbc.conf file, where we configure our DSNs as available resources for Asterisk.
The default context name expected by Asterisk is ‘asterisk‘, but it could have been called whatever you want as long as you remember that name and configure it correctly in the rest of configuration files that use ARA.
Note that we didn’t indicate the username or password for the database as that information was configured in the DSN’s definition’s file (/etc/asterisk/odbc.ini).
; Define your environmental variables here.
enabled => yes
dsn => asterisk-dsn
pre-connect => yes
This is the /etc/asterisk/cdr_odbc.conf file. Here we configure the Asterisk DSN resource that we will use to store our CDR data.
table=cdr ; "cdr" is default table name
hrtime=yes ; Enables microsecond accuracy
; with the billsec and duration fields
Note: the Asterisk DSN
Remember that when we use ‘dsn=asterisk‘ setting here, we are talking bout the context name configured previously in res_odbc.conf. (again, not the DSN in /etc/odbc.ini). ‘table=cdr‘ indicates the name of your CDR table.
The previous configuration files should be a good start point for any quick configuration that you plan to do.
If there’s anything I could make any clearer, just let me know.