2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Added process_log table to database

Log process data to a separate table for speed and better display (don't have to do too many updates)
Updated VoIP watching process to more gracefully handle socket timeouts/errors
This commit is contained in:
azammitdcarf
2011-02-17 03:36:18 +00:00
parent 614647435f
commit e1357712ce
7 changed files with 80 additions and 40 deletions

View File

@@ -59,7 +59,7 @@ function update_callback($buffer)
{ {
global $process_id; global $process_id;
process_append_data($process_id,"<p>" . $buffer . "</p>"); process_append_data($process_id,$buffer);
return ""; //empty buffer return ""; //empty buffer
} }

View File

@@ -70,7 +70,7 @@ if ($p)
kill_process($p); kill_process($p);
} }
xhtml_head(T_("Monitor system wide case sorting"),true,false,false,false,false,true); xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css"),false,false,false,true);
print "<h1>" . T_("Running process:") . " $p</h1>"; print "<h1>" . T_("Running process:") . " $p</h1>";
@@ -84,16 +84,25 @@ if ($p)
print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a></p>"; print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a></p>";
} }
print process_get_data($p); $d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
} }
else else
{ {
xhtml_head(T_("Monitor system wide case sorting")); xhtml_head(T_("Monitor system wide case sorting"),true,array("../css/table.css"));
print "<h2>" . T_("Monitor system wide case sorting") . "</h2>"; print "<h2>" . T_("Monitor system wide case sorting") . "</h2>";
print "<p><a href='?watch=watch'>" . T_("Click here to enable and begin system wide case sorting") . "</a></p>"; print "<p><a href='?watch=watch'>" . T_("Click here to enable and begin system wide case sorting") . "</a></p>";
print "<p>" . T_("System wide case sorting is periodically (via SYSTEM_SORT_MINUTES configuration directive) sorting cases on a system wide basis instead of finding the most appropriate case each time an operator requests a new case. This may increase performance where there are a large number of cases or complex quotas in place. If you are not experiencing any performance problems, it is not recommended to use this feature.") . "</p>"; print "<p>" . T_("System wide case sorting is periodically (via SYSTEM_SORT_MINUTES configuration directive) sorting cases on a system wide basis instead of finding the most appropriate case each time an operator requests a new case. This may increase performance where there are a large number of cases or complex quotas in place. If you are not experiencing any performance problems, it is not recommended to use this feature.") . "</p>";
print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>"; print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>";
print process_get_last_data(2); $d = process_get_last_data(2);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
} }
xhtml_foot(); xhtml_foot();

View File

@@ -54,7 +54,7 @@ function update_callback($buffer)
{ {
global $process_id; global $process_id;
process_append_data($process_id,"<p>" . $buffer . "</p>"); process_append_data($process_id,$buffer);
return ""; //empty buffer return ""; //empty buffer
} }
@@ -92,7 +92,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
//Make sure that the system knows we are system sorting //Make sure that the system knows we are system sorting
set_setting('systemsort',true); set_setting('systemsort',true);
print date("Y-m-d H:i") . " : " . T_("Sorting cases"); print T_("Sorting cases");
$time_start = microtime(true); $time_start = microtime(true);

View File

