Asterisk CDR issue

Hello, I need to store CDR data in mysql database. I used MariaDB as a driver. But Following Issue occurred. How fix it??

[Feb 24 14:39:10] WARNING[70862][C-00000001]: pbx_variables.c:1164 pbx_builtin_setvar: Please avoid unnecessary spaces on variables as it may lead to unexpected results ('ODBC_WRITE("784xxxxx" <784xxxxxx>,784xxxxx,s,dmse_IVR,PJSIP/registrar-00000000,,Set,CDR(userfield)' set to 'Your_custom_userfield_data,0,0,NO ANSWER,DOCUMENTATION,,1708765749.0,1708765749.0,Your_custom_userfield_data)').
[Feb 24 14:39:10] ERROR[70862][C-00000001]: pbx_functions.c:699 ast_func_write: Function ODBC_WRITE not registered


[Feb 24 14:39:14] ERROR[70803]: cdr_odbc.c:171 odbc_log: Unable to retrieve database handle.  CDR failed.


  1. Unnecessary Spaces Warning: The warning indicates that there are unnecessary spaces in the variable being set, which may lead to unexpected results. You should review the relevant configuration or dialplan code to ensure that variables are being set without unnecessary spaces. In your case, it seems to be related to setting the CDR userfield. Ensure that the variable is set correctly without any extraneous spaces.
  2. Function Not Registered Error: The error message indicates that the function ODBC_WRITE is not registered. This suggests that either the function is not defined in your Asterisk configuration or there’s an issue with loading the module that provides this function. You should verify that the function ODBC_WRITE is correctly defined in your Asterisk configuration files. If it’s defined but still not registered, ensure that the corresponding module providing this function is loaded properly. You may need to check your Asterisk module loading configuration (e.g., modules.conf) to ensure that the necessary modules are being loaded.
  3. Unable to Retrieve Error: The error related to cdr_odbc.c suggests a problem with retrieving data from the ODBC data source for the Call Detail Records (CDR). This could be due to various reasons such as incorrect database configuration, connectivity issues, or problems with the ODBC driver. Double-check your ODBC configuration in Asterisk (cdr_odbc.conf), ensuring that it matches the configuration of your MySQL/MariaDB database. Verify the connection parameters, database credentials, and data source name (DSN). Additionally, ensure that the ODBC driver for MariaDB is correctly installed and configured on your system.

For 3rd problem, →

This is my cdr_odbc.conf file code


[global]
hostname=localhost
dbname=asterisk
table=cdr
password=asterisk
user=asterisk
port=3306
sock=/var/run/mysqld/mysqld.sock
;sock=/run/mysqld/mysqld.sock

this is my odbc.ini

[asterisk]
Description = MySQL Asterisk
Driver = MariaDB Unicode
Database = asterisk
Server = localhost
User = asterisk
Password = asterisk
Port = 3306
Socket = /var/run/mysqld/mysqld.sock

and this is odbcinst.ini


[MariaDB]
Description=ODBC for MariaDB
Driver=/usr/local/lib/libmaodbc8w.so
Setup=/usr/local/lib/libodbcmyS.so
UsageCount=1

[MariaDB Unicode]
Driver=libmaodbc.so
Description=MariaDB Connector/ODBC(Unicode)
Threading=0
UsageCount=1


What is the problem??

Your ODBC configuration files seem mostly correct, but there are a couple of potential issues to consider:

  1. Driver and Setup Paths in odbcinst.ini: Ensure that the paths to the ODBC driver (Driver parameter) and setup library (Setup parameter) are correct. Double-check the paths to libmaodbc8w.so and libodbcmyS.so respectively. If these paths are incorrect or the files are missing, ODBC won’t be able to load the driver properly.
  2. Socket Path in odbc.ini: Confirm that the path to the MySQL/MariaDB socket file specified in your odbc.ini matches the actual location of the socket file on your system. The Socket parameter should point to the correct socket file, typically located in /var/run/mysqld/mysqld.sock or /run/mysqld/mysqld.sock. If the socket file is located elsewhere or has a different name, update the Socket parameter accordingly.
  3. Permissions and Connectivity: Ensure that the user running the Asterisk service has appropriate permissions to access the MySQL/MariaDB database through ODBC. Verify that the user credentials (user and password parameters) in both cdr_odbc.conf and odbc.ini are correct and have sufficient privileges to read and write to the cdr table in the asterisk database.
  4. ODBC Driver Configuration: Check the documentation for the MariaDB ODBC driver to ensure that it’s properly configured for your system. Make sure that any required dependencies are installed and that the driver is compatible with your version of Asterisk and MySQL/MariaDB.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.