From f5084b74663eabb8bbfb359b38c4419fa8f63506 Mon Sep 17 00:00:00 2001 From: mattf Date: Sat, 10 Jan 2009 10:15:21 +0000 Subject: [PATCH] added another queue_log cleanup process to AST_cleanup_agent_log.pl this one for negative call time, usually caused by time sync issues between servers in a multi-server setup git-svn-id: svn://192.168.202.10@1030 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/bin/AST_cleanup_agent_log.pl | 458 ++++++++++++--------- 1 file changed, 270 insertions(+), 188 deletions(-) diff --git a/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl b/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl index fa5ae7c1..c81dc524 100644 --- a/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl +++ b/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl @@ -41,6 +41,7 @@ if (length($ARGV[0])>1) print " (without time flag will do logs from 150-10 minutes ago)\n"; print " [-last-24hours] = will clean up logs for the last 24 hours only\n"; print " [-more-than-24hours] = will clean up logs older than 24 hours only\n"; + print " [-skip-queue-log-inserts] = will skip only the queue_log missing record checks\n"; print " [-q] = quiet, no output\n"; print " [-test] = test\n"; print " [-debug] = verbose debug messages\n"; @@ -84,6 +85,11 @@ if (length($ARGV[0])>1) $TWENTYFOUR_OLDER=1; if ($Q < 1) {print "\n----- MORE THAN 24 HOURS OLD ONLY -----\n\n";} } + if ($args =~ /-skip-queue-log-inserts/i) + { + $skip_queue_log_inserts=1; + if ($Q < 1) {print "\n----- SKIPPING QUEUE_LOG INSERTS -----\n\n";} + } } } else @@ -383,128 +389,62 @@ if ($enable_queuemetrics_logging > 0) if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} - $COMPLETEinsert=0; - $COMPLETEupdate=0; - $CONNECTinsert=0; - $noCONNECT=0; - $noCALLSTATUS=0; - $noCOMPLETEinsert=0; - ##### grab all queue_log entries for ENTERQUEUE verb to validate - $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb='ENTERQUEUE' $QM_SQL_time order by time_id;"; - $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; - $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; - $EQ_records=$sthB->rows; - if ($DB) {print "ENTERQUEUE Records: $EQ_records|$stmtB|\n\n";} - $h=0; - while ($EQ_records > $h) - { - @aryB = $sthB->fetchrow_array; - $time_id[$h] = "$aryB[0]"; - $call_id[$h] = "$aryB[1]"; - $queue[$h] = "$aryB[2]"; - $agent[$h] = "$aryB[3]"; - $verb[$h] = "$aryB[4]"; - $serverid[$h] = "$aryB[5]"; - $h++; - } - $sthB->finish(); - $h=0; - while ($EQ_records > $h) + + if ($skip_queue_log_inserts < 1) { - ##### find the CONNECT details for calls that were sent to agents - $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid,data1 FROM queue_log where verb='CONNECT' and call_id='$call_id[$h]' $QM_SQL_time;"; + $COMPLETEinsert=0; + $COMPLETEupdate=0; + $CONNECTinsert=0; + $noCONNECT=0; + $noCALLSTATUS=0; + $noCOMPLETEinsert=0; + ############################################################## + ##### grab all queue_log entries for ENTERQUEUE verb to validate + $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb='ENTERQUEUE' $QM_SQL_time order by time_id;"; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; - $CQ_records=$sthB->rows; - if ($CQ_records > 0) + $EQ_records=$sthB->rows; + if ($DB) {print "ENTERQUEUE Records: $EQ_records|$stmtB|\n\n";} + $h=0; + while ($EQ_records > $h) { @aryB = $sthB->fetchrow_array; - $Ctime_id[$h] = "$aryB[0]"; - $Ccall_id[$h] = "$aryB[1]"; - $Cqueue[$h] = "$aryB[2]"; - $Cagent[$h] = "$aryB[3]"; - $Cverb[$h] = "$aryB[4]"; - $Cserverid[$h] = "$aryB[5]"; - $Cdata1[$h] = "$aryB[6]"; + $time_id[$h] = "$aryB[0]"; + $call_id[$h] = "$aryB[1]"; + $queue[$h] = "$aryB[2]"; + $agent[$h] = "$aryB[3]"; + $verb[$h] = "$aryB[4]"; + $serverid[$h] = "$aryB[5]"; + $h++; } $sthB->finish(); - if ( ($CQ_records > 0) && ($Ctime_id[$h] > 1000) ) + $h=0; + while ($EQ_records > $h) { - ##### find the CALLSTATUS details for calls that were dispositioned by an agent - $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb='CALLSTATUS' and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; + ##### find the CONNECT details for calls that were sent to agents + $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid,data1 FROM queue_log where verb='CONNECT' and call_id='$call_id[$h]' $QM_SQL_time;"; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; - $SQ_records=$sthB->rows; - if ($SQ_records > 0) + $CQ_records=$sthB->rows; + if ($CQ_records > 0) { @aryB = $sthB->fetchrow_array; - $Stime_id[$h] = "$aryB[0]"; - $Scall_id[$h] = "$aryB[1]"; - $Squeue[$h] = "$aryB[2]"; - $Sagent[$h] = "$aryB[3]"; - $Sverb[$h] = "$aryB[4]"; - $Sserverid[$h] = "$aryB[5]"; + $Ctime_id[$h] = "$aryB[0]"; + $Ccall_id[$h] = "$aryB[1]"; + $Cqueue[$h] = "$aryB[2]"; + $Cagent[$h] = "$aryB[3]"; + $Cverb[$h] = "$aryB[4]"; + $Cserverid[$h] = "$aryB[5]"; + $Cdata1[$h] = "$aryB[6]"; } $sthB->finish(); - if ( ($SQ_records > 0) && ($Stime_id[$h] > 1000) ) + if ( ($CQ_records > 0) && ($Ctime_id[$h] > 1000) ) { - ##### check if there is a COMPLETEAGENT or COMPLETECALLER record for this call_id - $stmtB = "SELECT count(*) FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; - $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; - $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; - $MQ_records=$sthB->rows; - if ($MQ_records > 0) - { - @aryB = $sthB->fetchrow_array; - $COMPLETEcount[$h] = "$aryB[0]"; - } - $sthB->finish(); - if ($COMPLETEcount[$h] > 0) - { - ##### check that the queue is set properly - $stmtB = "SELECT count(*) FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]' and queue='$queue[$h]';"; - $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; - $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; - $QQ_records=$sthB->rows; - if ($QQ_records > 0) - { - @aryB = $sthB->fetchrow_array; - $COMPLETEqueue[$h] = "$aryB[0]"; - } - $sthB->finish(); - if ($COMPLETEqueue[$h] < 1) - { - $stmtB = "UPDATE queue_log SET queue='$queue[$h]' where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; - if ($TEST < 1) - { - $Baffected_rows = $dbhB->do($stmtB); - } - if ($DB) {print "MCRI: $Baffected_rows|$stmtB|\n";} - $COMPLETEupdate++; - } - } - else - { - ##### insert a COMPLETEAGENT record for this call into the queue_log - $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Scall_id[$h]',queue='$Squeue[$h]',agent='$Sagent[$h]',verb='COMPLETEAGENT',data1='$Cdata1[$h]',data2='$CALLtime[$h]',data3='1',serverid='$Sserverid[$h]';"; - if ($TEST < 1) - { - $Baffected_rows = $dbhB->do($stmtB); - } - if ($DB) {print "MCRI: $Baffected_rows|$stmtB|\n";} - $COMPLETEinsert++; - } - } - else - { - if ($DB) {print "NO CALLSTATUS: $Ctime_id[$h]|$Ccall_id[$h]|$Cagent[$h] \n";} - $noCALLSTATUS++; - ##### find the COMPLETE details for calls that were connected to an agent - $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; + ##### find the CALLSTATUS details for calls that were dispositioned by an agent + $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb='CALLSTATUS' and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; $SQ_records=$sthB->rows; @@ -522,115 +462,189 @@ if ($enable_queuemetrics_logging > 0) if ( ($SQ_records > 0) && ($Stime_id[$h] > 1000) ) { - ##### insert a CALLSTATUS record for this call into the queue_log - $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Scall_id[$h]',queue='$Cqueue[$h]',agent='$Sagent[$h]',verb='CALLSTATUS',data1='PU',serverid='$Sserverid[$h]';"; - if ($TEST < 1) + ##### check if there is a COMPLETEAGENT or COMPLETECALLER record for this call_id + $stmtB = "SELECT count(*) FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $MQ_records=$sthB->rows; + if ($MQ_records > 0) { - $Baffected_rows = $dbhB->do($stmtB); + @aryB = $sthB->fetchrow_array; + $COMPLETEcount[$h] = "$aryB[0]"; + } + $sthB->finish(); + if ($COMPLETEcount[$h] > 0) + { + ##### check that the queue is set properly + $stmtB = "SELECT count(*) FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]' and queue='$queue[$h]';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $QQ_records=$sthB->rows; + if ($QQ_records > 0) + { + @aryB = $sthB->fetchrow_array; + $COMPLETEqueue[$h] = "$aryB[0]"; + } + $sthB->finish(); + if ($COMPLETEqueue[$h] < 1) + { + $stmtB = "UPDATE queue_log SET queue='$queue[$h]' where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; + if ($TEST < 1) + { + $Baffected_rows = $dbhB->do($stmtB); + } + if ($DB) {print "MCRI: $Baffected_rows|$stmtB|\n";} + $COMPLETEupdate++; + } + } + else + { + ##### insert a COMPLETEAGENT record for this call into the queue_log + $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Scall_id[$h]',queue='$Squeue[$h]',agent='$Sagent[$h]',verb='COMPLETEAGENT',data1='$Cdata1[$h]',data2='$CALLtime[$h]',data3='1',serverid='$Sserverid[$h]';"; + if ($TEST < 1) + { + $Baffected_rows = $dbhB->do($stmtB); + } + if ($DB) {print "MCRI: $Baffected_rows|$stmtB|\n";} + $COMPLETEinsert++; } - if ($DB) {print "MCSI: $Baffected_rows|$stmtB|\n";} - $CONNECTinsert++; } else { - $old_call_sec = ($secX - 10800); - if ($Ctime_id[$h] < $old_call_sec) + if ($DB) {print "NO CALLSTATUS: $Ctime_id[$h]|$Ccall_id[$h]|$Cagent[$h] \n";} + $noCALLSTATUS++; + ##### find the COMPLETE details for calls that were connected to an agent + $stmtB = "SELECT time_id,call_id,queue,agent,verb,serverid FROM queue_log where verb IN('COMPLETEAGENT','COMPLETECALLER') and call_id='$call_id[$h]' and agent='$Cagent[$h]';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $SQ_records=$sthB->rows; + if ($SQ_records > 0) { - $search_sec_BEGIN = ($Ctime_id[$h] - 3600); - $search_sec_END = ($Ctime_id[$h] + 3600); - $search_lead_id = substr($call_id[$h], 11, 9); - $search_lead_id = ($search_lead_id + 0); - $VALuser = $Cagent[$h]; - $VALuser =~ s/Agent\///gi; + @aryB = $sthB->fetchrow_array; + $Stime_id[$h] = "$aryB[0]"; + $Scall_id[$h] = "$aryB[1]"; + $Squeue[$h] = "$aryB[2]"; + $Sagent[$h] = "$aryB[3]"; + $Sverb[$h] = "$aryB[4]"; + $Sserverid[$h] = "$aryB[5]"; + } + $sthB->finish(); - ##### insert a COMPLETEAGENT record for this call into the queue_log - $stmtA = "SELECT pause_epoch,wait_epoch,talk_epoch,dispo_epoch,status FROM vicidial_agent_log where lead_id='$search_lead_id' and user='$VALuser' and pause_epoch > \"$search_sec_BEGIN\" and pause_epoch < \"$search_sec_END\" order by pause_epoch desc;"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArows=$sthA->rows; - $rec_count=0; - while ($sthArows > $rec_count) + if ( ($SQ_records > 0) && ($Stime_id[$h] > 1000) ) + { + ##### insert a CALLSTATUS record for this call into the queue_log + $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Scall_id[$h]',queue='$Cqueue[$h]',agent='$Sagent[$h]',verb='CALLSTATUS',data1='PU',serverid='$Sserverid[$h]';"; + if ($TEST < 1) { - @aryA = $sthA->fetchrow_array; - $VALpause = "$aryA[0]"; - $VALwait = "$aryA[1]"; - $VALtalk = "$aryA[2]"; - $VALdispo = "$aryA[3]"; - $VALstatus ="$aryA[4]"; - $queuemetrics_log_id = "$aryA[5]"; - $queuemetrics_eq_prepend = "$aryA[6]"; - $rec_count++; + $Baffected_rows = $dbhB->do($stmtB); } - $sthA->finish(); - - if ($rec_count > 0) + if ($DB) {print "MCSI: $Baffected_rows|$stmtB|\n";} + $CONNECTinsert++; + } + else + { + $old_call_sec = ($secX - 10800); + if ($Ctime_id[$h] < $old_call_sec) { - $Stime_id[$h]=0; - if ($VALwait >= $Ctime_id[$h]) {$Stime_id[$h] = $VALwait;} - if ($VALtalk >= $Ctime_id[$h]) {$Stime_id[$h] = $VALtalk;} - if ($VALdispo >= $Ctime_id[$h]) {$Stime_id[$h] = $VALdispo;} - if ($Stime_id[$h] < 1) {$Stime_id[$h] = ($time_id[$h] + 1);} - $VALstatus =~ s/ //gi; - if ( ($VALstatus =~ /NULL/i) || (length($VALstatus<1)) ) {$VALstatus='ERI';} + $search_sec_BEGIN = ($Ctime_id[$h] - 3600); + $search_sec_END = ($Ctime_id[$h] + 3600); + $search_lead_id = substr($call_id[$h], 11, 9); + $search_lead_id = ($search_lead_id + 0); + $VALuser = $Cagent[$h]; + $VALuser =~ s/Agent\///gi; ##### insert a COMPLETEAGENT record for this call into the queue_log - $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Ccall_id[$h]',queue='$Cqueue[$h]',agent='$Cagent[$h]',verb='COMPLETEAGENT',data1='$Cdata1[$h]',data2='$CALLtime[$h]',data3='1',serverid='$Cserverid[$h]';"; - if ($TEST < 1) + $stmtA = "SELECT pause_epoch,wait_epoch,talk_epoch,dispo_epoch,status FROM vicidial_agent_log where lead_id='$search_lead_id' and user='$VALuser' and pause_epoch > \"$search_sec_BEGIN\" and pause_epoch < \"$search_sec_END\" order by pause_epoch desc;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $rec_count=0; + while ($sthArows > $rec_count) { - $Baffected_rows = $dbhB->do($stmtB) or die "ERROR: $stmtB" . DBI->errstr; + @aryA = $sthA->fetchrow_array; + $VALpause = "$aryA[0]"; + $VALwait = "$aryA[1]"; + $VALtalk = "$aryA[2]"; + $VALdispo = "$aryA[3]"; + $VALstatus ="$aryA[4]"; + $queuemetrics_log_id = "$aryA[5]"; + $queuemetrics_eq_prepend = "$aryA[6]"; + $rec_count++; } - if ($DB) {print "MNCI: $Baffected_rows|$stmtB|$TEST\n";} - - ##### insert a CALLSTATUS record for this call into the queue_log - $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Ccall_id[$h]',queue='$Cqueue[$h]',agent='$Cagent[$h]',verb='CALLSTATUS',data1='$VALstatus',serverid='$Cserverid[$h]';"; - if ($TEST < 1) + $sthA->finish(); + + if ($rec_count > 0) { - $Baffected_rows = $dbhB->do($stmtB) or die "ERROR: $stmtB" . DBI->errstr; - } - if ($DB) {print "MNCI: $Baffected_rows|$stmtB|$TEST\n";} - $noCOMPLETEinsert++; + $Stime_id[$h]=0; + if ($VALwait >= $Ctime_id[$h]) {$Stime_id[$h] = $VALwait;} + if ($VALtalk >= $Ctime_id[$h]) {$Stime_id[$h] = $VALtalk;} + if ($VALdispo >= $Ctime_id[$h]) {$Stime_id[$h] = $VALdispo;} + if ($Stime_id[$h] < 1) {$Stime_id[$h] = ($time_id[$h] + 1);} + $VALstatus =~ s/ //gi; + if ( ($VALstatus =~ /NULL/i) || (length($VALstatus<1)) ) {$VALstatus='ERI';} + ##### insert a COMPLETEAGENT record for this call into the queue_log + $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Ccall_id[$h]',queue='$Cqueue[$h]',agent='$Cagent[$h]',verb='COMPLETEAGENT',data1='$Cdata1[$h]',data2='$CALLtime[$h]',data3='1',serverid='$Cserverid[$h]';"; + if ($TEST < 1) + { + $Baffected_rows = $dbhB->do($stmtB) or die "ERROR: $stmtB" . DBI->errstr; + } + if ($DB) {print "MNCI: $Baffected_rows|$stmtB|$TEST\n";} + + ##### insert a CALLSTATUS record for this call into the queue_log + $CALLtime[$h] = ($Stime_id[$h] - $time_id[$h]); + $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$Stime_id[$h]',call_id='$Ccall_id[$h]',queue='$Cqueue[$h]',agent='$Cagent[$h]',verb='CALLSTATUS',data1='$VALstatus',serverid='$Cserverid[$h]';"; + if ($TEST < 1) + { + $Baffected_rows = $dbhB->do($stmtB) or die "ERROR: $stmtB" . DBI->errstr; + } + if ($DB) {print "MNCI: $Baffected_rows|$stmtB|$TEST\n";} + $noCOMPLETEinsert++; + + } } } } } - } - else - { - if ($DBX) {print "NO CONNECT: $time_id[$h]|$call_id[$h]|$queue[$h] \n";} - $noCONNECT++; - } - if ($DB) - { - ($Dsec,$Dmin,$Dhour,$Dmday,$Dmon,$Dyear,$Dwday,$Dyday,$Disdst) = localtime($time_id[$h]); - $Dyear = ($Dyear + 1900); - $Dmon++; - if ($Dmon < 10) {$Dmon = "0$Dmon";} - if ($Dmday < 10) {$Dmday = "0$Dmday";} - if ($Dhour < 10) {$Dhour = "0$Dhour";} - if ($Dmin < 10) {$Dmin = "0$Dmin";} - if ($Dsec < 10) {$Dsec = "0$Dsec";} - $DBSQLdate = "$Dyear-$Dmon-$Dmday $Dhour:$Dmin:$Dsec"; + else + { + if ($DBX) {print "NO CONNECT: $time_id[$h]|$call_id[$h]|$queue[$h] \n";} + $noCONNECT++; + } + if ($DB) + { + ($Dsec,$Dmin,$Dhour,$Dmday,$Dmon,$Dyear,$Dwday,$Dyday,$Disdst) = localtime($time_id[$h]); + $Dyear = ($Dyear + 1900); + $Dmon++; + if ($Dmon < 10) {$Dmon = "0$Dmon";} + if ($Dmday < 10) {$Dmday = "0$Dmday";} + if ($Dhour < 10) {$Dhour = "0$Dhour";} + if ($Dmin < 10) {$Dmin = "0$Dmin";} + if ($Dsec < 10) {$Dsec = "0$Dsec";} + $DBSQLdate = "$Dyear-$Dmon-$Dmday $Dhour:$Dmin:$Dsec"; - if ($h =~ /0$/) {$k='+';} - if ($h =~ /1$/) {$k='|';} - if ($h =~ /2$/) {$k='/';} - if ($h =~ /3$/) {$k='-';} - if ($h =~ /4$/) {$k="\\";} - if ($h =~ /5$/) {$k='|';} - if ($h =~ /6$/) {$k='/';} - if ($h =~ /7$/) {$k='-';} - if ($h =~ /8$/) {$k="\\";} - if ($h =~ /9$/) {$k='0';} - print STDERR "$k $noCONNECT $noCALLSTATUS $COMPLETEinsert|$COMPLETEupdate $CONNECTinsert $noCOMPLETEinsert $h/$EQ_records $DBSQLdate|$time_id[$h] $Ctime_id[$h]|$CQ_records $Stime_id[$h]|$SQ_records $call_id[$h]|$COMPLETEcount[$h]\r"; + if ($h =~ /0$/) {$k='+';} + if ($h =~ /1$/) {$k='|';} + if ($h =~ /2$/) {$k='/';} + if ($h =~ /3$/) {$k='-';} + if ($h =~ /4$/) {$k="\\";} + if ($h =~ /5$/) {$k='|';} + if ($h =~ /6$/) {$k='/';} + if ($h =~ /7$/) {$k='-';} + if ($h =~ /8$/) {$k="\\";} + if ($h =~ /9$/) {$k='0';} + print STDERR "$k $noCONNECT $noCALLSTATUS $COMPLETEinsert|$COMPLETEupdate $CONNECTinsert $noCOMPLETEinsert $h/$EQ_records $DBSQLdate|$time_id[$h] $Ctime_id[$h]|$CQ_records $Stime_id[$h]|$SQ_records $call_id[$h]|$COMPLETEcount[$h]\r"; + } + $h++; } - $h++; } + + ####################################################################### ##### grab all queue_log entries with more than one COMPLETE verb to clean up $stmtB = "SELECT call_id, count(*) FROM queue_log WHERE verb IN('COMPLETEAGENT','COMPLETECALLER','TRANSFER') GROUP BY call_id HAVING count(*)>1 ORDER BY count(*) DESC;"; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; @@ -657,6 +671,74 @@ if ($enable_queuemetrics_logging > 0) $h++; } + + ########################################################################## + ##### grab all queue_log COMPLETEAGENT entries with negative call time to clean up + $stmtB = "SELECT call_id, time_id FROM queue_log WHERE verb IN('COMPLETEAGENT') and data2 < '0';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $XN_records=$sthB->rows; + if ($DB) {print "Negative COMPLETEAGENT Records: $XN_records|$stmtB|\n\n";} + $h=0; + while ($XN_records > $h) + { + @aryB = $sthB->fetchrow_array; + $CNcall_id[$h] = "$aryB[0]"; + $CNtime_id[$h] = "$aryB[1]"; + $h++; + } + $sthB->finish(); + + $h=0; + while ($XN_records > $h) + { + ### Get time of CONNECT + $stmtB = "SELECT time_id FROM queue_log WHERE verb IN('CONNECT') and call_id='$CNcall_id[$h]';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $XNC_records=$sthB->rows; + if ($XNC_records < 1) + {print "ERROR! No CONNECT record for $CNcall_id[$h] $CNtime_id[$h]";} + else + { + @aryB = $sthB->fetchrow_array; + $CCNtime_id[$h] = "$aryB[0]"; + $sthB->finish(); + + ### Get time of CALLSTATUS + $stmtB = "SELECT time_id FROM queue_log WHERE verb IN('CALLSTATUS') and call_id='$CNcall_id[$h]';"; + $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; + $sthB->execute or die "executing: $stmtB ", $dbhB->errstr; + $XNS_records=$sthB->rows; + if ($XNS_records < 1) + {print "ERROR! No CALLSTATUS record for $CNcall_id[$h] $CNtime_id[$h]";} + else + { + @aryB = $sthB->fetchrow_array; + $CSNtime_id[$h] = "$aryB[0]"; + $sthB->finish(); + + if ($CSNtime_id[$h] < $CCNtime_id[$h]) + { + ##### update CALLSTATUS record to CONNECT time_id + $stmtB = "UPDATE queue_log SET time_id='$CCNtime_id[$h]' WHERE call_id='$CNcall_id[$h]' and verb IN('CALLSTAUTS') LIMIT 1;"; + if ($TEST < 1) {$Baffected_rows = $dbhB->do($stmtB); } + if ($DB) {print "CALLSTATUS time_id Record Updated: $Baffected_rows|$stmtB|\n\n";} + } + } + if ($CNtime_id[$h] < $CCNtime_id[$h]) + { + ##### update COMPLETEAGENT record to CONNECT time_id and 0 data2 + $stmtB = "UPDATE queue_log SET time_id='$CCNtime_id[$h]',data2='0' WHERE call_id='$CNcall_id[$h]' and verb IN('COMPLETEAGENT') LIMIT 1;"; + if ($TEST < 1) {$Baffected_rows = $dbhB->do($stmtB); } + if ($DB) {print "COMPLETEAGENT time_id Record Updated: $Baffected_rows|$stmtB|\n";} + if ($DB) {print "Debug: $CCNtime_id[$h]|$CSNtime_id[$h]|$CNtime_id[$h]|$CNcall_id[$h]|\n\n";} + } + } + $h++; + } + + $dbhB->disconnect(); }