PABX criado para pesquisas
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
3.3 KiB

#!/usr/bin/php -q
<?php
require("bd.php");
require("util/util.php");
//declare(ticks = 1);
//register_shutdown_function("QueueRemovePid");
//pcntl_signal(SIGINT, "QueueRemovePid");
$TABELA = "ast_eventos_dacs";
$path = "/var/log/queue_log.log";
$pathPid = "/tmp/queue_log.pid";
$pathScp = "/var/log/scripts";
$pathQueue = "/var/log/asterisk/queue_log";
$pathQueueOrg = "/var/log/asterisk/queue_log.original";
$pathQueueOld = "/var/log/asterisk/queue_log.old";
try {
if (file_exists($pathPid)) {
GeraExcept("Log ja em execucao.");
}
/*
* Cria o arquvo de pid.
*/
file_put_contents($pathPid, getmypid() . "\n");
/*
* Cria diretorio de scripst caso nao exista.
*/
if (!file_exists($pathScp)) {
mkdir($pathScp, 0777, true);
}
/*
* Apagar o queue_log.old
*/
if (file_exists($pathQueueOld)) {
unlink($pathQueueOld);
}
/*
* Renomeia o queue_log e muda as permissoes do arquivo.
*/
exec("mv {$pathQueue} {$pathQueueOld}");
exec("touch {$pathQueue}");
exec("chown --recursive pbx:pbx {$pathQueue}");
exec("chmod --recursive u=rwX,g=rX,o= {$pathQueue}");
exec("asterisk -rx \"logger reload\"");
/*
* Cria uma copia de seguranca do arquivo.
*/
exec("cat {$pathQueueOld} >> {$pathQueueOrg}");
/*
* Eventos tratados no log
*/
$evtAll = array('COMPLETEAGENTRAMAL', 'COMPLETECALLERRAMAL', 'EXITWITHTIMEOUT', 'TIMEOUT', 'CHAMANDO', 'NOANSWER', 'COMPLETAAGENT', 'COMPLETACALLER', 'BUSY', 'ATENDIDA', 'TRANSBORDANDO', 'TRANSBORDADO', 'ABANDON', 'COMPLETEAGENT', 'COMPLETECALLER', 'CONNECT', 'ENTERQUEUE', 'TRANSFER', 'BUSYS', 'NOANSWERS');
/*
* Eventos relacionados ao status das chamadas
*/
$evtCall = array("CHAMANDO", "COMPLETACALLER", "COMPLETAAGENT", "COMPLETEAGENTRAMAL", "COMPLETECALLERRAMAL", "BUSYS", "NOANSWERS");
$handle = fopen($pathQueueOld, 'r');
while (!feof($handle)) {
$linha = trim(@fgets($handle));
$linha .= str_repeat('|', 8 - substr_count($linha,'|'));
list($UID1, $UID2, $FILA, $AGENTE, $EVENTO, $PARAM1, $PARAM2, $PARAM3, $PARAM4) = explode("|", $linha);
/*
* Verifica se o envento esta na lista de acetos.
*/
if (array_search($EVENTO, $evtAll) !== false) {
/*
* Eventos relacionados a chamadas e transferencias recebem um tratamento diferente para os params.
*/
if ($EVENTO == "TRANSFER") {
$PARAM1 = $PARAM3;
} else if (array_search($EVENTO, $evtCall) !== false) {
list($PARAM1, $PARAM2, $PARAM3, $PARAM4) = explode(",", $PARAM1);
}
$query = "insert into $TABELA (uid1,uid2,fila,agente,evento,param1,param2,param3,param4) values ('$UID1','$UID2','$FILA','$AGENTE','$EVENTO','$PARAM1','$PARAM2','$PARAM3','$PARAM4')";
if (!pg_query($dbcon, $query)) {
RaiseExcept("Erro ao atualizar Base de dados: Cmd:[{$query}]");
}
}
}
QueueRemovePid();
} catch (Exception $ex) {
QueueRemovePid();
$log .= sprintf("Script: %s Data: %s\n", $argv[0], date("Y-m-d H:m:i"));
WriteLog($log, $path);
}
exit(0);
function QueueRemovePid() {
global $pathPid;
if (file_exists($pathPid)) {
unlink($pathPid);
}
}