How can we help you?

How to send an email when a call is abandoned or times out
Posted by: Nicolás Gudiño Posted on: Dec-2nd, 2015 10:46

Since Asternic Stats PRO version 2.1.0, there is a new option in the asterniclog service to run custom scripts whenever the queue_log file is updated. This can be useful if you want to perform some task whenever a certain event is recorded in queue_log.

The command line option for specifying that script is -t and should be followed by the full path of your custom script.

That script will be executed any time something is written in the queue_log file, you can add logic into that script to perform any kind of action like sending an email.

As an example, in /etc/sysconfig/asterniclog you can add the parameter like this:

OPTIONS="-u qstatsUser -p qstatsPassw0rd -d qstats -h localhost -l /var/log/asterisk/queue_log -c -t /usr/local/parselog/myscript.php --daemon"

Then write a script /usr/local/parselog/myscript.php that sends an email:

#!/usr/bin/php
<?php
$mailto = "your@mail.com";
$subject = "Call Center Alert";
$headers = 'From: webmaster@callcenter.com' . "\r\n" . 'Reply-To: webmaster@callcenter.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

$date = $argv[1];
$queue = $argv[2];
$agent = $argv[3];
$event = $argv[4];
$uniq = $argv[5];
$text = "";

$formatted_date = gmdate("Y-m-d\TH:i:s\Z",$date);

if($event == 'ABANDON') {
exec("/usr/sbin/asterisk -rx 'queue show $queue'",$return);
exec("grep $uniq /var/log/asterisk/queue_log | grep ENTERQUEUE | cut -d \| -f 7",$clid);
exec("grep $uniq /var/log/asterisk/queue_log | grep RINGNOANSWER | cut -d \| -f 4",$ringnoanswer);
$agents = extract_members($return);
$agent_string = implode(",",$agents);
$ringnoanswer = array_unique($ringnoanswer);
$ringno_string = implode(",",$ringnoanswer);

$text = "Call from $clid[0] on queue $queue was abandoned at $formatted_date\n";
$text.= "Available agents at time of event:\n$agent_string\n\n";
if($ringno_string<>'') {
$text.= "Agents that failed to answer were:\n$ringno_string\n\n";
}
}
if($event == 'EXITWITHTIMEOUT') {
exec("/usr/sbin/asterisk -rx 'queue show $queue'",$return);
exec("grep $uniq /var/log/asterisk/queue_log | grep ENTERQUEUE | cut -d \| -f 7",$clid);
exec("grep $uniq /var/log/asterisk/queue_log | grep RINGNOANSWER | cut -d \| -f 4",$ringnoanswer);
$agents = extract_members($return);
$agent_string = implode(",",$agents);
$ringnoanswer = array_unique($ringnoanswer);
$ringno_string = implode(",",$ringnoanswer);

$text = "Call from $clid[0] on queue $queue timed out at $formatted_date\n";
$text.= "Available agents at time of event:\n$agent_string\n\n";
if($ringno_string<>'') {
$text.= "Agents that failed to answer were:\n$ringno_string\n\n";
}
}

if($text <> '') {
mail($mailto, $subject, $text, $headers);
}

function extract_members($data) {
$ret = array();
foreach($data as $linea) {
if(substr($linea,0,5)==" ") {
$partes = preg_split("/\(/",$linea);
$agente = trim($partes[0]);
$ret[] = $agente;
}
}
return $ret;
}


Finally restart the asterniclog service with:


service asterniclog restart


The script can be used to perform any kind of tasks, not only sending emails. It is up to your imagination.




Nicolás Gudiño Apr-5th, 2016 17:06

All versions are available always in www.asternic.net/download.php

Leave a comment