FreePBX

Automatically Delete Call Recordings in FreePBX

A simple script to delete call recordings. Note that this has been designed to work hand-in-hand with our other script, that coverts the recordings to MP3 to save space: FreePBX – convert WAV call recordings to MP3

You can easily modify the script to delete call recordings that are in WAV format, or for different periods of time, by altering the “*.mp3” to “*.wav” and by modifying the +365 to +30 +60 +90 etc.


#!/bin/bash
# A script to delete old FreePBX call recordings
# Version 1 - 2016/12/08
#
# Changelog
# v1 - Initial Version
#
# Copyright Jaytag Computer Limited 2016 - www.jaytag.co.uk
#
# You may use or modify this script as you wish as long as this copyright
# message remains. Redistribution prohibited.
#
# Find all recordings older than 365 days and delete
find /var/spool/asterisk/monitor -name "*.mp3" -mtime +365 -delete

read more
DamianAutomatically Delete Call Recordings in FreePBX

FreePBX – convert WAV call recordings to MP3 v2

An updated version of our script to bulk convert wav call recordings to mp3 as mentioned here.

This version may be redistributed freely, as long as the copyright message remains.
#!/bin/bash
# A Script to Convert FreePBX call recordings from WAV to MP3
# Also updates the CDR database, for correct downloads through the web UI
# Version 2 - 2016/04/15
#
# Changelog
# v2 - Skip broken files (but show an error message)
# v1 - Initial version
#
# Copyright Jaytag Computer Limited 2016 - www.jaytag.co.uk
#
# You may use or modify this script as you wish as long as this copyright
# message remains. Redistribution is permitted.

# Set the Asterisk Recording Directory
recorddir="/var/spool/asterisk/monitor/"

# Start the Loop
for wavfile in `find $recorddir -name \*.wav`; do

# Make Variables from the WAV file names
wavfilenopath="$(echo $wavfile | sed 's/.*\///')"
mp3file="$(echo $wavfile | sed s/".wav"/".mp3"/)"
mp3filenopath="$(echo $mp3file | sed 's/.*\///')"

# Convert the WAV files to MP3, exit with an error message if the conversion fails
nice lame -b 16 -m m -q 9-resample "$wavfile" "$mp3file" && rm -frv $wavfile || echo "$wavfile encoding failed"

# Update the CDR Database, only if conversion is sucessful
if [ -e "$mp3file" ] then
mysql -u root -s -N -D asteriskcdrdb<<<"UPDATE cdr SET recordingfile='$mp3filenopath' WHERE recordingfile = '$wavfilenopath'"
echo "DBUPDATE -------------------------------------------------------"
echo "DBUPDATE - $wavfilenopath changed to $mp3filenopath in CDR DB"
echo "DBUPDATE -------------------------------------------------------"
fi

# On-Screen display of variables for debugging/logging
# echo ""
# echo "File -------------------------------------------------------"
# echo "Wav File : " $wavfile
# echo "Wav No Path : " $wavfilenopath
# echo "MP3 File : " $mp3file
# echo "MP3 No Path : " $mp3filenopath
# echo "End File ---------------------------------------------------"
# echo ""

# End the Loop
done

read more
DamianFreePBX – convert WAV call recordings to MP3 v2

Monitoring Asterisk With Observium

On the Asterisk server, ensure xinetd is installed

yum -y install xinetd
service xinetd start

Create an Observium agent for xinetd

nano /etc/xinetd.d/observium_agent

Add this to the file

service app-asterisk
{
type = UNLISTED
port = 36602
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/bin/observium_agent/asterisk

# Don’t be too verbose. Don’t log every check. This might be
# commented out for debugging. If this option is commented out
# the default options will be used for this service.
log_on_success =

disable = no
}

Create the executable that xinetd will call when Observium connects

mkdir /usr/bin/observium_agent
nano /usr/bin/observium_agent/asterisk

Add this to the file

#!/bin/bash

####### Asterisk Telephony Server
if [ -a /usr/sbin/asterisk ] then
echo ‘<<<app-asterisk>>>’
ACTIVECHAN=$(asterisk -rx ‘core show channels’ | grep ‘active channels’ | cut -d’ ‘ -f1)
ACTIVECALL=$(asterisk -rx ‘core show channels’ | grep ‘active call’ | cut -d’ ‘ -f1)
IAXCHANNELS=$(asterisk -rx ‘iax2 show channels’ | grep active | cut -d’ ‘ -f1)
SIPCHANNELS=$(asterisk -rx ‘sip show channels’ | grep active | cut -d’ ‘ -f1)
SIPTOTALPEERS=$(asterisk -rx ‘sip show peers’ | grep ‘sip peers’ | cut -d’ ‘ -f1)
SIPONLINE=$(asterisk -rx ‘sip show peers’ | grep -o ‘[0-9]* online’ | head -1 | cut -d’ ‘ -f1)
IAXTOTALPEERS=$(asterisk -rx ‘iax2 show peers’ | grep ‘iax2 peers’ | cut -d’ ‘ -f1)
IAXONLINE=$(asterisk -rx ‘iax2 show peers’ | grep -o ‘[0-9]* online’ | head -1 | cut -d’ ‘ -f1)

echo “activechan:$ACTIVECHAN”
echo “activecall:$ACTIVECALL”
echo “iaxchannels:$IAXCHANNELS”
echo “sipchannels:$SIPCHANNELS”
echo “sippeers:$SIPTOTALPEERS”
echo “sippeersonline:$SIPONLINE”
echo “iaxpeers:$IAXTOTALPEERS”
echo “iaxpeersonline:$IAXONLINE”

