Added experimantal VCA files

git-svn-id: svn://192.168.202.10@3964 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2026-01-12 20:27:40 +00:00
parent c3bc069ff2
commit b90fc612ed
4 changed files with 1530 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,139 @@
#!/usr/bin/perl
#
# VCA_client_settings.pl version 2.14
#
# DESCRIPTION:
#
# Copyright (C) 2026 Michael Cargile, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# 260112-1114 - Inital Build
#
# constants
$DB=0; # Debug flag, set to 0 for no debug messages per minute, can be overridden by CLI flag
$secX = time();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
$i++;
}
if ($args =~ /--help/i)
{
print "Updates the /etc/vca-client.ini file with the values in the VCA_CLIENT_SETTINGS settings container.\n\n";
print "allowed run time options:\n";
print " [-debug] = verbose debug messages\n";
print "\n";
exit;
}
else
{
if ($args =~ /-debug/i)
{
$DB=1; # Debug flag
print "Debug output enabled\n";
}
}
}
else
{
# print "no command line options set\n";
}
### end parsing run-time options ###
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
my $vca_client_ini = '/etc/vca-client.ini';
my $write_config = 0;
my $vca_mod_epoch = (stat($vca_client_ini))[9] or $write_config = 1;
if (( $write_config == 1 ) and ($DB)) { print "$vca_client_ini doesnt exist.\n"; }
if (!$VARDB_port) {$VARDB_port='3306';}
use DBI;
use Sys::Hostname;
my $hostname = hostname();
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### grab the VCA Client Settings from the settings container
$stmtA = "SELECT UNIX_TIMESTAMP(modify_stamp), container_entry from vicidial_settings_containers where container_id = 'VCA_CLIENT_SETTINGS';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
if ($DB) {print "|$stmtA|\n";}
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$rec_count=0;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$vca_container_mod_epoch = $aryA[0];
$vca_container_entry = $aryA[1];
}
$sthA->finish();
if (($write_config == 0) and ($vca_container_mod_epoch > $vca_mod_epoch))
{
$write_config = 1;
if ($DB) { print "VCA_CLIENT_SETTINGS is newer than $vca_client_ini. $vca_container_mod_epoch $vca_mod_epoch\n"; }
}
else
{
if ($DB) { print "VCA_CLIENT_SETTINGS is older than $vca_client_ini. $vca_container_mod_epoch $vca_mod_epoch\n"; }
}
if ($write_config == 1)
{
$vca_container_entry =~ s/HOSTNAME/$hostname/g;
open(my $fh, '>', $vca_client_ini) or die "Could not open file '$vca_client_ini' $!";
print $fh $vca_container_entry;
if ($DB) { print "Writing to $vca_client_ini\n\n$vca_container_entry\n" ; }
close($fh);
}
$dbhA->disconnect();
@@ -0,0 +1,45 @@
CREATE TABLE `vicidial_vca_log` (
`vca_log_id` int(9) unsigned NOT NULL AUTO_INCREMENT,
`analysis_date` datetime DEFAULT NULL,
`call_id` varchar(30) DEFAULT NULL,
`server_ip` varchar(39) NOT NULL,
`uniqueid` varchar(20) DEFAULT NULL,
`channel` varchar(100) DEFAULT NULL,
`amd_status` varchar(10) DEFAULT NULL,
`amd_cause` varchar(30) DEFAULT NULL,
`language` varchar(5) DEFAULT NULL,
`lang_prob` float DEFAULT NULL,
`text` varchar(100) DEFAULT NULL,
`fft_max_mean_ratio` int(9) DEFAULT NULL,
`freq_peaks` varchar(50) DEFAULT NULL,
`total_detection_ms` float DEFAULT NULL,
`total_collection_ms` float DEFAULT NULL,
`collected_audio_ms` float DEFAULT NULL,
`time_to_decision_ms` float DEFAULT NULL,
`last_silence_ms` float DEFAULT NULL,
`nr_ms` float DEFAULT NULL,
`fa_ms` float DEFAULT NULL,
`asr_trans_ms` float DEFAULT NULL,
`asr_seg_ms` float DEFAULT NULL,
`latency_ms` float DEFAULT NULL,
`human_score` int(9) DEFAULT NULL,
`machine_score` int(9) DEFAULT NULL,
`dc_score` int(9) DEFAULT NULL,
`con_num` smallint(6) DEFAULT NULL,
`asr_confidence` float DEFAULT NULL,
`asr_comp_ratio` float DEFAULT NULL,
`rec_url` varchar(255) DEFAULT NULL,
`vca_server_host` varchar(100) DEFAULT NULL,
`vca_server_port` smallint(5) unsigned DEFAULT 0,
`gpu_id` smallint(6) DEFAULT NULL,
PRIMARY KEY (`vca_log_id`),
KEY `channel` (`channel`),
KEY `analysis_date` (`analysis_date`),
KEY `call_id` (`call_id`),
KEY `amd_status` (`amd_status`),
KEY `amd_cause` (`amd_cause`),
KEY `text` (`text`)
) ENGINE=MyISAM AUTO_INCREMENT=164460 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
CREATE TABLE vicidial_vca_log_archive LIKE vicidial_vca_log;
ALTER TABLE vicidial_vca_log_archive MODIFY vca_log_id INT(9) UNSIGNED NOT NULL;
@@ -0,0 +1,288 @@
#!/usr/bin/perl
#
# VCA_log_manage.pl version 2.14
#
# This script is designed to manage the vicidial_vca_log table records, with
# options to archive them and/or purge them at specific intevals.
#
# Place in the crontab and run every month after one in the morning, or whenever
# your server is not busy with other tasks
# 30 1 1 * * /usr/share/astguiclient/VCA_log_manage.pl
#
# Copyright (C) 2026 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 260112-1455 - First version, based on parts of ADMIN_archive_log_tables script
#
$CALC_TEST=0;
$T=0; $TEST=0;
$DB=0; $DBX=0;
$archive_vca_only=0;
$archived_vca_purge_only=0;
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
$i++;
}
if ($args =~ /--help/i)
{
print "allowed run time options:\n";
print " [--days=XX] = number of days to archive past, default is 732(2 years)\n";
print " [--archive-vca-log-only] = OPTIONAL, only archive vicidial_vca_log table then exit\n";
print " [--archived-vca-purge-only] = OPTIONAL, only delete vicidial_vca_log_archive table records then exit\n";
print " [--wipe-all-being-archived] = OPTIONAL, deletes all records from the active table after archiving\n";
print " [--quiet] = quiet\n";
print " [--calc-test] = date calculation test only\n";
print " [--test] = test\n";
print " [--debug] = debug output for some options\n";
print " [--debugX] = extra debug output for some options\n\n";
exit;
}
else
{
if ($args =~ /-quiet/i)
{
$q=1; $Q=1;
}
if ($args =~ /--test/i)
{
$T=1; $TEST=1;
print "\n-----TESTING-----\n\n";
}
if ($args =~ /--debug/i)
{
$DB=1;
print "\n-----DEBUG-----\n\n";
}
if ($args =~ /--debugX/i)
{
$DBX=1;
print "\n-----DEBUG X-----\n\n";
}
if ($args =~ /--calc-test/i)
{
$CALC_TEST=1;
print "\n-----DATE CALCULATION TESTING ONLY-----\n\n";
}
if ($args =~ /--wipe-all-being-archived/i)
{
$wipe_all=1;
print "\n----- WIPE ALL LOG TABLES BEING ARCHIVED: $wipe_all -----\n\n";
}
if ($args =~ /--days=/i)
{
@data_in = split(/--days=/,$args);
$CLIdays = $data_in[1];
$CLIdays =~ s/ .*$//gi;
$CLIdays =~ s/\D//gi;
if ($CLIdays > 999999)
{$CLIdays=730;}
if ($Q < 1)
{print "\n----- DAYS OVERRIDE: $CLIdays -----\n\n";}
}
if ($args =~ /--archive-vca-log-only/i)
{
$archive_vca_only++;
if ($Q < 1)
{print "\n----- ARCHIVE VCA LOG ONLY: |$archive_vca_only| -----\n\n";}
}
if ($args =~ /--archived-vca-purge-only/i)
{
$archived_vca_purge_only++;
if ($Q < 1)
{print "\n----- ARCHIVED VCA LOG PURGE ONLY: |$archived_vca_purge_only| -----\n\n";}
}
}
}
else
{
print "no command line options set\n";
}
### end parsing run-time options ###
if ( (length($CLIdays)<1) || ($CLIdays < 1) )
{
$CLIdays = ($CLImonths * 30.5);
$CLIdays = sprintf("%.0f",$CLIdays);
}
$secX = time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$del_epoch = ($secX - (86400 * $CLIdays)); # X days ago
($RMsec,$RMmin,$RMhour,$RMmday,$RMmon,$RMyear,$RMwday,$RMyday,$RMisdst) = localtime($del_epoch);
$RMyear = ($RMyear + 1900);
$RMmon++;
if ($RMmon < 10) {$RMmon = "0$RMmon";}
if ($RMmday < 10) {$RMmday = "0$RMmday";}
if ($RMhour < 10) {$RMhour = "0$RMhour";}
if ($RMmin < 10) {$RMmin = "0$RMmin";}
if ($RMsec < 10) {$RMsec = "0$RMsec";}
$del_time = "$RMyear-$RMmon-$RMmday $RMhour:$RMmin:$RMsec";
$del_date = "$RMyear-$RMmon-$RMmday";
if (!$Q) {print "\n\n-- VCA_log_manage.pl --\n\n";}
if (!$Q) {print "This program is designed manage the vicidial_vca_log table records, with \n";}
if (!$Q) {print "options to archive them and/or purge them at specific intevals.\n";}
if (!$Q) {print "$CLIdays days ( $del_time [$del_date]|$del_epoch ) from current date \n\n";}
if ($CALC_TEST > 0)
{
exit;
}
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
# Customized Variables
$server_ip = $VARserver_ip; # Asterisk server IP
use DBI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
if (!$T)
{
########## BEGIN --archive-vca-log-only flag processing ##########
if ($archive_vca_only > 0)
{
##### vicidial_vca_log
$stmtA = "SELECT count(*) from vicidial_vca_log;";
$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_vca_log_count = $aryA[0];
}
$sthA->finish();
$stmtA = "SELECT count(*) from vicidial_vca_log_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_vca_log_archive_count = $aryA[0];
}
$sthA->finish();
if (!$Q) {print "\nProcessing vicidial_vca_log table... ($vicidial_vca_log_count|$vicidial_vca_log_archive_count)\n";}
$stmtA = "INSERT IGNORE INTO vicidial_vca_log_archive SELECT * from vicidial_vca_log;";
$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_vca_log_archive table \n";}
$rv = $sthA->err();
if (!$rv)
{
if ($wipe_all > 0)
{$stmtA = "DELETE FROM vicidial_vca_log;";}
else
{$stmtA = "DELETE FROM vicidial_vca_log WHERE analysis_date < '$del_time';";}
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
$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_vca_log table \n";}
$stmtA = "optimize table vicidial_vca_log;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
}
if (!$Q) {print "\nProcessing vicidial_vca_log table finished: ($sthArows rows deleted) \n";}
exit;
}
########## END --archive-vca-log-only flag processing ##########
########## BEGIN --archived-vca-purge-only flag processing ##########
if ($archived_vca_purge_only > 0)
{
$stmtA = "SELECT count(*) from vicidial_vca_log_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_vca_log_archive_count = $aryA[0];
}
$sthA->finish();
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table purge... ($vicidial_vca_log_archive_count)\n";}
$stmtA = "DELETE FROM vicidial_vca_log_archive WHERE analysis_date < '$del_time';";
if ($DBX > 0) {print " DEBUG: |$stmtA|\n";}
$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_vca_log_archive table \n";}
$stmtA = "optimize table vicidial_vca_log_archive;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
if (!$Q) {print "\nProcessing vicidial_vca_log_archive table finished: ($sthArows rows deleted) \n";}
exit;
}
########## END --archived-vca-purge-only flag processing ##########
}
### calculate time to run script ###
$secY = time();
$secZ = ($secY - $secX);
$secZm = ($secZ /60);
if (!$Q) {print "\nscript execution time in seconds: $secZ minutes: $secZm\n";}
exit;