Last active
August 21, 2024 07:54
-
-
Save shahriarhasib/7a982f46d7f1cd0ab99bab33808367ec to your computer and use it in GitHub Desktop.
Asterisk CDR into database | MySQL | PHPMyAdmin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Configuring Asterisk CDR to update into database with MySQL and using phpmyadmin for web access to the databases. | |
## Resources: | |
## Ubuntu 24.04 LTS, Asterisk 20.6.0 | |
## Last update: 2024.08.21 | |
##At once to install: | |
apt install mysql-server php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip apache2 phpmyadmin asterisk-mysql | |
apt install asterisk-mysql | |
#Or Indiviually for understanding: | |
# Install MySQL Server, which is a popular relational database management system | |
#apt install mysql-server | |
# Secure MySQL Installation: | |
#sudo mysql_secure_installation | |
# Install PHP, a widely-used scripting language that is especially suited for web development | |
# apt install php | |
# Install the Apache2 PHP module, which allows PHP to be executed by the Apache web server | |
#apt install libapache2-mod-php | |
# Install the PHP MySQL extension, enabling PHP scripts to interact with MySQL databases | |
#apt install php-mysql | |
# Install the PHP cURL extension, allowing PHP scripts to make HTTP requests to other servers | |
#apt install php-curl | |
# Install the PHP GD library, which provides image processing capabilities within PHP scripts | |
#apt install php-gd | |
# Install the PHP JSON extension, allowing PHP scripts to handle JSON data | |
#apt install php-json | |
# Install the PHP ZIP extension, enabling PHP scripts to work with ZIP compressed files | |
#apt install php-zip | |
# Install Apache2, a widely-used open-source web server that serves web content | |
#apt install apache2 | |
# Install phpMyAdmin, a web-based interface for managing MySQL and MariaDB databases | |
#apt install phpmyadmin | |
# Install the Asterisk module for MySQL, enabling the Asterisk telephony system to interact with MySQL databases | |
#apt install asterisk-mysql | |
#Loging to web: | |
http://ip/phpmyadmin | |
#Username: phpmyadmin | |
#password: As set during installation of phpmyadmin | |
#Login to mysql console: | |
mysql -u root -p | |
#Login without password or with password if set | |
#Create a database for CDR: | |
#sql: | |
CREATE DATABASE asteriskcdrdb; | |
#Create a MySQL user and grant privileges: | |
#sql: | |
CREATE USER 'asteriskuser'@'localhost' IDENTIFIED BY '7AEmMN76dADwn2#UqyY3'; | |
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO 'asteriskuser'@'localhost'; | |
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO 'phpmyadmin'@'localhost'; | |
FLUSH PRIVILEGES; | |
#Switch to the new database: | |
#sql: | |
USE asteriskcdrdb; | |
#Create the cdr table: | |
#sql: | |
CREATE TABLE cdr ( | |
calldate datetime NOT NULL default CURRENT_TIMESTAMP, | |
clid varchar(80) NOT NULL default '', | |
src varchar(80) NOT NULL default '', | |
dst varchar(80) NOT NULL default '', | |
dcontext varchar(80) NOT NULL default '', | |
channel varchar(80) NOT NULL default ste'', | |
dstchannel varchar(80) NOT NULL default '', | |
lastapp varchar(80) NOT NULL default '', | |
lastdata varchar(80) NOT NULL default '', | |
duration int(11) NOT NULL default '0', | |
billsec int(11) NOT NULL default '0', | |
disposition varchar(45) NOT NULL default '', | |
amaflags int(11) NOT NULL default '0', | |
accountcode varchar(20) NOT NULL default '', | |
uniqueid varchar(32) NOT NULL default '', | |
userfield varchar(255) NOT NULL default '' | |
); | |
#Exit MySQL: | |
#sql: | |
quit; | |
#Ensure that the cdr_mysql module is listed and loaded. | |
sudo asterisk -rx "module show like cdr_mysql" | |
#cdr_mysql is supposed to be removed for the newer version of asterisk, ref: https://docs.asterisk.org/Development/Asterisk-Module-Deprecations/ | |
#if cdr_mysql is not avaialbale no need to follow next steps here, jump to use ODBC Connector: (https://gist.github.com/shahriarhasib/0f7b810b2874d31db105faee679d6b7c) | |
#if cdr_mysql is available then: | |
#Add or modify the following configuration: | |
vi /etc/asterisk/cdr_mysql.conf | |
# Define the values to be updated | |
[global] | |
hostname="localhost" | |
user="asteriskuser" | |
password="7AEmMN76dADwn2#UqyY3" | |
dbname="asteriskcdrdb" | |
table="cdr" | |
cdrzone="Asia/Dhaka" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment