Asterisk is an open source PBX that helps you to have
your own inexpensive VoIP network. This tool will help you to have a
better overview of the calls passing through the queues you have
(incoming calls). We assume that you have some basic knowledge in
Asterisk and mainly at least small experience with queues
(/etc/asterisk/queues.conf), PHP and databases.
The
application is reading the queue_log file, puts it in a database and
from this database gets different kind of statistics for the
queue(s) you are interested in.
We are using a jpGraph
product for the graphics which is QPL licensed.
PREREQUISITES
To use this statistics you need:
Asterisk
PHP version
4.3.5. or higher (preferably with Apache web server)
Database server
(PostgreSQL)
Zend Optimizer
As you probably
saw the php scripts are encoded. So you need to install Zend
Optimizer module for Apache in order to start the scripts (other way
apache can not read the php files).
NOTE: After Zend
Optimizer is installed check your php.ini file. There your Zend
Optimizer might be turned off.
Download the PHP files and
create the database table as described below (you have to use
PosgresSQL for the database).
STRUCTURE
The application is working in the following
way.
1. All calls going into the Asterisk Queues are
documented in queue_log (Asterisk has to be set to do this - by
default queue_log is not enabled).
2. PHP script is reading
all queue_log files (original and rotated). Logger rotating program
is rotating the queue_log at certain date or time or when the file
reaches some limited size. The original file is named queue_log and
the rotated queue_log.0, queue_log.1 and so on. So the script reads
the files (sorted by modification date) one by one starting from the
latest modified finishing with the most resent. The data is stored
in the created postgres database tables. The script that read the
log files and fills up the database is logque.php (in directory
log). You can run it manually or schedule some task manager
(crontab) to run it at certain time.
3. PHP gets the stored
data from the database and creates tables and graphics for the
statistics.
QUEUE_LOG
Queue_log is an Asterisk log file where data
concerning the queue is written. More precisely is to say that only
data concerning the incoming calls, agent logins and logouts and
internal transfers is written.
To fill in the database you
must first of all have a queue_log file. The default directory where
the log files are placed is
/var/log/asterisk/.
The
queue_log is not created by default. Check whether you have this
line in
/etc/asterisk/logger.conf.
queue_log=>
This writes the data
from the queue to this queue_log file. logger.conf file is for
setting the logs which to be created and filled in
/var/log/asterisk/. So the first step is to set Asterisk to
write to the queue_log.
DATABASE
The tables that you need are several and can be
created by executing db.sql. You should have installed postgres.
Just execute the queries from the db file in the download
directory.
It is preferable to create a new database. If you
are not aware how to make one here is a simple query that does
this:
CREATE DATABASE db_name
WITH OWNER =
username
ENCODING = 'SQL_ASCII'
TABLESPACE = pg_default;
When you have the database just execute the query from
db.sql and you will have the tables that you need for storing the
queue_log data.
FINE SETTINGS
The application is encoded except the
config.inc.php files in directory log and include which you can
modify.
1. Log directory
Look at config.inc.php in the log directory.
These configuration settings are only for the logque.php script.
There you have to set the required parameter for connecting to the
database as well as the absolute path to your queue_log
files.
$queue_log_dir = '/var/log/asterisk/';
This default
path to the queue_log files if you are using linux os. But for
example if you are on windows you can copy them from the asteriks
server to C:/qstats or C:/temp
Afterward you have to set the
database connection:
$db_host = '127.0.0.1';
$db_name =
'database_name';
$db_user = 'username';
$db_pass =
'password';
This is establishing connection to the database
on the local machine (127.0.0.1), so if your database is somewhere
remotely you have to type the address where it can be accessed. Just
change the value for the $db_host variable to a valid address
for your database server. $db_name is the database name where
the table data is stored, and $db_user is the username for
the user who has privileges to access the database. $db_pass
is the password of the user who is accessing the
database.
2. Include directory
This config.inc.php file is for the rest of the
php application i.e. all the stats graphs and reports. You have to
originate the connection to the database as described in the
previous section.
$dbhost = '127.0.0.1';
$dbname =
'database_name';
$dblogin = 'username';
$dbpass =
'password';
Next is to provide the absolute path for the
report images. There is option to see the reports in PDF format. The
images for the report are generated and stored somewhere locally
before used for the report itself. But the PHP has to have
permissions to write down on your hard drive the images so you have
to provide the path to this directory.
The images for the
reports have to be saved locally on your pc. Therefore the web
server must have privileges to write and read from the directory
where they will be stored. The default directory is different and
depends on the OS. For Linux it is "/tmp" and for Windows it is
"%USERPROFILE%Local SettingsTemp" (usually C:Documents and
Settings<user>Local SettingsTemp). Choose you OS between Linux
and windows. Comment the one you are not going to use.
$os =
"linux";
#$os = "windows";
Then set the correct path to
the directory where the images will be stored.
The settings of
the images_path for the OS you are not going to use does not matter.
For Linux default image path is /tmp. You can change it but have to
make sure that the web server can write into it. For windows you can
also make a directory where the images to be stored, but again you
have to provide read and write access for the web
server.
$image_path_lin = "/tmp";
$image_path_win =
"C:/qimages";
You have language settings also. You can choose
between English (EN), French (FR) and Italian(IT). Volunteers to
translate into other languages are always welcome, that is why the
language files are not encoded. In this config file you can set your
default language.
$default_language = 'en';
The
reason that you have two identically the same config.inc.php files
is that you can have the logque script and the rest on two separate
computers.
STATS
When you have created the database and copy the
other scripts on your web server (you can place the logque on other
machine but anyway the hierarchy must not be changed), then you can
run the application. Make sure that all downloaded directories and
files are structured on your computer as in the download directory.
All this files have to be in your apache-working directory (if you
are using Apache as web server for PHP).
First fill in the
database with the logque.php (placed in the log directory). Make
sure the settings in the same directory in config.inc.php are
correct (path to the queue_log files).
Then just type in a
browser path/index.php. Then the program will run and you
will be prompted to choose period, queue (you can select all
available queues), time zone and language for the statistics
calculations.