CDR-Stats is both multi-tenant in that many users can view only their own CDR, based on accountcode. Additionally, CDR-Stats can display and report statistics from many telephony servers, either individually or aggregated statistics.
To use CDR-Stats, navigate to http://<<IP-Address of your Server>>:8008, and log in with the username and password you entered during the installation.
NB: In installations that have iptables installed and configured, access has to be allowed to port 8008 and 9000 TCP. Add the following line into iptables, usually after the rule to allow http access, port 80. In CentOS, the firewall rules are to be found in /etc/sysconfig/iptables. Issue service iptables restart to apply the rule.
-A INPUT -p tcp -m tcp –dport 8008 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 9000 -j ACCEPT
Configuring CDR-Stats
Configuration of CDR-Stats is done via a text file in /usr/share/cdr_stats/settings_local.py. Any changes to this file should be committed by restarting celery and apache.
service cdr-stats-celeryd restart
service apache2 restart (httpd for CentOS)
The settings in this file are covered in more detail below.
Country Reporting
CDR-Stats is able to identify the destination country of the call. This is a useful fraud prevention measure, so that calls to unexpected destinations are immediately apparent. Places that should not be called should be added in the Blacklist in the admin section so that these destinations are highlighted in the call data records.
However, in order to get accurate reporting, the call detail records have to be in international format, e.g. in the USA, this means 11 digit numbers, beginning with a 1, and for other countries, the numbers called should be prefixed with the international dial code.
There is a facility for manipulating the dialled digits reported in the call detail records, as well as identifying calls as internal calls. This is done in the “general” section of /usr/share/cdr-stats/settings_local.py.
PHONENUMBER_PREFIX_LIMIT_MIN & PHONENUMBER_PREFIX_LIMIT_MAX are used to determine how many digits are used to match against the dialcode prefix database, e.g
PHONENUMBER_PREFIX_LIMIT_MIN = 2
PHONENUMBER_PREFIX_LIMIT_MAX = 5
If a phone number has less digits than PHONENUMBER_MIN_DIGITS it will be considered an extension.
PHONENUMBER_MIN_DIGITS = 6
PHONENUMBER_MAX_DIGITS = 9
If a phone number has more digits than PHONENUMBER_DIGITS_MIN but less than PHONE_DIGITS_MAX then the phone number will be considered as local or national call and the LOCAL_DIALCODE will be added.
LOCAL_DIALCODE = 1
Set the dialcode of your country (44 for UK, 1 for US)
PREFIX_TO_IGNORE = “+,0,00,000,0000,00000,011,55555,99999″
List of prefixes to ignore, these prefixes are removed from the phone number prior to analysis.
Examples
So for the USA, to cope with 10 or 11 digit dialling, PHONENUMBER_MAX_DIGITS would be set to 10, and LOCAL_DIALCODE set to 1. Thus 10 digit numbers would have a 1 added, but 11 digit numbers are left untouched.
In the UK, the number of significant digits is either 9 or 10 after the “0″ trunk code. So to ensure that all UK numbers had 44 prefixed to them and the single leading 0 removed, the prefixes to ignore would include 0, the PHONENUMBER_MAX_DIGITS would be set to 10, and the LOCAL_DIALCODE would be 44.
In Spain, where there is no “0″ trunk code, and the length of all numbers is 9, then the PHONENUMBER_MAX_DIGITS would be set to 9, and the LOCAL_DIALCODE set to 34.
Switch Configuration (Asterisk)
During the install process on an Asterisk system, the script asked a number of questions regarding how to connect to the CDR Database.
Check the database credentials for accuracy in the CDR_backend section, it will look similar this:
CDR_BACKEND = {
‘ localhost’: {
‘db_engine’: ‘mysql’, # mysql, pgsql, mongo
‘cdr_type’: ‘asterisk’, # asterisk or freeswitch
‘db_name’: ‘asteriskcdrdb’,
‘table_name’: ‘cdr’,
‘host’: ‘localhost’,
‘port’: 3306, # 3306 mysql, 5432 pgsql
‘user’: ‘root’,
‘password’: ‘passw0rd’,
},
#…some more settings
}
The next setting to check is the LOCAL_SWITCH_IP entry.
#Define the IP of your local Switch, it needs to exist in the CDR_BACKEND list
LOCAL_SWITCH_IP = ‘localhost’
Set the IP address or hostname of the remote server here. This will be the same as the host in the database settings.
Finally set the Asterisk manager settings. The correct settings can be seen and configured in /etc/asterisk/manager.conf, take a note of these settings, and apply them as below.
#Asterisk Manager / Used for Realtime and Concurrent calls
ASTERISK_MANAGER_HOST = ‘localhost’
ASTERISK_MANAGER_USER = ‘admin’
ASTERISK_MANAGER_SECRET = ‘amp111′
NB: Celery and Apache must be restarted after any changes.
Alerts
Email alerts can be configured in the Alarms section of the admin pages. Click Add Alarm, then configure the alert you require. Two alert conditions can be configured:-
- ALOC – Average Length of Call. This can indicate fraudulent activity or a problem with a trunk.
- ASR – Answer Seize Ratio. This is the ratio between the number of calls made against the number of calls answered. Low ASR values can be caused a failing trunk to one or more destinations.
When configured, CDR-Stats can email a recipient with an alert.
Adding New Switches
Multiple switches can be added to pass their CDR to CDR-Stats. This is set up in two places, in /usr/share/cdr-stats/settings_local.py, and in Switch settings under CDR in the Admin pages.
At the time of writing, CDR-Stats support the automatic import of CDR from either an asterisk MySQL CDR store or for freeswitch, via the mod_cdr_mongodb module. The settings to connect to the CDR stores are in /usr/share/cdr-stats/settings_local.py. These should be set up correctly during the installation script.
Asterisk
The asterisk settings may be as follows:-
ASTERISK_CDR_MYSQL_IMPORT = {
’127.0.0.1′: {
‘db_name’: ‘asteriskcdrdb’,
‘table_name’: ‘cdr’,
‘host’: ‘localhost’,
’user’: ‘root’,
’password’: ‘passw0rd’,
},
#’192.168.1.200′: {
#’db_name’: ‘asteriskcdrdb’,
#’table_name’: ‘cdr’,
#’host’: ‘localhost’,
#’user’: ‘root’,
#’password’: ‘passw0rd’,
#},
}
To add a new remote Asterisk MySQL CDR store, you would ensure connection to the remote MySQL database, then uncomment the new server settings by removing the # and configuring the credentials to connect to the remote Asterisk CDR store.
Freeswitch
Freeswitch settings are under the CDR_MONGO_IMPORT section, and should look as follows:
#MongoDB Setting(s) to use for import
CDR_MONGO_IMPORT = {
’127.0.0.1′: {
‘db_name’: ‘freeswitch_cdr’,
‘host’: ‘localhost’,
‘port’: 27017,
‘collection’: ‘cdr’,
},
#’192.168.1.15′: {
# ‘db_name’: ‘freeswitch_cdr’,
# ‘host’: ’192.168.1.15′,
# ‘port’: 27017,
# ‘collection’: ‘cdr’,
#},
}
To connect a new Freeswitch system to CDR-Stats, you would ensure that port 27017 TCP was open to ONLY the CDR-Stats server on the remote system, uncomment the settings by removing the #, and then configure the IP address and db_name to match those in the mod_cdr_mongodb configuration as described at http://www.cdr-stats.org/documentation/beginners-guide/howto-installing-on-freeswitch/
NB: After changing this file, then both celery and apache should be restarted.
Clearing & Re-Importing Data (FreePBX)
When setting up the CDR import to correctly assign the country, mistakes can be made, and so it may be necessary to clear down and and re-import the data.
First stop celery:
service cdr-stats-celeryd stop
Log into the Mongo Database with the command mongo and run the following commands:
use cdr-stats;
db.monthly_analytic.remove({});
db.daily_analytic.remove({});
db.aggregate_world_report.remove({});
db.aggregate_result_cdr_view.remove({});
db.aggregate_hourly_country_report.remove({});
db.cdr_common.remove({});
To exit the mongo console type CTRL-D
Now log into MySQL with a command like:
mysql -uroot -ppassw0rd asteriskcdrdb
Then when in the MySQL console
update cdr SET import_cdr = 0;
This sets the flag which tells CDR-Stats whether or not the CDR have been imported; when done, CTRL-C exits the MySQL console.
Finally start celery, and the CDR should be re-imported
service cdr-stats-celeryd start
Import CDR
The administrator can import call detail records from a third party switch. for querying and analysis.
There are a number of fields that must be imported as well as optional fields. Where an installation has been done on Freeswitch, only the CDR subsequent to the CDR-Stats installation will be displayed. This feature can be used to bring in historical CDR.
Customers and Users
New users can be added who can only see call data records relating to their account code. They are given their own logon, and only have access to the reporting inteface.
Configuring the SMTP Client
To configure the SMTP client so that reports and alerts are sent via email, edit /usr/share/cdr-stats/settings_local.py, and identify the email section.
Fill in the details to match your SMTP server. The above example is for Gmail. When done, restart Celery and Apache.
To test that the email is working, from the command line type:
$workon cdr-stats
$python manage.py send_daily_report
More Help?
If there are any questions or issues, please join our mailing list at http://groups.google.com/group/cdr-stats