@@ -70,7 +70,7 @@ if ($p)
kill_process($p); kill_process($p);
} }
xhtml_head(T_("Monitor VoIP Process"),true,false,false,false,false,true); xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css"),false,false,false,true);
print "<h1>" . T_("Running process:") . " $p</h1>"; print "<h1>" . T_("Running process:") . " $p</h1>";
@@ -86,15 +86,23 @@ if ($p)
print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a> ". T_("(requires activity on the VoIP Server to take effect)") . "</p>"; print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a> ". T_("(requires activity on the VoIP Server to take effect)") . "</p>";
} }
print process_get_data($p); $d = process_get_data($p);
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
} }
else else
{ {
xhtml_head(T_("Monitor VoIP Process")); xhtml_head(T_("Monitor VoIP Process"),true,array("../css/table.css"));
print "<h2>" . T_("Monitor VoIP Process") . "</h2>"; print "<h2>" . T_("Monitor VoIP Process") . "</h2>";
print "<p><a href='?watch=watch'>" . T_("Click here to begin monitoring the VoIP Process") . "</a></p>"; print "<p><a href='?watch=watch'>" . T_("Click here to begin monitoring the VoIP Process") . "</a></p>";
print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>"; print "<h2>" . T_("Outcome of last process run (if any)") . "</h2>";
print process_get_last_data(); $d = process_get_last_data();
if ($d !== false)
{
xhtml_table($d,array('process_log_id','datetime','data'),array(T_("Log id"), T_("Date"), T_("Log entry")));
}
} }
xhtml_foot(); xhtml_foot();

View File

