Using Asternic Stats PRO"
Tested on Issabel call center box.
1> edit the file
/etc/sysconfig/asterniclog
change it to:
OPTIONS="-u qstatsUser -p qstatsPassw0rd -d qstats -h localhost -l /var/log/asterisk/queue_log -c -t /usr/local/parselog/myscript.php --daemon"
Create file
/usr/local/parselog/myscript.php
Put this in the file:
(alter $mailto, $subject and $headers to reflect specifics to your email system
(alter $mailto, $subject and $headers to reflect specifics to your email system
#!/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);
exec("grep $uniq /var/log/asterisk/queue_log | grep ABANDON | tail -n 1 | cut -d \| -f 8",$waittime);
$waittime = implode('',$waittime);
if($waittime<6) {
// Ignoring short abandon
exit;
}
$agents = extract_members($return);
$agent_string = '';
foreach($agents as $state=>$agentsinstate) {
$agent_string .= "Agents $state: ". implode(",",$agentsinstate)."\n";
}
$ringnoanswer = array_unique($ringnoanswer);
$ringno_string = implode(",",$ringnoanswer);
$text = "Call from $clid[0] on queue $queue was abandoned at $formatted_date after $waittime seconds wait.\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);
exec("grep $uniq /var/log/asterisk/queue_log | grep EXITWITHTIMEOUT | tail -n 1 | cut -d \| -f 8",$waittime);
$waittime = implode('',$waittime);
if($waittime<6) {
// Ignoring short timeout
exit;
}
$agents = extract_members($return);
$agent_string = '';
foreach($agents as $state=>$agentsinstate) {
$agent_string .= "Agents $state: ". implode(",",$agentsinstate)."\n";
}
$ringnoanswer = array_unique($ringnoanswer);
$ringno_string = implode(",",$ringnoanswer);
$text = "Call from $clid[0] on queue $queue timed out at $formatted_date after $waittime seconds.\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]);
if(preg_match("/Not in use/i",$linea)) {
$ret['available'][] = $agente;
} else if(preg_match("/unavailable/i",$linea)) {
$ret['unavailable'][] = $agente;
} else if(preg_match("/busy/i",$linea)) {
$ret['busy'][] = $agente;
} else if(preg_match("/in use/i",$linea)) {
$ret['in use'][] = $agente;
} else if(preg_match("/invalid/i",$linea)) {
$ret['invalid'][] = $agente;
} else {
$ret['unknown'][] = $agente;
}
}
}
return $ret;
}
Save the file
Change the owner of the file to asterisk
chown asterisk:asterisk /usr/local/parselog/myscript.php
Make the file executable
chmod +755 /usr/local/parselog/myscript.php
Restart the Asternic process
service asterniclog restart
Make a test call to the queue, then abandon. It will send an email
You can watch the mail log if you have problems, it can help you solve smtp messages
tail -100f /var/log/maillog
No comments:
Post a Comment
Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.