diff --git a/agc_2-X/branches/agc_2.2.0/bin/AST_VDauto_dial.pl b/agc_2-X/branches/agc_2.2.0/bin/AST_VDauto_dial.pl index cd10af28..ce2c2c69 100644 --- a/agc_2-X/branches/agc_2.2.0/bin/AST_VDauto_dial.pl +++ b/agc_2-X/branches/agc_2.2.0/bin/AST_VDauto_dial.pl @@ -88,6 +88,7 @@ # 91108-2122 - Added LAGGED PAUSEREASON QM entry for lagged agents # 91123-1802 - Added outbound_autodial field, and exception for outbound-only agents on blended campaign # 91213-1856 - Added queue_position to queue_log ABANDON records +# 100327-1359 - Fixed LAGGED issues # @@ -1317,53 +1318,46 @@ while($one_day_interval > 0) &event_logger; } - if ($KLcallerid[$kill_vac] !~ /^M\d\d\d\d\d\d\d\d\d\d/) - { - $stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where callerid='$KLcallerid[$kill_vac]';"; - $Vaffected_rows = $dbhA->do($stmtA); - - if ($Vaffected_rows > 0) - { - $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where callerid='$KLcallerid[$kill_vac]';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArowsML=$sthA->rows; - $lagged_ids=0; - while ($sthArowsML > $lagged_ids) - { - @aryA = $sthA->fetchrow_array; - $MLAGagent_log_id[$lagged_ids] = $aryA[0]; - $MLAGuser[$lagged_ids] = $aryA[1]; - $lagged_ids++; - } - $sthA->finish(); - $lagged_ids=0; - while ($sthArowsML > $lagged_ids) - { - $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$MLAGagent_log_id[$lagged_ids]';"; - $VLaffected_rows = $dbhA->do($stmtA); - - if ($enable_queuemetrics_logging > 0) - { - $secX = time(); - $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") - or die "Couldn't connect to database: " . DBI->errstr; - - if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} - - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$MLAGuser[$lagged_ids]',verb='PAUSEREASON',serverid='$queuemetrics_log_id',data1='LAGGED';"; - $Baffected_rows = $dbhB->do($stmtB); - - $dbhB->disconnect(); - } - - $lagged_ids++; - } - - $event_string = "| dead call vla agent PAUSED $Vaffected_rows|$VLaffected_rows|$CLlead_id|$CLphone_number|$CLstatus|"; - &event_logger; - } - } + # if ($KLcallerid[$kill_vac] !~ /^M\d\d\d\d\d\d\d\d\d\d/) + # { + # $stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where callerid='$KLcallerid[$kill_vac]';"; + # $Vaffected_rows = $dbhA->do($stmtA); + # if ($Vaffected_rows > 0) + # { + # $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where callerid='$KLcallerid[$kill_vac]';"; + # $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + # $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + # $sthArowsML=$sthA->rows; + # $lagged_ids=0; + # while ($sthArowsML > $lagged_ids) + # { + # @aryA = $sthA->fetchrow_array; + # $MLAGagent_log_id[$lagged_ids] = $aryA[0]; + # $MLAGuser[$lagged_ids] = $aryA[1]; + # $lagged_ids++; + # } + # $sthA->finish(); + # $lagged_ids=0; + # while ($sthArowsML > $lagged_ids) + # { + # $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$MLAGagent_log_id[$lagged_ids]';"; + # $VLaffected_rows = $dbhA->do($stmtA); + # if ($enable_queuemetrics_logging > 0) + # { + # $secX = time(); + # $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + # or die "Couldn't connect to database: " . DBI->errstr; + # if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + # $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$MLAGuser[$lagged_ids]',verb='PAUSEREASON',serverid='$queuemetrics_log_id',data1='LAGGED';"; + # $Baffected_rows = $dbhB->do($stmtB); + # $dbhB->disconnect(); + # } + # $lagged_ids++; + # } + # $event_string = "| dead call vla agent PAUSED $Vaffected_rows|$VLaffected_rows|$CLlead_id|$CLphone_number|$CLstatus|"; + # &event_logger; + # } + # } if ( ($enable_queuemetrics_logging > 0) && ($CLstatus =~ /LIVE/) ) { @@ -1776,7 +1770,7 @@ while($one_day_interval > 0) if ($toPAUSEcount > 0) { - $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where server_ip='$server_ip' and last_update_time < '$PDtsSQLdate' and status NOT IN('PAUSED');"; + $stmtA = "SELECT agent_log_id,user,server_ip,campaign_id,user_group from vicidial_live_agents where server_ip='$server_ip' and last_update_time < '$PDtsSQLdate' and status NOT IN('PAUSED');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArowsL=$sthA->rows; @@ -1786,18 +1780,24 @@ while($one_day_interval > 0) @aryA = $sthA->fetchrow_array; $LAGagent_log_id[$lagged_ids] = $aryA[0]; $LAGuser[$lagged_ids] = $aryA[1]; + $LAGserver_ip[$lagged_ids] = $aryA[2]; + $LAGcampaign_id[$lagged_ids] = $aryA[3]; + $LAGuser_group[$lagged_ids] = $aryA[4]; $lagged_ids++; } $sthA->finish(); $lagged_ids=0; while ($sthArowsL > $lagged_ids) { + $secX = time(); $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$LAGagent_log_id[$lagged_ids]';"; $VLaffected_rows = $dbhA->do($stmtA); + $stmtA = "INSERT INTO vicidial_agent_log set event_time='$now_date',server_ip='$LAGserver_ip[$lagged_ids]',campaign_id='$LAGcampaign_id[$lagged_ids]',user_group='$LAGuser_group[$lagged_ids]',user='$LAGuser[$lagged_ids]',pause_epoch='$secX',pause_sec='0',wait_epoch='$secX';"; + $VLaffected_rows = $dbhA->do($stmtA); + if ($enable_queuemetrics_logging > 0) { - $secX = time(); $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") or die "Couldn't connect to database: " . DBI->errstr; diff --git a/agc_2-X/branches/agc_2.2.0/bin/AST_cleanup_agent_log.pl b/agc_2-X/branches/agc_2.2.0/bin/AST_cleanup_agent_log.pl index 25fd77e4..379a621d 100644 --- a/agc_2-X/branches/agc_2.2.0/bin/AST_cleanup_agent_log.pl +++ b/agc_2-X/branches/agc_2.2.0/bin/AST_cleanup_agent_log.pl @@ -24,6 +24,7 @@ # 91210-0609 - Added LOGOFF queue_log correction during live call # 91214-0933 - Added queue_position to queue_log COMPLETE... and ABANDON records # 100203-1110 - Added fix for vicidial_closer_log records with 0 length +# 100327-0926 - Added validation of four agent "sec" fields # # constants @@ -47,7 +48,9 @@ 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 " [-last-30days] = will clean up logs for the last 30 days only\n"; print " [-skip-queue-log-inserts] = will skip only the queue_log missing record checks\n"; + print " [-skip-agent-log-validation] = will skip only the vicidial_agent_log validation\n"; print " [-only-check-agent-login-lags] = will only fix queue_log missing PAUSEREASON records\n"; print " [-only-qm-live-call-check] = will only check the queue_log calls that report as live, in ViciDial\n"; print " [-q] = quiet, no output\n"; @@ -98,6 +101,11 @@ if (length($ARGV[0])>1) $TWENTYFOUR_HOURS=1; if ($Q < 1) {print "\n----- LAST 24 HOURS ONLY -----\n\n";} } + if ($args =~ /-last-30days/i) + { + $THIRTY_DAYS=1; + if ($Q < 1) {print "\n----- LAST 30 DAYS ONLY -----\n\n";} + } if ($args =~ /-more-than-24hours/i) { $TWENTYFOUR_OLDER=1; @@ -108,6 +116,11 @@ if (length($ARGV[0])>1) $skip_queue_log_inserts=1; if ($Q < 1) {print "\n----- SKIPPING QUEUE_LOG INSERTS -----\n\n";} } + if ($args =~ /-skip-agent-log-validation/i) + { + $skip_agent_log_validation=1; + if ($Q < 1) {print "\n----- SKIPPING VICIDIAL_AGENT_LOG VALIDATION -----\n\n";} + } } } else @@ -198,6 +211,24 @@ if ($TWENTYFOUR_OLDER > 0) $QM_SQL_time = "and time_id < $TDtarget"; $QM_SQL_time_H = "and time_id < $TDtarget"; } +if ($THIRTY_DAYS > 0) + { + $TDtarget = ($secX - 2592000); # 30 days in the past + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $TDSQLdate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $VDAD_SQL_time = "and event_time > \"$TDSQLdate\" and event_time < \"$FDSQLdate\""; + $VDCL_SQL_time = "and call_date > \"$TDSQLdate\" and call_date < \"$FDSQLdate\""; + $QM_SQL_time = "and time_id > $TDtarget and time_id < $FDtarget"; + $QM_SQL_time_H = "and time_id > $TDtarget and time_id < $HDtarget"; + } # default path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; @@ -760,6 +791,208 @@ if ($DB) {print STDERR " Bad Closer times recalculated: $affected_rows\n\n"; + + +##### BEGIN vicidial_agent_log sec validation ##### +if ($skip_agent_log_validation < 1) + { + if ($DBX) {print "\n\n";} + if ($DB) {print " - starting validation of vicidial_agent_log sec fields\n";} + $total_corrected_records=0; + $total_scanned_records=0; + $total_pause=0; + $total_wait=0; + $total_talk=0; + $total_dispo=0; + $total_dead=0; + + ### Gather distinct users in vicidial_agent_log during time period + $stmtA = "SELECT distinct user from vicidial_agent_log where user != '' $VDAD_SQL_time;"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsU=$sthA->rows; + + $i=0; + while ($sthArowsU > $i) + { + @aryA = $sthA->fetchrow_array; + $Vuser[$i] = $aryA[0]; + $i++; + } + $sthA->finish(); + + $i=0; + while ($sthArowsU > $i) + { + ### Gather distinct users in vicidial_agent_log during time period + $stmtA = "SELECT agent_log_id,pause_epoch,pause_sec,wait_epoch,wait_sec,talk_epoch,talk_sec,dispo_epoch,dispo_sec,dead_epoch,dead_sec,event_time from vicidial_agent_log where user='$Vuser[$i]' $VDAD_SQL_time;"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsR=$sthA->rows; + $r=0; + $total_Vrecords=0; + @Vagent_log_id = @MT; + @Vpause_epoch = @MT; + @Vpause_sec = @MT; + @Vwait_epoch = @MT; + @Vwait_sec = @MT; + @Vtalk_epoch = @MT; + @Vtalk_sec = @MT; + @Vdispo_epoch = @MT; + @Vdispo_sec = @MT; + @Vdead_epoch = @MT; + @Vdead_sec = @MT; + @Vevent_time = @MT; + + # gather records + while ($sthArowsR > $r) + { + @aryA = $sthA->fetchrow_array; + $Vagent_log_id[$r] = $aryA[0]; + $Vpause_epoch[$r] = $aryA[1]; + $Vpause_sec[$r] = $aryA[2]; + $Vwait_epoch[$r] = $aryA[3]; + $Vwait_sec[$r] = $aryA[4]; + $Vtalk_epoch[$r] = $aryA[5]; + $Vtalk_sec[$r] = $aryA[6]; + $Vdispo_epoch[$r] = $aryA[7]; + $Vdispo_sec[$r] = $aryA[8]; + $Vdead_epoch[$r] = $aryA[9]; + $Vdead_sec[$r] = $aryA[10]; + $Vevent_time[$r] = $aryA[11]; + $r++; + } + $sthA->finish(); + + $total_Vrecords = $r; + $r=0; + while ($sthArowsR > $r) + { + $NVpause_sec=0; + $NVwait_sec=0; + $NVtalk_sec=0; + $NVdispo_sec=0; + $NVdead_sec=0; + $next_r = ($r + 1); + if ($next_r < $total_Vrecords) + {$next_begin_epoch = $Vpause_epoch[$next_r];} + else + {$next_begin_epoch = 0;} + + if ( ($Vwait_epoch[$r] < 1000) || ( ($Vwait_epoch[$r] <= $Vpause_epoch[$r]) && ($Vtalk_epoch[$r] < 1000) && ($Vpause_sec[$r] > 0) ) ) + { + $Vwait_epoch[$r] = $next_begin_epoch; + $NVpause_sec = ($Vwait_epoch[$r] - $Vpause_epoch[$r]); + } + else + { + $NVpause_sec = ($Vwait_epoch[$r] - $Vpause_epoch[$r]); + if ($Vtalk_epoch[$r] < 1000) + { + $Vtalk_epoch[$r] = $next_begin_epoch; + $NVwait_sec = ($Vtalk_epoch[$r] - $Vwait_epoch[$r]); + } + else + { + $NVwait_sec = ($Vtalk_epoch[$r] - $Vwait_epoch[$r]); + if ($Vdispo_epoch[$r] < 1000) + { + $Vdispo_epoch[$r] = $next_begin_epoch; + $NVtalk_sec = ($Vdispo_epoch[$r] - $Vtalk_epoch[$r]); + } + else + { + $NVtalk_sec = ($Vdispo_epoch[$r] - $Vtalk_epoch[$r]); + if ($next_begin_epoch < 1000) + { + $NVdispo_sec = $Vdispo_sec[$r]; + } + else + { + $NVdispo_sec = ($next_begin_epoch - $Vdispo_epoch[$r]); + } + } + } + } + + if ( ($NVpause_sec > 43999) || ($NVpause_sec < 0) ) {$NVpause_sec = 0;} + if ( ($NVwait_sec > 43999) || ($NVwait_sec < 0) ) {$NVwait_sec = 0;} + if ( ($NVtalk_sec > 43999) || ($NVtalk_sec < 0) ) {$NVtalk_sec = 0;} + if ( ($NVdispo_sec > 43999) || ($NVdispo_sec < 0) ) {$NVdispo_sec = 0;} + + $corrections=0; + $corrections_LOG=''; + $corrections_SQL=''; + if ( ($NVpause_sec > $Vpause_sec[$r]) || ($NVpause_sec < $Vpause_sec[$r]) ) + { + $corrections++; + $total_pause++; + $corrections_LOG .= "PAUSE:$NVpause_sec!$Vpause_sec[$r]|"; + $corrections_SQL .= "pause_sec='$NVpause_sec',"; + } + if ( ($NVwait_sec > $Vwait_sec[$r]) || ($NVwait_sec < $Vwait_sec[$r]) ) + { + $corrections++; + $total_wait++; + $corrections_LOG .= "WAIT:$NVwait_sec!$Vwait_sec[$r]|"; + $corrections_SQL .= "wait_sec='$NVwait_sec',"; + } + if ( ($NVtalk_sec > $Vtalk_sec[$r]) || ($NVtalk_sec < $Vtalk_sec[$r]) ) + { + $corrections++; + $total_talk++; + $corrections_LOG .= "TALK:$NVtalk_sec!$Vtalk_sec[$r]|"; + $corrections_SQL .= "talk_sec='$NVtalk_sec',"; + } + if ( ($NVdispo_sec > $Vdispo_sec[$r]) || ($NVdispo_sec < $Vdispo_sec[$r]) ) + { + $corrections++; + $total_dispo++; + $corrections_LOG .= "DISPO:$NVdispo_sec!$Vdispo_sec[$r]|"; + $corrections_SQL .= "dispo_sec='$NVdispo_sec',"; + } + if ($NVtalk_sec < $Vdead_sec[$r]) + { + $corrections++; + $total_dead++; + $corrections_LOG .= "DEAD:$NVtalk_sec!$Vdead_sec[$r]|"; + } + + if ($corrections > 0) + { + $total_corrected_records++; + chop($corrections_SQL); + if ($DB > 0) {print "$Vevent_time[$r] $Vuser[$i] $corrections $Vagent_log_id[$r] $corrections_LOG $corrections_SQL\n";} + $stmtA = "UPDATE vicidial_agent_log set $corrections_SQL where agent_log_id='$Vagent_log_id[$r]';"; + if($DBX){print STDERR "|$stmtA|\n";} + if ($TEST < 1) + { + $affected_rows = $dbhA->do($stmtA); + } + } + + $total_scanned_records++; + $r++; + } + + $i++; + } + + if ($DB) {print " - finished validation of vicidial_agent_log sec fields:\n";} + if ($DB) {print " records scanned/corrected: $total_scanned_records / $total_corrected_records\n";} + if ($DB) {print " PAUSE updates: $total_pause\n";} + if ($DB) {print " WAIT updates: $total_wait\n";} + if ($DB) {print " TALK updates: $total_talk\n";} + if ($DB) {print " DISPO updates: $total_dispo\n";} + if ($DB) {print " DEAD updates: $total_dead\n";} + if ($DB) {print " distinct users: $i\n";} + } +##### END vicidial_agent_log sec validation ##### + + + if ($enable_queuemetrics_logging > 0) { if ($skip_queue_log_inserts < 1) diff --git a/agc_2-X/branches/agc_2.2.0/www/agc/vdc_db_query.php b/agc_2-X/branches/agc_2.2.0/www/agc/vdc_db_query.php index 2ed77a51..a6b31eb1 100644 --- a/agc_2-X/branches/agc_2.2.0/www/agc/vdc_db_query.php +++ b/agc_2-X/branches/agc_2.2.0/www/agc/vdc_db_query.php @@ -2465,7 +2465,7 @@ if ($ACTION == 'manDiaLlookCaLL') if ( ($now_dead_epoch > 1000) and ($now_dead_epoch < $StarTtime) ) {$dead_epochSQL = ",dead_epoch='$StarTtime'";} } - $stmt="UPDATE vicidial_agent_log set wait_sec='$wait_sec',wait_epoch='$StarTtime',talk_epoch='$StarTtime',lead_id='$lead_id' $dead_epochSQL where agent_log_id='$agent_log_id';"; + $stmt="UPDATE vicidial_agent_log set wait_sec='$wait_sec',talk_epoch='$StarTtime',lead_id='$lead_id' $dead_epochSQL where agent_log_id='$agent_log_id';"; if ($format=='debug') {echo "\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00054',$user,$server_ip,$session_name,$one_mysql_log);} diff --git a/agc_2-X/trunk/bin/AST_VDauto_dial.pl b/agc_2-X/trunk/bin/AST_VDauto_dial.pl index 116e4c79..a5546f5d 100644 --- a/agc_2-X/trunk/bin/AST_VDauto_dial.pl +++ b/agc_2-X/trunk/bin/AST_VDauto_dial.pl @@ -89,6 +89,7 @@ # 91123-1802 - Added outbound_autodial field, and exception for outbound-only agents on blended campaign # 91213-1856 - Added queue_position to queue_log ABANDON records # 100309-0551 - Added queuemetrics_loginout option +# 100327-1359 - Fixed LAGGED issues # @@ -1331,53 +1332,46 @@ while($one_day_interval > 0) &event_logger; } - if ($KLcallerid[$kill_vac] !~ /^M\d\d\d\d\d\d\d\d\d\d/) - { - $stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where callerid='$KLcallerid[$kill_vac]';"; - $Vaffected_rows = $dbhA->do($stmtA); - - if ($Vaffected_rows > 0) - { - $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where callerid='$KLcallerid[$kill_vac]';"; - $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; - $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; - $sthArowsML=$sthA->rows; - $lagged_ids=0; - while ($sthArowsML > $lagged_ids) - { - @aryA = $sthA->fetchrow_array; - $MLAGagent_log_id[$lagged_ids] = $aryA[0]; - $MLAGuser[$lagged_ids] = $aryA[1]; - $lagged_ids++; - } - $sthA->finish(); - $lagged_ids=0; - while ($sthArowsML > $lagged_ids) - { - $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$MLAGagent_log_id[$lagged_ids]';"; - $VLaffected_rows = $dbhA->do($stmtA); - - if ($enable_queuemetrics_logging > 0) - { - $secX = time(); - $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") - or die "Couldn't connect to database: " . DBI->errstr; - - if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} - - $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$MLAGuser[$lagged_ids]',verb='PAUSEREASON',serverid='$queuemetrics_log_id',data1='LAGGED';"; - $Baffected_rows = $dbhB->do($stmtB); - - $dbhB->disconnect(); - } - - $lagged_ids++; - } - - $event_string = "| dead call vla agent PAUSED $Vaffected_rows|$VLaffected_rows|$CLlead_id|$CLphone_number|$CLstatus|"; - &event_logger; - } - } + # if ($KLcallerid[$kill_vac] !~ /^M\d\d\d\d\d\d\d\d\d\d/) + # { + # $stmtA = "UPDATE vicidial_live_agents set status='PAUSED',random_id='10' where callerid='$KLcallerid[$kill_vac]';"; + # $Vaffected_rows = $dbhA->do($stmtA); + # if ($Vaffected_rows > 0) + # { + # $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where callerid='$KLcallerid[$kill_vac]';"; + # $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + # $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + # $sthArowsML=$sthA->rows; + # $lagged_ids=0; + # while ($sthArowsML > $lagged_ids) + # { + # @aryA = $sthA->fetchrow_array; + # $MLAGagent_log_id[$lagged_ids] = $aryA[0]; + # $MLAGuser[$lagged_ids] = $aryA[1]; + # $lagged_ids++; + # } + # $sthA->finish(); + # $lagged_ids=0; + # while ($sthArowsML > $lagged_ids) + # { + # $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$MLAGagent_log_id[$lagged_ids]';"; + # $VLaffected_rows = $dbhA->do($stmtA); + # if ($enable_queuemetrics_logging > 0) + # { + # $secX = time(); + # $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") + # or die "Couldn't connect to database: " . DBI->errstr; + # if ($DBX) {print "CONNECTED TO DATABASE: $queuemetrics_server_ip|$queuemetrics_dbname\n";} + # $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$MLAGuser[$lagged_ids]',verb='PAUSEREASON',serverid='$queuemetrics_log_id',data1='LAGGED';"; + # $Baffected_rows = $dbhB->do($stmtB); + # $dbhB->disconnect(); + # } + # $lagged_ids++; + # } + # $event_string = "| dead call vla agent PAUSED $Vaffected_rows|$VLaffected_rows|$CLlead_id|$CLphone_number|$CLstatus|"; + # &event_logger; + # } + # } if ( ($enable_queuemetrics_logging > 0) && ($CLstatus =~ /LIVE/) ) { @@ -1790,7 +1784,7 @@ while($one_day_interval > 0) if ($toPAUSEcount > 0) { - $stmtA = "SELECT agent_log_id,user from vicidial_live_agents where server_ip='$server_ip' and last_update_time < '$PDtsSQLdate' and status NOT IN('PAUSED');"; + $stmtA = "SELECT agent_log_id,user,server_ip,campaign_id,user_group from vicidial_live_agents where server_ip='$server_ip' and last_update_time < '$PDtsSQLdate' and status NOT IN('PAUSED');"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArowsL=$sthA->rows; @@ -1800,18 +1794,24 @@ while($one_day_interval > 0) @aryA = $sthA->fetchrow_array; $LAGagent_log_id[$lagged_ids] = $aryA[0]; $LAGuser[$lagged_ids] = $aryA[1]; + $LAGserver_ip[$lagged_ids] = $aryA[2]; + $LAGcampaign_id[$lagged_ids] = $aryA[3]; + $LAGuser_group[$lagged_ids] = $aryA[4]; $lagged_ids++; } $sthA->finish(); $lagged_ids=0; while ($sthArowsL > $lagged_ids) { + $secX = time(); $stmtA = "UPDATE vicidial_agent_log set sub_status='LAGGED' where agent_log_id='$LAGagent_log_id[$lagged_ids]';"; $VLaffected_rows = $dbhA->do($stmtA); + $stmtA = "INSERT INTO vicidial_agent_log set event_time='$now_date',server_ip='$LAGserver_ip[$lagged_ids]',campaign_id='$LAGcampaign_id[$lagged_ids]',user_group='$LAGuser_group[$lagged_ids]',user='$LAGuser[$lagged_ids]',pause_epoch='$secX',pause_sec='0',wait_epoch='$secX';"; + $VLaffected_rows = $dbhA->do($stmtA); + if ($enable_queuemetrics_logging > 0) { - $secX = time(); $dbhB = DBI->connect("DBI:mysql:$queuemetrics_dbname:$queuemetrics_server_ip:3306", "$queuemetrics_login", "$queuemetrics_pass") or die "Couldn't connect to database: " . DBI->errstr; 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 12c8d893..44ed2b19 100644 --- a/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl +++ b/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl @@ -25,6 +25,7 @@ # 91214-0933 - Added queue_position to queue_log COMPLETE... and ABANDON records # 100203-1110 - Added fix for vicidial_closer_log records with 0 length # 100309-0555 - Added queuemetrics_loginout option +# 100327-0926 - Added validation of four agent "sec" fields # # constants @@ -48,7 +49,9 @@ 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 " [-last-30days] = will clean up logs for the last 30 days only\n"; print " [-skip-queue-log-inserts] = will skip only the queue_log missing record checks\n"; + print " [-skip-agent-log-validation] = will skip only the vicidial_agent_log validation\n"; print " [-only-check-agent-login-lags] = will only fix queue_log missing PAUSEREASON records\n"; print " [-only-qm-live-call-check] = will only check the queue_log calls that report as live, in ViciDial\n"; print " [-q] = quiet, no output\n"; @@ -99,6 +102,11 @@ if (length($ARGV[0])>1) $TWENTYFOUR_HOURS=1; if ($Q < 1) {print "\n----- LAST 24 HOURS ONLY -----\n\n";} } + if ($args =~ /-last-30days/i) + { + $THIRTY_DAYS=1; + if ($Q < 1) {print "\n----- LAST 30 DAYS ONLY -----\n\n";} + } if ($args =~ /-more-than-24hours/i) { $TWENTYFOUR_OLDER=1; @@ -109,6 +117,11 @@ if (length($ARGV[0])>1) $skip_queue_log_inserts=1; if ($Q < 1) {print "\n----- SKIPPING QUEUE_LOG INSERTS -----\n\n";} } + if ($args =~ /-skip-agent-log-validation/i) + { + $skip_agent_log_validation=1; + if ($Q < 1) {print "\n----- SKIPPING VICIDIAL_AGENT_LOG VALIDATION -----\n\n";} + } } } else @@ -199,6 +212,24 @@ if ($TWENTYFOUR_OLDER > 0) $QM_SQL_time = "and time_id < $TDtarget"; $QM_SQL_time_H = "and time_id < $TDtarget"; } +if ($THIRTY_DAYS > 0) + { + $TDtarget = ($secX - 2592000); # 30 days in the past + ($Tsec,$Tmin,$Thour,$Tmday,$Tmon,$Tyear,$Twday,$Tyday,$Tisdst) = localtime($TDtarget); + $Tyear = ($Tyear + 1900); + $Tmon++; + if ($Tmon < 10) {$Tmon = "0$Tmon";} + if ($Tmday < 10) {$Tmday = "0$Tmday";} + if ($Thour < 10) {$Thour = "0$Thour";} + if ($Tmin < 10) {$Tmin = "0$Tmin";} + if ($Tsec < 10) {$Tsec = "0$Tsec";} + $TDSQLdate = "$Tyear-$Tmon-$Tmday $Thour:$Tmin:$Tsec"; + + $VDAD_SQL_time = "and event_time > \"$TDSQLdate\" and event_time < \"$FDSQLdate\""; + $VDCL_SQL_time = "and call_date > \"$TDSQLdate\" and call_date < \"$FDSQLdate\""; + $QM_SQL_time = "and time_id > $TDtarget and time_id < $FDtarget"; + $QM_SQL_time_H = "and time_id > $TDtarget and time_id < $HDtarget"; + } # default path to astguiclient configuration file: $PATHconf = '/etc/astguiclient.conf'; @@ -762,6 +793,208 @@ if ($DB) {print STDERR " Bad Closer times recalculated: $affected_rows\n\n"; + + +##### BEGIN vicidial_agent_log sec validation ##### +if ($skip_agent_log_validation < 1) + { + if ($DBX) {print "\n\n";} + if ($DB) {print " - starting validation of vicidial_agent_log sec fields\n";} + $total_corrected_records=0; + $total_scanned_records=0; + $total_pause=0; + $total_wait=0; + $total_talk=0; + $total_dispo=0; + $total_dead=0; + + ### Gather distinct users in vicidial_agent_log during time period + $stmtA = "SELECT distinct user from vicidial_agent_log where user != '' $VDAD_SQL_time;"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsU=$sthA->rows; + + $i=0; + while ($sthArowsU > $i) + { + @aryA = $sthA->fetchrow_array; + $Vuser[$i] = $aryA[0]; + $i++; + } + $sthA->finish(); + + $i=0; + while ($sthArowsU > $i) + { + ### Gather distinct users in vicidial_agent_log during time period + $stmtA = "SELECT agent_log_id,pause_epoch,pause_sec,wait_epoch,wait_sec,talk_epoch,talk_sec,dispo_epoch,dispo_sec,dead_epoch,dead_sec,event_time from vicidial_agent_log where user='$Vuser[$i]' $VDAD_SQL_time;"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsR=$sthA->rows; + $r=0; + $total_Vrecords=0; + @Vagent_log_id = @MT; + @Vpause_epoch = @MT; + @Vpause_sec = @MT; + @Vwait_epoch = @MT; + @Vwait_sec = @MT; + @Vtalk_epoch = @MT; + @Vtalk_sec = @MT; + @Vdispo_epoch = @MT; + @Vdispo_sec = @MT; + @Vdead_epoch = @MT; + @Vdead_sec = @MT; + @Vevent_time = @MT; + + # gather records + while ($sthArowsR > $r) + { + @aryA = $sthA->fetchrow_array; + $Vagent_log_id[$r] = $aryA[0]; + $Vpause_epoch[$r] = $aryA[1]; + $Vpause_sec[$r] = $aryA[2]; + $Vwait_epoch[$r] = $aryA[3]; + $Vwait_sec[$r] = $aryA[4]; + $Vtalk_epoch[$r] = $aryA[5]; + $Vtalk_sec[$r] = $aryA[6]; + $Vdispo_epoch[$r] = $aryA[7]; + $Vdispo_sec[$r] = $aryA[8]; + $Vdead_epoch[$r] = $aryA[9]; + $Vdead_sec[$r] = $aryA[10]; + $Vevent_time[$r] = $aryA[11]; + $r++; + } + $sthA->finish(); + + $total_Vrecords = $r; + $r=0; + while ($sthArowsR > $r) + { + $NVpause_sec=0; + $NVwait_sec=0; + $NVtalk_sec=0; + $NVdispo_sec=0; + $NVdead_sec=0; + $next_r = ($r + 1); + if ($next_r < $total_Vrecords) + {$next_begin_epoch = $Vpause_epoch[$next_r];} + else + {$next_begin_epoch = 0;} + + if ( ($Vwait_epoch[$r] < 1000) || ( ($Vwait_epoch[$r] <= $Vpause_epoch[$r]) && ($Vtalk_epoch[$r] < 1000) && ($Vpause_sec[$r] > 0) ) ) + { + $Vwait_epoch[$r] = $next_begin_epoch; + $NVpause_sec = ($Vwait_epoch[$r] - $Vpause_epoch[$r]); + } + else + { + $NVpause_sec = ($Vwait_epoch[$r] - $Vpause_epoch[$r]); + if ($Vtalk_epoch[$r] < 1000) + { + $Vtalk_epoch[$r] = $next_begin_epoch; + $NVwait_sec = ($Vtalk_epoch[$r] - $Vwait_epoch[$r]); + } + else + { + $NVwait_sec = ($Vtalk_epoch[$r] - $Vwait_epoch[$r]); + if ($Vdispo_epoch[$r] < 1000) + { + $Vdispo_epoch[$r] = $next_begin_epoch; + $NVtalk_sec = ($Vdispo_epoch[$r] - $Vtalk_epoch[$r]); + } + else + { + $NVtalk_sec = ($Vdispo_epoch[$r] - $Vtalk_epoch[$r]); + if ($next_begin_epoch < 1000) + { + $NVdispo_sec = $Vdispo_sec[$r]; + } + else + { + $NVdispo_sec = ($next_begin_epoch - $Vdispo_epoch[$r]); + } + } + } + } + + if ( ($NVpause_sec > 43999) || ($NVpause_sec < 0) ) {$NVpause_sec = 0;} + if ( ($NVwait_sec > 43999) || ($NVwait_sec < 0) ) {$NVwait_sec = 0;} + if ( ($NVtalk_sec > 43999) || ($NVtalk_sec < 0) ) {$NVtalk_sec = 0;} + if ( ($NVdispo_sec > 43999) || ($NVdispo_sec < 0) ) {$NVdispo_sec = 0;} + + $corrections=0; + $corrections_LOG=''; + $corrections_SQL=''; + if ( ($NVpause_sec > $Vpause_sec[$r]) || ($NVpause_sec < $Vpause_sec[$r]) ) + { + $corrections++; + $total_pause++; + $corrections_LOG .= "PAUSE:$NVpause_sec!$Vpause_sec[$r]|"; + $corrections_SQL .= "pause_sec='$NVpause_sec',"; + } + if ( ($NVwait_sec > $Vwait_sec[$r]) || ($NVwait_sec < $Vwait_sec[$r]) ) + { + $corrections++; + $total_wait++; + $corrections_LOG .= "WAIT:$NVwait_sec!$Vwait_sec[$r]|"; + $corrections_SQL .= "wait_sec='$NVwait_sec',"; + } + if ( ($NVtalk_sec > $Vtalk_sec[$r]) || ($NVtalk_sec < $Vtalk_sec[$r]) ) + { + $corrections++; + $total_talk++; + $corrections_LOG .= "TALK:$NVtalk_sec!$Vtalk_sec[$r]|"; + $corrections_SQL .= "talk_sec='$NVtalk_sec',"; + } + if ( ($NVdispo_sec > $Vdispo_sec[$r]) || ($NVdispo_sec < $Vdispo_sec[$r]) ) + { + $corrections++; + $total_dispo++; + $corrections_LOG .= "DISPO:$NVdispo_sec!$Vdispo_sec[$r]|"; + $corrections_SQL .= "dispo_sec='$NVdispo_sec',"; + } + if ($NVtalk_sec < $Vdead_sec[$r]) + { + $corrections++; + $total_dead++; + $corrections_LOG .= "DEAD:$NVtalk_sec!$Vdead_sec[$r]|"; + } + + if ($corrections > 0) + { + $total_corrected_records++; + chop($corrections_SQL); + if ($DB > 0) {print "$Vevent_time[$r] $Vuser[$i] $corrections $Vagent_log_id[$r] $corrections_LOG $corrections_SQL\n";} + $stmtA = "UPDATE vicidial_agent_log set $corrections_SQL where agent_log_id='$Vagent_log_id[$r]';"; + if($DBX){print STDERR "|$stmtA|\n";} + if ($TEST < 1) + { + $affected_rows = $dbhA->do($stmtA); + } + } + + $total_scanned_records++; + $r++; + } + + $i++; + } + + if ($DB) {print " - finished validation of vicidial_agent_log sec fields:\n";} + if ($DB) {print " records scanned/corrected: $total_scanned_records / $total_corrected_records\n";} + if ($DB) {print " PAUSE updates: $total_pause\n";} + if ($DB) {print " WAIT updates: $total_wait\n";} + if ($DB) {print " TALK updates: $total_talk\n";} + if ($DB) {print " DISPO updates: $total_dispo\n";} + if ($DB) {print " DEAD updates: $total_dead\n";} + if ($DB) {print " distinct users: $i\n";} + } +##### END vicidial_agent_log sec validation ##### + + + if ($enable_queuemetrics_logging > 0) { if ($skip_queue_log_inserts < 1) diff --git a/agc_2-X/trunk/www/agc/vdc_db_query.php b/agc_2-X/trunk/www/agc/vdc_db_query.php index 5f1c08af..b53963b7 100644 --- a/agc_2-X/trunk/www/agc/vdc_db_query.php +++ b/agc_2-X/trunk/www/agc/vdc_db_query.php @@ -2510,7 +2510,7 @@ if ($ACTION == 'manDiaLlookCaLL') if ( ($now_dead_epoch > 1000) and ($now_dead_epoch < $StarTtime) ) {$dead_epochSQL = ",dead_epoch='$StarTtime'";} } - $stmt="UPDATE vicidial_agent_log set wait_sec='$wait_sec',wait_epoch='$StarTtime',talk_epoch='$StarTtime',lead_id='$lead_id' $dead_epochSQL where agent_log_id='$agent_log_id';"; + $stmt="UPDATE vicidial_agent_log set wait_sec='$wait_sec',talk_epoch='$StarTtime',lead_id='$lead_id' $dead_epochSQL where agent_log_id='$agent_log_id';"; if ($format=='debug') {echo "\n";} $rslt=mysql_query($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00054',$user,$server_ip,$session_name,$one_mysql_log);}