From bfd1d6d40f0221123b036f8c0358d700b9929aaf Mon Sep 17 00:00:00 2001 From: mattf Date: Thu, 19 Aug 2021 12:38:48 +0000 Subject: [PATCH] Added vicidial_inbound_caller_codes logging to inbound call routing script git-svn-id: svn://192.168.202.10@3495 3d104415-ff17-0410-8863-d5cf3c621b8a --- agi/agi-VDAD_ALL_inbound.agi | 24 +++++++++ bin/ADMIN_archive_log_tables.pl | 83 ++++++++++++++++++++++++++++++ extras/MySQL_AST_CREATE_tables.sql | 17 +++++- extras/upgrade_2.14.sql | 17 ++++++ 4 files changed, 140 insertions(+), 1 deletion(-) diff --git a/agi/agi-VDAD_ALL_inbound.agi b/agi/agi-VDAD_ALL_inbound.agi index 04016e71..d9d03cf4 100644 --- a/agi/agi-VDAD_ALL_inbound.agi +++ b/agi/agi-VDAD_ALL_inbound.agi @@ -245,6 +245,7 @@ # 210325-2200 - Added populate_lead_comments option # 210609-0941 - Added drop_call_seconds_override option # 210804-0711 - Fix for closing time action issue #1321 +# 210819-0029 - Added vicidial_inbound_caller_codes logging # $script = 'agi-VDAD_ALL_inbound.agi'; @@ -492,6 +493,9 @@ if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\ if ( (!$callerid) or ($callerid =~ /unknown/) ) {$callerid = $calleridname;} } +$prev_callerid = $callerid; +if ($calleridname =~ /^J\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/) + {$prev_callerid = $calleridname;} ##### find out if this call is already in the vicidial_log_extended table #$VLEcount=0; @@ -1772,6 +1776,11 @@ if ( ( ( ( ($hm < $ct_default_start) || ($hm > $ct_default_stop) ) && ($hm >= $c $dbhP=$dbhA; $mysql_count='02145'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; if ($AGILOG) {$agi_string = "-- AH VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;} $VLEcount++; + + $stmtA = "INSERT INTO vicidial_inbound_caller_codes set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$NACqueryCID',prev_caller_code='$prev_callerid',group_id='$channel_group';"; + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "-- AH VICC insert: |$affected_rows|\n|$stmtA|"; &agi_output;} } if ($enable_drop_lists > 0) @@ -2345,6 +2354,11 @@ if ($VLEcount < 1) $dbhP=$dbhA; $mysql_count='02147'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; if ($AGILOG) {$agi_string = "-- ENTER QUEUE VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;} $VLEcount++; + + $stmtA = "INSERT INTO vicidial_inbound_caller_codes set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$callerid',prev_caller_code='$prev_callerid',group_id='$channel_group';"; + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "-- ENTER QUEUE VICC insert: |$affected_rows|\n|$stmtA|"; &agi_output;} } @@ -4730,6 +4744,11 @@ while ( ($drop_timer <= $DROP_TIME) && ($wait_in_queue > 0) && ($MCdrop_override $dbhP=$dbhA; $mysql_count='02146'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; if ($AGILOG) {$agi_string = "-- ACFLTR VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;} $VLEcount++; + + $stmtA = "INSERT INTO vicidial_inbound_caller_codes set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$NACqueryCID',prev_caller_code='$prev_callerid',group_id='$channel_group';"; + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "-- ACFLTR VICC insert: |$affected_rows|\n|$stmtA|"; &agi_output;} } if ($enable_drop_lists > 0) @@ -8581,6 +8600,11 @@ sub no_agent_no_queue_process $dbhP=$dbhA; $mysql_count='02146'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; if ($AGILOG) {$agi_string = "-- NANQUE VLE insert: |$affected_rows|\n|$stmtA|"; &agi_output;} $VLEcount++; + + $stmtA = "INSERT INTO vicidial_inbound_caller_codes set uniqueid='$uniqueid',server_ip='$VARserver_ip',call_date='$now_date',lead_id = '$insert_lead_id',caller_code='$NACqueryCID',prev_caller_code='$prev_callerid',group_id='$channel_group';"; + $affected_rows = $dbhA->do($stmtA); + $dbhP=$dbhA; $mysql_count='02XXX'; $MEL_aff_rows=$affected_rows; &mysql_error_logging; + if ($AGILOG) {$agi_string = "-- NANQUE VICC insert: |$affected_rows|\n|$stmtA|"; &agi_output;} } if ($enable_drop_lists > 0) diff --git a/bin/ADMIN_archive_log_tables.pl b/bin/ADMIN_archive_log_tables.pl index 956edc4d..4535139a 100644 --- a/bin/ADMIN_archive_log_tables.pl +++ b/bin/ADMIN_archive_log_tables.pl @@ -61,6 +61,7 @@ # 201107-2206 - Added optional park_log archiving # 210317-2104 - Added vicidial_agent_visibility_log archiving # 210407-2023 - Added vicidial_peer_event_log archiving +# 210819-0826 - Added vicidial_inbound_caller_codes archiving # $CALC_TEST=0; @@ -856,6 +857,35 @@ if (!$T) $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; } ##### END vicidial_xfer_log_archive trim processing ##### + + ##### BEGIN vicidial_inbound_caller_codes_archive trim processing ##### + $stmtA = "SELECT count(*) from vicidial_inbound_caller_codes_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $vicidial_inbound_caller_codes_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "Trimming vicidial_inbound_caller_codes_archive table... ($vicidial_inbound_caller_codes_archive_count)\n";} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_inbound_caller_codes_archive WHERE call_date < '$del_time';"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_inbound_caller_codes_archive table \n";} + + $stmtA = "optimize table vicidial_inbound_caller_codes_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### END vicidial_inbound_caller_codes_archive trim processing ##### } if (!$Q) {print "Trim process complete, exiting...\n";} @@ -1675,6 +1705,59 @@ if (!$T) } + ##### vicidial_inbound_caller_codes + $stmtA = "SELECT count(*) from vicidial_inbound_caller_codes;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $vicidial_inbound_caller_codes_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from vicidial_inbound_caller_codes_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $vicidial_inbound_caller_codes_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing vicidial_inbound_caller_codes table... ($vicidial_inbound_caller_codes_count|$vicidial_inbound_caller_codes_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO vicidial_inbound_caller_codes_archive SELECT * from vicidial_inbound_caller_codes;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_inbound_caller_codes_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + if ($wipe_all > 0) + {$stmtA = "DELETE FROM vicidial_inbound_caller_codes;";} + else + {$stmtA = "DELETE FROM vicidial_inbound_caller_codes WHERE call_date < '$del_time';";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_inbound_caller_codes table \n";} + + $stmtA = "optimize table vicidial_inbound_caller_codes;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $stmtA = "optimize table vicidial_inbound_caller_codes_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + + ##### vicidial_log_extended $stmtA = "SELECT count(*) from vicidial_log_extended;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; diff --git a/extras/MySQL_AST_CREATE_tables.sql b/extras/MySQL_AST_CREATE_tables.sql index 2cf50d9c..02f7f663 100644 --- a/extras/MySQL_AST_CREATE_tables.sql +++ b/extras/MySQL_AST_CREATE_tables.sql @@ -4665,6 +4665,19 @@ KEY `start_date` (`start_date`), KEY `khomp_id` (`khomp_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +CREATE TABLE vicidial_inbound_caller_codes ( +uniqueid VARCHAR(50) NOT NULL, +server_ip VARCHAR(15), +call_date DATETIME, +group_id VARCHAR(20) NOT NULL, +lead_id INT(9) UNSIGNED, +caller_code VARCHAR(30) NOT NULL, +prev_caller_code VARCHAR(40) NOT NULL, +index (uniqueid), +index (call_date), +unique index cicc_cd (caller_code, uniqueid) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -4923,6 +4936,8 @@ CREATE TABLE vicidial_agent_visibility_log_archive LIKE vicidial_agent_visibilit CREATE TABLE vicidial_peer_event_log_archive LIKE vicidial_peer_event_log; ALTER TABLE vicidial_peer_event_log_archive MODIFY peer_event_id INT(9) UNSIGNED NOT NULL; +CREATE TABLE vicidial_inbound_caller_codes_archive LIKE vicidial_inbound_caller_codes; + GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; @@ -5006,4 +5021,4 @@ INSERT INTO vicidial_settings_containers(container_id,container_notes,container_ UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1640',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1641',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/extras/upgrade_2.14.sql b/extras/upgrade_2.14.sql index 1f70c7d6..83c0a517 100644 --- a/extras/upgrade_2.14.sql +++ b/extras/upgrade_2.14.sql @@ -1782,3 +1782,20 @@ UPDATE system_settings SET db_schema_version='1639',db_schema_update_date=NOW() ALTER TABLE vicidial_campaigns ADD cid_group_id_two VARCHAR(20) default '---DISABLED---'; UPDATE system_settings SET db_schema_version='1640',db_schema_update_date=NOW() where db_schema_version < 1640; + +CREATE TABLE vicidial_inbound_caller_codes ( +uniqueid VARCHAR(50) NOT NULL, +server_ip VARCHAR(15), +call_date DATETIME, +group_id VARCHAR(20) NOT NULL, +lead_id INT(9) UNSIGNED, +caller_code VARCHAR(30) NOT NULL, +prev_caller_code VARCHAR(40) NOT NULL, +index (uniqueid), +index (call_date), +unique index cicc_cd (caller_code, uniqueid) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_inbound_caller_codes_archive LIKE vicidial_inbound_caller_codes; + +UPDATE system_settings SET db_schema_version='1641',db_schema_update_date=NOW() where db_schema_version < 1641;