Ghost voicemail files

Status
Not open for further replies.

francois

New Member
Oct 3, 2019
26
9
3
56
Hi All,

I implemented a small script that scans recursively the voicemail message files of every domain under freeswitch/storage/voicemail/default and check whether voicemail messages are all present in v_voicemail_messages.

My script show tons of ghost voicemail msg_[uuid].wav files. Fortunately, my maintenance cron job deletes +90 days old files but nevertheless all of this is a bit concerning.

As per the freeswitch log file, the scenario is: voicemail file gets recorded, mwi is sent, extension logs in the voicemail script using *97 and delete the voicemail message. Therefore I suspect freeswitch lua and not fusionpbx php. Obviously, the voicemail message file deletion works most of the time but still some files are not deleted as they should.

So, I added more traces around lua os.remove and looked at the log files to understand what may cause that issue but no error is reported by lua.

Any thougth?

Thanks!

Francois

Here is my sanity script:
function list_dir($root_path, $sub_path, &$index, &$return_array, $recursive = true) {
$path = strlen($sub_path) > 0 ? $root_path.'/'.$sub_path : $root_path;
$files = scandir($path);
foreach($files as $file) {
if (!in_array($file, array(".", "..")))
{
if (is_dir($path.'/'.$file) ) {
if ($recursive) {
list_dir($root_path, (strlen($sub_path) > 0?$sub_path.'/'.$file:$file), $index, $return_array, true);
}
} else {
$return_array[$index]['filename'] = (strlen($sub_path) > 0?$sub_path.'/'.$file:$file);
$return_array[$index]['modified'] = filemtime($path.'/'.$file);
//$return_array[$index]['size'] = filesize($path.'/'.$file);
$index++;
}
}
}
}

//get the voicemail messages from the db
$sql = "SELECT domain_name, v_voicemails.voicemail_id, v_voicemail_messages.* FROM v_voicemail_messages ";
$sql .= "INNER JOIN v_domains ON v_domains.domain_uuid = v_voicemail_messages.domain_uuid ";
$sql .= "INNER JOIN v_voicemails ON v_voicemails.voicemail_uuid = v_voicemail_messages.voicemail_uuid ";
$sql .= "ORDER BY domain_name, v_voicemails.voicemail_id";
$database = new database;
$result = $database->select($sql, null, 'all');

//create an array of message per [domain][voicemail_id]
foreach ($result as &$row) {
$voicemail_array[$row['domain_name']][$row['voicemail_id']][$row['voicemail_message_uuid']] = true;
}

//list files recursively
$index = 0;
$voicemail_files = array();
list_dir('/var/lib/freeswitch/storage/voicemail/default/', '', $index, $voicemail_files, true);

//compare the db against the file system and show ghost files
$i = 0;
foreach ($voicemail_files as &$voicemail_file) {
$parts = explode('/', $voicemail_file['filename']);
if (substr($parts[2], 0, 4) == 'msg_') {
if ($voicemail_array[$parts[0]][$parts[1]]['msg_'.$parts[2].'.wav'] != true) {
echo $i."-".$voicemail_file['filename']."-".date("F d Y H:i:s.", $voicemail_file['modified'])."<br>";
$i++;
}
}
}
 
Status
Not open for further replies.