14. Separating audio recordings in a daily folder

If you have full access to the configuration files of your Asterisk system, it is easy to save audio recordings in separate folders each day; this helps QueueMetrics in finding them quickly and makes them way more manageable (e.g. for archiving).

You can obtain this result by the following dialplan code:

. . . .
exten => 999,n,Set(MONITOR_FILENAME=/recordings/${STRFTIME(${EPOCH},,%Y-%m/%d)}/audio-${UNIQUEID}.wav)
exten => 999,n,Queue(778,t,,)
. . . .

Asterisk should automatically create missing directories, as needed.

A problem arises if you do not have control of where your recordings will be stored, possibly because you use a GUI that does not help you with this.

It is still possible to obtain the same result by making the folder where Asterisk writes its own recordings a symbolic link that actually points to the folder that recordings are stored under. This makes implementing various NAS solutions simple to do.

The following steps will archive voice recordings by month and day as subfolders of the folder /recordings, as in the following example:

/recordings/2010-11/15/audio-123456.789.wav

This way audio is archived by month and day.

[Warning]Warning

If you use such a solution with an external NAS, make sure you do not overload the I/O and network capacities of your server. If e.g. you record all traffic, you are going to double the Asterisk-related network bandwidth used, so beware.

14.1. Prerequisites

  • A working Asterisk, sending recordings to /var/spool/asterisk/monitor
  • An external NAS or disk volume, mounted on /recordings where you will store all audio data.
  • A working QueueMetrics system

14.2. Archiving script

The following script will create the destination directory and a symbolic link to it.

Before running it, copy the contents of /var/spool/asterisk/monitor to a different location, or they will be lost.

#!/bin/bash

VAR1=`date +%Y-%m`
VAR2=`date +%d`

mkdir /recordings/$VAR1/
mkdir /recordings/$VAR1/$VAR2
chown -R asterisk.asterisk /recordings/

cd /var/spool/asterisk/
rm -rf monitor
ln -s /recordings/$VAR1/$VAR2 monitor
chown -R asterisk.asterisk monitor

Make the script executable.

[Warning]Warning

All data you should have in /var/spool/asterisk/monitor will be deleted on the first run of this script; so make a copy first!

The script should run every day at midnight by using a cron job.

14.3. Changes to QueueMetrics

Edit the configuration.properties file as follows:

# This is the name of the class that finds recordings. See documentation.
audio.server=it.loway.app.queuemetrics.callListen.listeners.LocalFilesByDay

#The top level directory where monitored calls are held.
#Do NOT forget to add the ending slash.
default.monitored_calls=/recordings/%YY-%MM/%DD/

Log off and on again. You should see the file search being much quicker now.

14.4. Making older files accessible

If you have older files, they will not be accessible unless you separate and save them by day as newer files. This can be more or less easy based on the format of your file names.

If you need it, Loway offers a file separation service that can be performed remotely in order to obtain the desired result.