fi

Set the script as executable and restart xinetd

chmod +x /usr/bin/observium_agent/asterisk
service xinetd restart

In Observium, go to the server and select Settings > Properties
Enable Modules > unix-agent
Set Agent Port to 36602 in Agent
Poll the device, and the Asterisk App will appear in the ‘Apps’ section of the device

read more
DamianMonitoring Asterisk With Observium

FreePBX – convert WAV call recordings to MP3

convert-wav-to-mp3

One of our customers recently reported an interesting issue. They were running FreePBX on a machine with a very small amount of hard drive space. Usually, this would not be an issue, as FreePBX can be installed easily onto a small drive, even less than 10GB (I have a moment of reflection now, thinking that actually 10GB is massive!!)

In any case, when you start recording calls on a system, the free space is quickly eaten up.

Within FreePBX, there is no way to set the call recording to MP3, and as a result, large WAV files are created.

The solution? Convert them to MP3, and update the CDR database to reflect the changed filenames – so that if you wish to download the call recordings from the web UI, the links are correct.

Prerequisites:

  • LAME

The script looks through /var/spool/asterisk/monitor where the call files are stored, and then converts the WAV files to MP3. The WAV files are then deleted.

This version is designed for a one-time-run from the command line. You will of course need to modify the mysql -u portion if you wish to make the update changes as another user.

Exercise caution! If you do not want to delete the WAV files, delete “&& rm -frv $wavfile” from the below script.


#!/bin/bash
# A Script to Convert FreePBX call recordings from WAV to MP3
# Also updates the CDR database, for correct downloads through the web UI
# Version 1 - 2015/11/15
#
# Copyright Jaytag Computer Limited 2015 - www.jaytag.co.uk
#
# You may use or modify this script as you wish as long as this copyright
# message remains. Redistribution prohibited.
# Set the Asterisk Recording Directory
recorddir="/var/spool/asterisk/monitor"
# Start the Loop, store the path of each WAV call recording as variable $wavfile
for wavfile in `find $recorddir -name \*.wav`; do
# Make Variables from the WAV file names, stripping the file path with sed
wavfilenopath="$(echo $wavfile | sed 's/.*\///')"
mp3file="$(echo $wavfile | sed s/".wav"/".mp3"/)"
mp3filenopath="$(echo $mp3file | sed 's/.*\///')"
# Convert the WAV files to MP3, exit with an error message if the conversion fails
nice lame -b 16 -m m -q 9-resample "$wavfile" "$mp3file" && rm -frv $wavfile || { echo "$wavfile encoding failed" ; exit 1; }
# Update the CDR Database
mysql -u root -s -N -D asteriskcdrdb<<<"UPDATE cdr SET recordingfile='$mp3filenopath' WHERE recordingfile = '$wavfilenopath'"
# On-Screen display of variables for debugging/logging
# echo ""
# echo "File -------------------------------------------------------"
# echo "Wav File : " $wavfile
# echo "Wav No Path : " $wavfilenopath
# echo "MP3 File : " $mp3file
# echo "MP3 No Path : " $mp3filenopath
# echo "End File ---------------------------------------------------"
# echo ""
# End the Loop
done

Edit 15/06/2016: There is a new version of the script here.

read more
DamianFreePBX – convert WAV call recordings to MP3

Manually set FreePBX timezone

Check here for the correct timezone: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones​
SSH into the server
Run the following, with the relevant TZ database timezone. In this example, Europe/London
​ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
Then, edit /ect/sysconfig/clock
nano /etc/sysconfig/clock
Change the line to the correct TZ timezone:
ZONE="Europe/London"
Save the file
Run to check all is now correct:
date
Reboot the server

read more
DamianManually set FreePBX timezone

No DAHDI modules on the system. Not starting

You need to retrieve the correct kernel-devel for the kernel of linux you are running, and remake DAHDI from source

SSH onto the machine and run:
uname -r

Note the kernel version.

then, google for kernel-devel (kernel version)
find a suitable download source (i.e. from rpm.pbone.net)

then on the machine
rpm -ivh ftp://ftp.is.co.za/mirror/centos/6.5/updates/x86_64/Packages/kernel-devel-2.6.32-431.1.2.0.1.el6.x86_64.rpm

You can then download DAHDI and make from source:

cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
tar zxvf dahdi-linux-complete-current.tar.gz
cd dahdi-linux-complete-2.9.1.1+2.9.1
make all
make install
make config
/etc/init.d/dahdi restart
chkconfig dahdi on

DAHDI should then work OK​​

read more
DamianNo DAHDI modules on the system. Not starting

cdr_mysql.c:203 mysql_log: Cannot connect to database server localhost: (1045) Access denied for user ‘freepbxuser’@’localhost’ (using password: YES)

When restoring FreePBX from backup, you may find the CDR database is not updated. This is because the cdr_mysql.conf file is not overwritten by the restore, and so the password for the CDR database is incorrect.

You can resolve it like this:

SSH onto the server
nano /etc/freepbx.conf
Find the lines:
$amp_conf['AMPDBUSER']  = 'freepbxuser';
$amp_conf['AMPDBPASS']  = '3098SADFSLa';​​

Copy the password, quit nano
nano /etc/asterisk/cdr_mysql.conf
Insert the password in the apropriate section
Save the file, quit nano​
amportal reload
You may need to restart the server to allow the password to be updated.

read more
Damiancdr_mysql.c:203 mysql_log: Cannot connect to database server localhost: (1045) Access denied for user ‘freepbxuser’@’localhost’ (using password: YES)