@@ -453,6 +453,15 @@ CREATE TABLE `process` (
-- -------------------------------------------------------- -- --------------------------------------------------------
CREATE TABLE `process_log` (
`process_log_id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`process_id` BIGINT NOT NULL ,
`datetime` DATETIME NOT NULL ,
`data` TEXT NOT NULL ,
INDEX ( `process_id` )
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE=utf8_unicode_ci;
-- --
-- Table structure for table `questionnaire` -- Table structure for table `questionnaire`
-- --

View File

@@ -188,9 +188,8 @@ function process_append_data($process_id,$data)
$data = $db->qstr($data,get_magic_quotes_gpc()); $data = $db->qstr($data,get_magic_quotes_gpc());
$sql = "UPDATE `process` $sql = "INSERT INTO `process_log` (process_log_id,process_id,datetime,data)
SET `data` = CONCAT(`data`, $data) VALUES (NULL,'$process_id',NOW(),$data)";
WHERE `process_id` = '$process_id'";
$db->Execute($sql); $db->Execute($sql);
@@ -208,16 +207,17 @@ function process_get_data($process_id)
{ {
global $db; global $db;
$sql = "SELECT `data` $sql = "SELECT process_log_id,datetime,data
FROM `process` FROM `process_log`
WHERE `process_id` = '$process_id'"; WHERE `process_id` = '$process_id'
ORDER BY process_log_id DESC";
$rs = $db->GetRow($sql); $rs = $db->GetAll($sql);
if (!empty($rs)) if (!empty($rs))
return $rs['data']; return $rs;
return ""; return false;
} }
/** /**
@@ -231,7 +231,7 @@ function process_get_last_data($type = 1)
{ {
global $db; global $db;
$sql = "SELECT `data` $sql = "SELECT process_id
FROM `process` FROM `process`
WHERE type = '$type' WHERE type = '$type'
ORDER BY `process_id` DESC ORDER BY `process_id` DESC
@@ -240,9 +240,9 @@ function process_get_last_data($type = 1)
$rs = $db->GetRow($sql); $rs = $db->GetRow($sql);
if (!empty($rs)) if (!empty($rs))
return $rs['data']; return process_get_data($rs['process_id']);
return ""; return false;
} }
?> ?>

View File

@@ -326,7 +326,7 @@ class voip {
return false; return false;
} }
stream_set_timeout($this->socket, 1); // stream_set_timeout($this->socket, 1);
$q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: "; $q = "Action: Login\r\nUsername: $user\r\nSecret: $pass\r\nEvents: ";
@@ -395,11 +395,14 @@ class voipWatch extends voip {
function dbReconnect() function dbReconnect()
{ {
global $db; global $db;
//keep reconnecting to the db so it doesn't time out if (!$db->IsConnected())
$db = newADOConnection(DB_TYPE); {
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); //keep reconnecting to the db so it doesn't time out
$db->SetFetchMode(ADODB_FETCH_ASSOC); $db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
}
} }
@@ -413,7 +416,7 @@ class voipWatch extends voip {
{ {
global $db; global $db;
$sql = "SELECT l.call_id $sql = "SELECT l.call_id, c.case_id
FROM operator AS o FROM operator AS o
JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON JOIN (`case` AS c, `call_attempt` AS ca, `call` AS l) ON
( c.current_operator_id = o.operator_id ( c.current_operator_id = o.operator_id
@@ -426,10 +429,14 @@ class voipWatch extends voip {
$rs = $db->GetRow($sql); $rs = $db->GetRow($sql);
$call_id =0; $call_id =0;
$case_id =0;
if (!empty($rs)) if (!empty($rs))
{
$call_id =$rs['call_id']; $call_id =$rs['call_id'];
$case_id =$rs['case_id'];
}
return $call_id; return array($call_id,$case_id);
} }
@@ -511,10 +518,15 @@ class voipWatch extends voip {
$this->updateAllExtensionStatus(); $this->updateAllExtensionStatus();
$in = true;
$time = time();
//Watch for events //Watch for events
do do
{ {
if (!$this->isConnected() || $this->socket === false){ if (!$this->isConnected() || $this->socket === false || $in === FALSE){
fclose($this->socket);
print(T_("Disconnected") . "\n"); print(T_("Disconnected") . "\n");
$this->connect(VOIP_SERVER,VOIP_ADMIN_USER,VOIP_ADMIN_PASS,true); $this->connect(VOIP_SERVER,VOIP_ADMIN_USER,VOIP_ADMIN_PASS,true);
if ($this->isConnected()) print (T_("Reconnected") . "\n"); if ($this->isConnected()) print (T_("Reconnected") . "\n");
@@ -522,6 +534,7 @@ class voipWatch extends voip {
$in = fgets($this->socket, 4096); $in = fgets($this->socket, 4096);
//print "IN: $in\n"; //print "IN: $in\n";
/** /**
@@ -536,10 +549,10 @@ class voipWatch extends voip {
*/ */
if (eregi("Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) if (eregi("Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{ {
$call_id = $this->getCallId($regs[1]); list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0) if ($call_id != 0)
{ {
print T_("Ringing") . T_(" Extension ") . $regs[1] . "\n"; print T_("Ringing") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,2); $this->setState($call_id,2);
} }
} }
@@ -548,10 +561,10 @@ class voipWatch extends voip {
*/ */
else if (eregi("Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) else if (eregi("Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{ {
$call_id = $this->getCallId($regs[1]); list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0) if ($call_id != 0)
{ {
print T_("Answered") . T_(" Extension ") . $regs[1] . "\n"; print T_("Answered") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,3); $this->setState($call_id,3);
} }
} }
@@ -560,10 +573,10 @@ class voipWatch extends voip {
*/ */
else if (eregi("Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs)) else if (eregi("Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)",$line,$regs))
{ {
$call_id = $this->getCallId($regs[1]); list($call_id,$case_id) = $this->getCallId($regs[1]);
if ($call_id != 0) if ($call_id != 0)
{ {
print T_("Hangup") . T_(" Extension ") . $regs[1] . "\n"; print T_("Hangup") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id=$case_id\">$case_id</a>\n";
$this->setState($call_id,4,true); $this->setState($call_id,4,true);
} }
} }
@@ -589,7 +602,7 @@ class voipWatch extends voip {
//print $line . "\n\n"; //print $line . "\n\n";
$line = ""; $line = "";
} }
else else if ($in !== FALSE)
{ {
/** /**
* Append the lines to the message if we are not yet at the end of one * Append the lines to the message if we are not yet at the end of one
@@ -601,10 +614,11 @@ class voipWatch extends voip {
@flush(); @flush();
if ($process_id) if ($process_id && ((time() - $time) > 10))
{ {
$this->dbReconnect(); $this->dbReconnect();
$this->keepWatching = !is_process_killed($process_id); $this->keepWatching = !is_process_killed($process_id);
$time = time();
} }
} while ($this->keepWatching); } while ($this->keepWatching);