Added Event handlers for new manager events, updates to the listen script

git-svn-id: svn://192.168.202.10@3422 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2021-04-08 14:35:22 +00:00
parent 817ff333f7
commit aa93017117
5 changed files with 250 additions and 122 deletions
+55
View File
@@ -60,6 +60,7 @@
# 200102-0846 - Added vicidial_vmm_counts archiving
# 201107-2206 - Added optional park_log archiving
# 210317-2104 - Added vicidial_agent_visibility_log archiving
# 210407-2023 - Added vicidial_peer_event_log archiving
#
$CALC_TEST=0;
@@ -2104,6 +2105,60 @@ if (!$T)
}
##### vicidial_peer_event_log
$vicidial_peer_event_log_count_mil=0;
$stmtA = "SELECT count(*) from vicidial_peer_event_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_peer_event_log_count = $aryA[0];
}
$sthA->finish();
$vicidial_peer_event_log_count_mil = ($vicidial_peer_event_log_count - 1000000);
$stmtA = "SELECT count(*) from vicidial_peer_event_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_peer_event_log_archive_count = $aryA[0];
}
$sthA->finish();
if (!$Q) {print "\nProcessing vicidial_peer_event_log table... ($vicidial_peer_event_log_count|$vicidial_peer_event_log_archive_count)\n";}
$stmtA = "INSERT IGNORE INTO vicidial_peer_event_log_archive SELECT * from vicidial_peer_event_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_peer_event_log_archive table \n";}
$rv = $sthA->err();
if ( (!$rv) && ($vicidial_peer_event_log_count_mil > 0) )
{
if ($wipe_all > 0)
{$stmtA = "DELETE FROM vicidial_peer_event_log;";}
else
{$stmtA = "DELETE FROM vicidial_peer_event_log WHERE event_date < '$del_time' order by peer_event_id limit $vicidial_peer_event_log_count_mil;";}
$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_peer_event_log table \n";}
$stmtA = "optimize table vicidial_peer_event_log;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$stmtA = "optimize table vicidial_peer_event_log_archive;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
}
##### vicidial_inbound_survey_log
$stmtA = "SELECT count(*) from vicidial_inbound_survey_log;";
+145 -121
View File
@@ -17,14 +17,14 @@
# the ADMIN_keepalive_ALL.pl script, which makes sure it is always running in a
# screen, provided that the astguiclient.conf keepalive setting "2" is set.
#
# Copyright (C) 2017 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# Copyright (C) 2021 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# CHANGES
# 170915-2106 - Initial version based off the orginal AST_manager_listen.pl script
# 170920-1418 - Fix for issue with recordings beginning with CALLID variable
# 170930-0923 - Commented out handle_sip_event and handle_cpd_event functions, not needed anymore, to be deleted later
# 190121-1505 - Added RA_USER_PHONE On-Hook CID to solve last RINGAGENT issues
#
# 210407-2009 - Added Event handlers for new manager events
# constants
$DB=0; # Debug flag, set to 0 for no debug messages, lots of output
@@ -542,12 +542,6 @@ sub handle_event
case "DTMFBegin" { return handle_dtmf_begin_event( %event_hash ); }
case "DTMFEnd" { return handle_dtmf_end_event( %event_hash ); }
# CPD-Result event
# case "CPD-Result" { return handle_cpd_event( %event_hash ); }
# SIP-Hangup-Cause event
# case "SIP-Hangup-Cause" { return handle_sip_event( %event_hash ); }
# NewCallerid event
case "NewCallerid" { return handle_newcid_event( %event_hash ); }
@@ -557,6 +551,19 @@ sub handle_event
# Hangup event
case "Hangup" { return handle_hangup_event( %event_hash ); }
# SIPCriticalTimeout event
case "SIPCriticalTimeout" { return handle_sip_crit_timeout_event( %event_hash ); }
# PeerRegistered event
case "PeerRegistered" { return handle_peer_registered_event( %event_hash ); }
# SIPRTPDisconnect evett
case "SIPRTPDisconnect" { return handle_sip_rtp_disconnect_event( %event_hash ); }
# PeerStatus event
case "PeerStatus" { return handle_peer_status_event( %event_hash ); }
#case "" { return handle__event( %event_hash ); }
else { return 2; }
@@ -564,6 +571,136 @@ sub handle_event
}
sub handle_sip_crit_timeout_event
{
my %event_hash = @_;
if (
( exists $event_hash{'Type'} ) &&
( exists $event_hash{'CallID'} ) &&
( exists $event_hash{'SeqNo'} ) &&
( exists $event_hash{'Host'} ) &&
( exists $event_hash{'Timeout'} )
)
{
my ($ip,$port) = split( ':', $event_hash{'Host'});
$stmtA = "INSERT INTO vicidial_peer_event_log SET event_date=NOW(), event_type='CRITICALTIMEOUT', server_ip='$server_ip', host_ip='$ip', port='$port', channel_type='SIP', data='|Type=$event_hash{'Type'}|CallID=$event_hash{'CallID'}|SeqNo=$event_hash{'SeqNo'}|Timeout=$event_hash{'Timeout'}|'";
if($DB){print STDERR "|$stmtA|";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "$affected_rows|\n";}
return 1;
}
else
{
print STDERR "SIPCriticalTimeout event does not have a Type, CallID, SeqNo, Host, or Timeout ?!!!\n";
return 3;
}
}
sub handle_peer_registered_event
{
my %event_hash = @_;
if (
( exists $event_hash{'ChannelType'} ) &&
( exists $event_hash{'Peer'} ) &&
( exists $event_hash{'Host'} )
)
{
my ($ip,$port) = split( ':', $event_hash{'Host'});
my ($type,$phone_extension) = split( '/', $event_hash{'Peer'});
$stmtA = "INSERT INTO vicidial_peer_event_log SET event_date=NOW(6), event_type='REGISTERED', server_ip='$server_ip', host_ip='$ip', port='$port', channel_type='$event_hash{'ChannelType'}', peer='$event_hash{'Peer'}'";
if($DB){print STDERR "|$stmtA|";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "$affected_rows|\n";}
$stmtA = "UPDATE phones set phone_ip='$ip' where server_ip='$server_ip' and extension='$phone_extension' and protocol='$event_hash{'ChannelType'}';";
if($DB){print STDERR "|$stmtA|\n";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print "|$affected_rows phones updated|\n";}
return 1;
}
else
{
print STDERR "PeerRegistered event does not have a ChannelType, Peer, or Host ?!!!\n";
return 3;
}
}
sub handle_sip_rtp_disconnect_event
{
my %event_hash = @_;
if (
( exists $event_hash{'Channel'} ) &&
( exists $event_hash{'RTPLastRX'} )
)
{
my ($type,$phone_extension) = split( '/', $event_hash{'Channel'});
$stmtA = "INSERT INTO vicidial_peer_event_log SET event_date=NOW(6), event_type='RTPDISCONNECT', server_ip='$server_ip', channel_type='$type', channel='$event_hash{'Channel'}', data='|RTPLastRX=$event_hash{'RTPLastRX'}|'";
if($DB){print STDERR "|$stmtA|";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "$affected_rows|\n";}
return 1;
}
else
{
print STDERR "SIPRTPDisconnect event does not have a Channel or RTPLastRX ?!!!\n";
return 3;
}
}
sub handle_peer_status_event
{
my %event_hash = @_;
if (
( exists $event_hash{'ChannelType'} ) &&
( exists $event_hash{'PeerStatus'} ) &&
( exists $event_hash{'Peer'} )
)
{
my ($type,$phone_extension) = split( '/', $event_hash{'Peer'});
my $data = '|';
if ( exists( $event_hash{'PingTime'} )) { $data .= "PingTime=$event_hash{'PingTime'}|";}
if ( exists( $event_hash{'Time'} )) { $data .= "Time=$event_hash{'Time'}|";}
if ( exists( $event_hash{'MaxPing'} )) { $data .= "MaxPing=$event_hash{'MaxPing'}|";}
$stmtA = "INSERT INTO vicidial_peer_event_log SET event_date=NOW(6), event_type='$event_hash{'PeerStatus'}', server_ip='$server_ip', channel_type='$event_hash{'ChannelType'}', peer='$event_hash{'Peer'}', data='$data'";
if($DB){print STDERR "|$stmtA|";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print STDERR "$affected_rows|\n";}
if ( exists( $event_hash{'PingTime'} ))
{
$stmtA = "UPDATE phones set peer_status = '$event_hash{'PeerStatus'}', ping_time = '$event_hash{'PingTime'}' where server_ip='$server_ip' and extension='$phone_extension' and protocol='$event_hash{'ChannelType'}';";
}
else
{
$stmtA = "UPDATE phones set peer_status = '$event_hash{'PeerStatus'}' where server_ip='$server_ip' and extension='$phone_extension' and protocol='$event_hash{'ChannelType'}';";
}
if($DB){print STDERR "|$stmtA|\n";}
my $affected_rows = $dbhA->do($stmtA);
if($DB){print "|$affected_rows phones updated|\n";}
return 1;
}
else
{
print STDERR "PeerStatus event does not have a ChannelType, PeerStatus, Peer, or Time ?!!!\n";
return 3;
}
}
sub handle_hangup_event
{
my %event_hash = @_;
@@ -788,119 +925,6 @@ sub handle_dtmf_end_event
}
#sub handle_cpd_event
# {
# my %event_hash = @_;
#
# if (
# ( exists $event_hash{'Channel'} ) &&
# ( exists $event_hash{'Uniqueid'} ) &&
# ( exists $event_hash{'CallerIDName'} ) &&
# ( exists $event_hash{'ConnectedLineName'} ) &&
# ( exists $event_hash{'CPDResult'} )
# )
# {
#
# # get the valid Vicidial Call ID
# $call_id = get_valid_callid( $event_hash{'CallerIDName'}, $event_hash{'ConnectedLineName'} );
#
# &get_time_now;
#
# if($DB){print STDERR "|cpd_result = $event_hash{'CPDResult'}|cpd_detailed_result = $event_hash{'CPDDetailedResult'}|cpd_call_id = $event_hash{'CPDCallID'}|cpd_ref_id = $event_hash{'CPDReferenceID'}|cpd_camp_name = $event_hash{'CPDCampaignName'}|\n";}
#
# if (length($event_hash{'CPDResult'})>0)
# {
# $lead_id = substr($call_id, 10, 10);
# $lead_id = ($lead_id + 0);
#
# # TODO change the cpd log and this insert to include the new SIP Headers for 2.0 CPD
# $stmtA = "INSERT INTO vicidial_cpd_log set channel='$event_hash{'Channel'}', uniqueid='$event_hash{'Uniqueid'}', callerid='$call_id', server_ip='$event_hash{'ServerIP'}', lead_id='$lead_id', event_date='$now_date', result='$event_hash{'CPDResult'}';";
# if($DB){print STDERR "|$stmtA|\n";}
# my $affected_rows = $dbhA->do($stmtA);
# if($DB){print "|$affected_rows CPD_log inserted|$now_date|\n";}
# }
#
# return 1;
# }
# else
# {
# print STDERR "CPD-Result event does not have a Channel, Uniqueid, CPDResult, ConnectedLineName, or CallerIDName ?!!!\n";
# return 3;
# }
# }
#sub handle_sip_event
# {
# my %event_hash = @_;
#
# if (
# ( exists $event_hash{'Channel'} ) &&
# ( exists $event_hash{'Uniqueid'} ) &&
# ( exists $event_hash{'CallerIDName'} ) &&
# ( exists $event_hash{'ConnectedLineName'} ) &&
# ( exists $event_hash{'Result'} )
# )
# {
#
# # get the valid Vicidial Call ID
# $call_id = get_valid_callid( $event_hash{'CallerIDName'}, $event_hash{'ConnectedLineName'} );
#
# &get_time_now;
#
# @result_details=split(/\|/, $event_hash{'Result'});
#
# if ( (length($event_hash{'Result'})>0) && ($result_details[0] !~ /^407/) )
# {
# $lead_id = substr($call_id, 10, 10);
# $lead_id = ($lead_id + 0);
# $beginUNIQUEID = $event_hash{'Uniqueid'};
# $beginUNIQUEID =~ s/\..*//gi;
# $stmtA = "UPDATE vicidial_dial_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]',uniqueid='$event_hash{'Uniqueid'}' where caller_code='$call_id' and server_ip='$event_hash{'ServerIP'}' and lead_id='$lead_id';";
# if($DB){print STDERR "|$stmtA|\n";}
# my $affected_rows = $dbhA->do($stmtA);
# if($DB){print "|$affected_rows dial_log updated|$call_id|$event_hash{'ServerIP'}|$event_hash{'Result'}|\n";}
# $vddl_update = ($vddl_update + $affected_rows);
#
# $preCtarget = ($beginUNIQUEID - 180); # 180 seconds before call start
# ($preCsec,$preCmin,$preChour,$preCmday,$preCmon,$preCyear,$preCwday,$preCyday,$preCisdst) = localtime($preCtarget);
# $preCyear = ($preCyear + 1900);
# $preCmon++;
# if ($preCmon < 10) {$preCmon = "0$preCmon";}
# if ($preCmday < 10) {$preCmday = "0$preCmday";}
# if ($preChour < 10) {$preChour = "0$preChour";}
# if ($preCmin < 10) {$preCmin = "0$preCmin";}
# if ($preCsec < 10) {$preCsec = "0$preCsec";}
# $preCSQLdate = "$preCyear-$preCmon-$preCmday $preChour:$preCmin:$preCsec";
#
# $postCtarget = ($beginUNIQUEID + 10); # 10 seconds after call start
# ($postCsec,$postCmin,$postChour,$postCmday,$postCmon,$postCyear,$postCwday,$postCyday,$postCisdst) = localtime($postCtarget);
# $postCyear = ($postCyear + 1900);
# $postCmon++;
# if ($postCmon < 10) {$postCmon = "0$postCmon";}
# if ($postCmday < 10) {$postCmday = "0$postCmday";}
# if ($postChour < 10) {$postChour = "0$postChour";}
# if ($postCmin < 10) {$postCmin = "0$postCmin";}
# if ($postCsec < 10) {$postCsec = "0$postCsec";}
# $postCSQLdate = "$postCyear-$postCmon-$postCmday $postChour:$postCmin:$postCsec";
#
# $stmtA = "UPDATE vicidial_carrier_log SET sip_hangup_cause='$result_details[0]',sip_hangup_reason='$result_details[1]' where server_ip='$event_hash{'ServerIP'}' and caller_code='$call_id' and lead_id='$lead_id' and call_date > \"$preCSQLdate\" and call_date < \"$postCSQLdate\" order by call_date desc limit 1;";
# if($DB){print STDERR "|$stmtA|\n";}
# my $affected_rows = $dbhA->do($stmtA);
# if($DB){print "|$affected_rows carrier_log updated|$call_id|$event_hash{'ServerIP'}|$event_hash{'Uniqueid'}|$result_details[0]|$result_details[1]|\n";}
# }
#
# return 1;
# }
# else
# {
# print STDERR "SIP-Hangup-Cause event does not have a Channel, Uniqueid, Result, ConnectedLineName, or CallerIDName ?!!!\n";
# return 3;
# }
# }
sub get_time_now #get the current date and time and epoch for logging call lengths and datetimes
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@@ -30,6 +30,11 @@ eventfilter=Event: Newstate
eventfilter=Event: Hangup
eventfilter=!Event: HangupRequest
; Optional
eventfilter=Event: PeerStatus
eventfilter=Event: SIPRTPDisconnect
eventfilter=Event: PeerRegistered
eventfilter=Event: SIPCriticalTimeout
[sendcron]
secret = 1234
+22 -1
View File
@@ -4537,6 +4537,24 @@ index (db_time),
unique index visibleuser (user, visibility, event_end_epoch)
) ENGINE=MyISAM;
CREATE TABLE vicidial_peer_event_log (
`peer_event_id` INT(9) UNSIGNED NOT NULL AUTO_INCREMENT,
`event_type` ENUM('UNKNOWN','REGISTERED','UNREGISTERED','REACHABLE','LAGGED','UNREACHABLE','RTPDISCONNECT','CRITICALTIMEOUT') COLLATE utf8_unicode_ci DEFAULT 'UNKNOWN',
`event_date` DATETIME(6) NOT NULL,
`channel` VARCHAR(100) COLLATE utf8_unicode_ci DEFAULT '',
`server_ip` VARCHAR(15) COLLATE utf8_unicode_ci NOT NULL,
`host_ip` VARCHAR(15) COLLATE utf8_unicode_ci DEFAULT '',
`port` SMALLINT(6) DEFAULT NULL,
`channel_type` ENUM('IAX2','SIP') COLLATE utf8_unicode_ci DEFAULT NULL,
`peer` VARCHAR(100) COLLATE utf8_unicode_ci DEFAULT '',
`data` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT '',
PRIMARY KEY (`peer_event_id`),
KEY `event_date` (`event_date`),
KEY `peer` (`peer`),
KEY `channel` (`channel`)
) ENGINE=MyISAM AUTO_INCREMENT=630320 DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
ALTER TABLE vicidial_email_list MODIFY message text character set utf8;
@@ -4792,6 +4810,9 @@ CREATE UNIQUE INDEX uniqueidtime_park on park_log_archive (uniqueid,parked_time)
CREATE TABLE vicidial_agent_visibility_log_archive LIKE vicidial_agent_visibility_log;
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;
GRANT RELOAD ON *.* TO cron@'%';
GRANT RELOAD ON *.* TO cron@localhost;
@@ -4875,4 +4896,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='1628',db_schema_update_date=NOW(),reload_timestamp=NOW();
UPDATE system_settings SET db_schema_version='1629',db_schema_update_date=NOW(),reload_timestamp=NOW();
+23
View File
@@ -1612,3 +1612,26 @@ UPDATE system_settings SET db_schema_version='1627',db_schema_update_date=NOW()
ALTER TABLE system_settings ADD agent_screen_timer VARCHAR(20) default 'setTimeout';
UPDATE system_settings SET db_schema_version='1628',db_schema_update_date=NOW() where db_schema_version < 1628;
CREATE TABLE vicidial_peer_event_log (
`peer_event_id` INT(9) UNSIGNED NOT NULL AUTO_INCREMENT,
`event_type` ENUM('UNKNOWN','REGISTERED','UNREGISTERED','REACHABLE','LAGGED','UNREACHABLE','RTPDISCONNECT','CRITICALTIMEOUT') COLLATE utf8_unicode_ci DEFAULT 'UNKNOWN',
`event_date` DATETIME(6) NOT NULL,
`channel` VARCHAR(100) COLLATE utf8_unicode_ci DEFAULT '',
`server_ip` VARCHAR(15) COLLATE utf8_unicode_ci NOT NULL,
`host_ip` VARCHAR(15) COLLATE utf8_unicode_ci DEFAULT '',
`port` SMALLINT(6) DEFAULT NULL,
`channel_type` ENUM('IAX2','SIP') COLLATE utf8_unicode_ci DEFAULT NULL,
`peer` VARCHAR(100) COLLATE utf8_unicode_ci DEFAULT '',
`data` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT '',
PRIMARY KEY (`peer_event_id`),
KEY `event_date` (`event_date`),
KEY `peer` (`peer`),
KEY `channel` (`channel`)
) ENGINE=MyISAM AUTO_INCREMENT=630320 DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
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;
UPDATE system_settings SET db_schema_version='1629',db_schema_update_date=NOW() where db_schema_version < 1629;