KHOMP integration updates

git-svn-id: svn://192.168.202.10@3478 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2021-07-07 22:59:24 +00:00
parent a5bab75131
commit a38c7ae17a
3 changed files with 216 additions and 187 deletions
+54 -25
View File
@@ -86,7 +86,6 @@
# 190709-2240 - Added Call Quota logging
# 191001-1509 - Small fix for monitoring issue
# 200210-1644 - Added KHOMP code
# 200902-1611 - Fixed bug with khomp_end_call data
#
# defaults for PreFork
@@ -185,7 +184,7 @@ use Net::Server;
use vars qw(@ISA);
use Net::Server::PreFork; # any personality will do
@ISA = qw(Net::Server::PreFork);
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Time::HiRes ('tv_interval','gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Time::Local;
# Needed for Khomp Integration
@@ -349,6 +348,8 @@ sub process_request
if ( $key eq 'khomp_id_format' ) { $khomp_id_format = $value; }
if ( $key eq 'khomp_api_login_url' ) { $khomp_api_login_url = $value; }
if ( $key eq 'khomp_sub_account_header' ) { $khomp_sub_account_header = $value; }
if ( $key eq 'khomp_api_token' ) { $khomp_api_token = $value; }
if ( $key eq 'khomp_api_token_expire' ) { $khomp_api_token_expire = $value; }
}
}
@@ -2760,21 +2761,57 @@ sub process_khomp_analytics
elsif ($khomp_id_format eq 'CALLERCODE_CAMP_EXTERNIP')
{ $khomp_id = $callerid . '_' . $campaign_id . '_' . $external_server_ip; }
my $login_token = 'TOKEN';
my $api_auth_time = 0;
if ( ($khomp_api_token_expire < time() ) or ( $khomp_api_token eq 'TOKENTOKENTOKEN' ))
{
if ($AGILOG) {$agi_string = "-- KHOMP API Token $khomp_api_token has expired at $khomp_api_token_expire"; &agi_output;}
# get a new API token
my $new_khomp_api_token = '';
if ( $khomp_api_proxied eq 'false' )
{
($login_token, $api_auth_time) = khomp_api_login( $khomp_api_login_url, $khomp_api_user, $khomp_api_pass );
($new_khomp_api_token, $api_auth_time) = khomp_api_login( $khomp_api_login_url, $khomp_api_user, $khomp_api_pass );
}
if ( $login_token ne 'login' )
# update the settings container
my $old_token_string = "khomp_api_token => $khomp_api_token";
my $new_token_string = "khomp_api_token => $new_khomp_api_token";
my $new_token_expire_time = time() + 3600;
my $old_token_expire_string = "khomp_api_token_expire => $khomp_api_token_expire";
my $new_token_expire_string = "khomp_api_token_expire => $new_token_expire_time";
# LOCK vicidial_settings_containers
$stmtA = "LOCK TABLES vicidial_settings_containers WRITE";
$dbhA->do($stmtA);
# UPDATE the Token
$stmtToken = "UPDATE vicidial_settings_containers SET container_entry = REGEXP_REPLACE(container_entry, '$old_token_string', '$new_token_string') WHERE container_id = 'KHOMPSETTINGS';";
$affected_rows = $dbhA->do($stmtToken);
# UPDATE the Expire time
$stmtExpire = "UPDATE vicidial_settings_containers SET container_entry = REGEXP_REPLACE(container_entry, '$old_token_expire_string', '$new_token_expire_string') WHERE container_id = 'KHOMPSETTINGS';";
$affected_rows = $dbhA->do($stmtExpire);
# Unlock vicidial_settings_containers
$stmtA = "UNLOCK TABLES";
$dbhA->do($stmtA);
if ($AGILOG) {$agi_string = "-- KHOMP SC TOKEN UPDATE|$affected_rows|$stmtToken|"; &agi_output;}
if ($AGILOG) {$agi_string = "-- KHOMP SC TOKEN EXPIRE UPDATE|$affected_rows|$stmtExpire|"; &agi_output;}
# over write the old with the new
$khomp_api_token = $new_khomp_api_token;
}
else
{
if ($AGILOG) {$agi_string = "-- KHOMP API Token $khomp_api_token still valid till $khomp_api_token_expire"; &agi_output;}
}
if ( $khomp_api_token ne 'TOKENTOKENTOKEN' )
{
# build JSON object
my $khomp_request = {
'id' => 0,
'method' => 'CallList',
'params' => {
'token' => "$login_token",
'token' => "$khomp_api_token",
'query' => {
'type' => "eq",
'field' => "sip_header:$khomp_header",
@@ -2789,7 +2826,7 @@ sub process_khomp_analytics
$khomp_json = encode_json( $khomp_request );
# call the API
($result, $api_query_time) = khomp_json_api( $khomp_json, $khomp_api_url, $khomp_api_user, $khomp_api_pass );
($result, $api_query_time) = khomp_json_api( $khomp_json, $khomp_api_url );
# check the result
if ( $result =~ /^ERROR/ )
@@ -2808,10 +2845,6 @@ sub process_khomp_analytics
$parsed_data{'api_auth_time'} = $api_auth_time;
$parsed_data{'api_query_time'} = $api_query_time;
# log the khomp data in the vicidial_khomp_log
log_khomp_call_data( %parsed_data);
$conclusion = $parsed_data{'conclusion'};
$pattern = $parsed_data{'pattern'};
@@ -2924,6 +2957,11 @@ sub process_khomp_analytics
}
}
if ( $khomp_action ne '' ) { $parsed_data{'vici_action'} = "$khomp_action"; }
if ( $khomp_VDL_status ne '' ) { $parsed_data{'vici_status'} = "$khomp_VDL_status"; }
# log the khomp data in the vicidial_khomp_log
log_khomp_call_data( %parsed_data);
if ($AGILOG) { $agi_string = "--KHOMP: conclusion = $conclusion|pattern = $pattern|status = $khomp_VDL_status"; &agi_output; }
@@ -2964,6 +3002,8 @@ sub log_khomp_call_data
if ( defined( $khomp_call_data{'hangup_origin'} ) ) { $stmtA .= ", hangup_origin = '$khomp_call_data{'hangup_origin'}'"; }
if ( defined( $khomp_call_data{'hangup_cause_recv'} ) ) { $stmtA .= ", hangup_cause_recv = '$khomp_call_data{'hangup_cause_recv'}'"; }
if ( defined( $khomp_call_data{'hangup_cause_sent'} ) ) { $stmtA .= ", hangup_cause_sent = '$khomp_call_data{'hangup_cause_sent'}'"; }
if ( defined( $khomp_call_data{'vici_action'} ) ) { $stmtA .= ", vici_action = '$khomp_call_data{'vici_action'}'"; }
if ( defined( $khomp_call_data{'vici_status'} ) ) { $stmtA .= ", vici_status = '$khomp_call_data{'vici_status'}'"; }
$stmtA .= " WHERE khomp_id = '$khomp_call_data{'khomp_id'}'";
@@ -3087,10 +3127,7 @@ sub khomp_api_login
($auth_end_sec, $auth_end_usec) = gettimeofday();
$auth_sec = $auth_end_sec - $auth_start_sec;
$auth_usec = $auth_end_usec - $auth_start_usec;
$api_auth_time = "$auth_sec.$auth_usec";
$api_auth_time = tv_interval ( [$auth_start_sec, $auth_start_usec], [$auth_end_sec, $auth_end_usec]);
return ($token, $api_auth_time);
}
@@ -3098,10 +3135,7 @@ sub khomp_api_login
### code for connecting to KHOMP api and passing JSON
sub khomp_json_api
{
(
$khomp_json,
$khomp_api_url,
) = @_;
( $khomp_json, $khomp_api_url ) = @_;
my $query_start_sec;
my $query_start_usec;
@@ -3133,12 +3167,7 @@ sub khomp_json_api
($query_end_sec, $query_end_usec) = gettimeofday();
$query_sec = $query_end_sec - $query_start_sec;
$query_usec = $query_end_usec - $query_start_usec;
$api_query_time = "$query_sec.$query_usec";
$api_query_time = tv_interval ( [$query_start_sec, $query_start_usec], [$query_end_sec, $query_end_usec]);
return ($result, $api_query_time);
}
@@ -44,6 +44,8 @@ CREATE TABLE `vicidial_khomp_log` (
`hangup_query_time` varchar(20) COLLATE utf8_unicode_ci DEFAULT '0',
`route_auth_time` varchar(20) COLLATE utf8_unicode_ci DEFAULT '0',
`route_query_time` varchar(20) COLLATE utf8_unicode_ci DEFAULT '0',
`vici_action` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`vici_status` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`khomp_log_id`),
KEY `caller_code` (`caller_code`),
KEY `start_date` (`start_date`),
@@ -5266,7 +5266,7 @@ sub process_khomp_analytics
if ($AGILOG) {$agi_string = "-- KHOMP API Token $khomp_api_token still valid till $khomp_api_token_expire"; &agi_output;}
}
if ( $login_token ne 'login' )
if ( $khomp_api_token ne 'TOKENTOKENTOKEN' )
{
# build JSON object
my $khomp_request = {
@@ -5308,9 +5308,6 @@ sub process_khomp_analytics
$parsed_data{'api_auth_time'} = $api_auth_time;
$parsed_data{'api_query_time'} = $api_query_time;
# log the khomp data in the vicidial_khomp_log
log_khomp_call_data( %parsed_data );
$conclusion = $parsed_data{'conclusion'};
$pattern = $parsed_data{'pattern'};
@@ -5338,6 +5335,12 @@ sub process_khomp_analytics
if ($AGILOG) { $agi_string = "--KHOMP: conclusion = $conclusion|pattern = $pattern|action = $action|status = $status"; &agi_output; }
if ( $action ne '' ) { $parsed_data{'vici_action'} = "$action"; }
if ( $status ne '' ) { $parsed_data{'vici_status'} = "$status"; }
# log the khomp data in the vicidial_khomp_log
log_khomp_call_data( %parsed_data );
# handle the AMD action
if (
(( $action eq 'amdaction' ) && ($cpd_amd_action =~ /DISPO|MESSAGE|CALLMENU|INGROUP/)) ||
@@ -5345,9 +5348,7 @@ sub process_khomp_analytics
( $action eq 'status' )
)
{
$parsed_data{'vdad_action'} = $action;
$parsed_data{'vdad_result'} = $status;
khomp_end_call( %parsed_data );
khomp_end_call( %parsed_data, $action, $status );
}
if ( $action eq 'route' )
{
@@ -5390,6 +5391,8 @@ sub log_khomp_call_data
if ( defined( $khomp_call_data{'hangup_origin'} ) ) { $stmtA .= ", hangup_origin = '$khomp_call_data{'hangup_origin'}'"; }
if ( defined( $khomp_call_data{'hangup_cause_recv'} ) ) { $stmtA .= ", hangup_cause_recv = '$khomp_call_data{'hangup_cause_recv'}'"; }
if ( defined( $khomp_call_data{'hangup_cause_sent'} ) ) { $stmtA .= ", hangup_cause_sent = '$khomp_call_data{'hangup_cause_sent'}'"; }
if ( defined( $khomp_call_data{'vici_action'} ) ) { $stmtA .= ", vici_action = '$khomp_call_data{'vici_action'}'"; }
if ( defined( $khomp_call_data{'vici_status'} ) ) { $stmtA .= ", vici_status = '$khomp_call_data{'vici_status'}'"; }
$stmtA .= " WHERE khomp_id = '$khomp_call_data{'khomp_id'}'";
@@ -5401,9 +5404,7 @@ sub log_khomp_call_data
sub khomp_end_call
{
%khomp_call_data = @_;
$vdad_action = $khomp_call_data{'vdad_action'};
$vdad_result = $khomp_call_data{'vdad_result'};
%khomp_call_data, $vdad_action, $vdad_result = @_;
if ($AGILOG) {$agi_string = "-- VDAD KHOMP End Call |a:$vdad_action|s:$vdad_result|"; &agi_output;}
@@ -5638,10 +5639,7 @@ sub khomp_api_login
### code for connecting to KHOMP api and passing JSON
sub khomp_json_api
{
(
$khomp_json,
$khomp_api_url,
) = @_;
( $khomp_json, $khomp_api_url ) = @_;
my $query_start_sec;
my $query_start_usec;