Introduction: This tutorial will guide you through the process of setting up a Python script to receive 3CX Call Detail Records (CDR) and save the data to a MySQL database. We will cover the steps to install the necessary server and Python environment, deploy the Python script, and set up the MySQL database to store the CDR data.

  1. Setting up the server and Python environment

a. Install Python Before you start, ensure that you have Python 3 installed on your server. If you don’t have it already, you can download and install it from the official Python website (https://www.python.org/downloads/).

b. Install MySQL Next, you need to install MySQL on your server. You can follow the official MySQL installation guide for your operating system (https://dev.mysql.com/doc/refman/8.0/en/installing.html).

c. Install the MySQL Connector for Python To connect to the MySQL database from your Python script, you need to install the MySQL Connector for Python. You can install it using pip.

  1. Deploying the Python script

Create a new Python script and copy the final version of the Python code that we developed throughout this conversation. Make sure to update the MySQL connection details (host, user, password, and database) in the script with your own values.

  1. Setting up the MySQL database

a. Create a new database Log in to your MySQL server and create a new database to store the CDR data.

b. Create a new table Create a new table in the CDR database to store the call detail records. The table should have the following columns: from_no, to_no, duration, and time_end.

  1. Running the Python script

To start the Python script, open a terminal and navigate to the directory where the script is located. Run the script using the appropriate command for your system.

The script will start listening for incoming CDR data on the specified IP and port. When the script receives CDR data, it will process it and save it to the MySQL database. For detail python code, Please check our github code

58voip/3cx (github.com)

 

Conclusion: In this tutorial, we demonstrated how to set up a Python script to receive 3CX CDR data and save it to a MySQL database. By following these steps, you can now store and analyze your call detail records for various purposes, such as billing, call analysis, or performance monitoring. Remember to include the Python code we developed in this conversation at the end of your blog post.