From b7c18b2bc80e5298912e087ce1b6b1729e2dcab6 Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 19 Jan 2010 19:20:31 +0000 Subject: [PATCH] added DID logging of call length to call_log table from start until pre-in-group queue or hangup git-svn-id: svn://192.168.202.10@1313 3d104415-ff17-0410-8863-d5cf3c621b8a --- .../branches/agc_2.2.0/agi/agi-DID_route.agi | 65 +++++++++++++++---- .../agc_2.2.0/agi/agi-VDAD_ALL_inbound.agi | 31 ++++++++- agc_2-X/branches/agc_2.2.0/bin/FastAGI_log.pl | 21 +++--- agc_2-X/trunk/agi/agi-VDAD_ALL_inbound.agi | 31 ++++++++- agc_2-X/trunk/bin/FastAGI_log.pl | 21 +++--- 5 files changed, 136 insertions(+), 33 deletions(-) diff --git a/agc_2-X/branches/agc_2.2.0/agi/agi-DID_route.agi b/agc_2-X/branches/agc_2.2.0/agi/agi-DID_route.agi index 9b432a33..d36f09b4 100644 --- a/agc_2-X/branches/agc_2.2.0/agi/agi-DID_route.agi +++ b/agc_2-X/branches/agc_2.2.0/agi/agi-DID_route.agi @@ -4,10 +4,12 @@ # # runs when a call comes into an inbound context on a trunk. This script will # send the calls to various places depending on the settings for each DID. -# # # You need to put a line similar to this below in your extensions.conf file in -# the context for where incoming calls go from your trunks: +# the context for where incoming calls go from your trunks (for example, the +# trunkinbound context which is present in the default dialplan): +# +#[trunkinbound] # ;inbound DID catch-all: #exten => _X.,1,AGI(agi-DID_route.agi) # @@ -28,6 +30,7 @@ $script = 'agi-DID_route.agi'; $dtmf_silent_prefix = '7'; $at='@'; $S='*'; +$US='_'; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @@ -198,6 +201,7 @@ if ($sthArows > 0) $user_unavailable_action = $aryA[11]; $user_route_settings_ingroup = $aryA[12]; $menu_id = $aryA[13]; + $record_call = ''; $DIDs_in_system++; } @@ -227,16 +231,22 @@ if ($sthArows < 1) $user_unavailable_action = $aryA[11]; $user_route_settings_ingroup = $aryA[12]; $menu_id = $aryA[13]; + $record_call = ''; } $sthA->finish(); } -### Log the call +### Log the call to vicidial_did_log $stmtA = "INSERT INTO vicidial_did_log SET uniqueid='$uniqueid',channel='$channel',server_ip='$VARserver_ip',caller_id_number='$callerid',caller_id_name='$calleridname',extension='$extension',call_date='$SQLdate',did_id='$did_id',did_route='$did_route';"; if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;} $affected_rowsL = $dbhA->do($stmtA); if ($AGILOG) {$agi_string = "-- DID LOG : |$affected_rowsL|$stmtA|"; &agi_output;} +### Log the call to call_log +$stmtA = "INSERT INTO call_log SET uniqueid='$unique_id', channel='$channel', channel_group='DID_INBOUND', server_ip='$VARserver_ip', type='$type', extension='$extension', number_dialed='$extension', caller_code='$callerid', start_time='$SQLdate', start_epoch='$now_date_epoch';"; +$affected_rowsC = $dbhA->do($stmtA); +if ($AGILOG) {$agi_string = "-- CALL LOG : |$affected_rowsC|$stmtA|"; &agi_output;} + if ($AGILOG) {$did_string = "$SQLdate|$uniqueid|$channel|$extension|$callerid|$calleridname|$did_id|$did_route|"; &did_output;} if ($DIDs_in_system < 1) @@ -246,6 +256,35 @@ if ($DIDs_in_system < 1) exit; } +### if set to record this call, start recording ### +if ($record_call =~ /Y/) + { + $insert_recording_id=''; + $filename = "$tsSQLdate$US$extension$US$callerid"; + ### code to record call goes here ### + + $AGI->exec("Monitor wav|/var/spool/asterisk/monitor/MIX/$filename"); + + ### insert record into recording_log table ### + $stmtA = "INSERT INTO recording_log (channel,server_ip,extension,start_time,start_epoch,length_in_sec,filename,lead_id,user,location,vicidial_id) values('$channel','$VARserver_ip','$extension','$SQLdate','now_date_epoch','0','$filename','0','$callerid','$filename','$unique_id');"; + $affected_rowsR = $dbhA->do($stmtA); + if ($affected_rowsR > 0) + { + $stmtB = "select LAST_INSERT_ID() LIMIT 1;"; + $sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $insert_recording_id = $aryA[0]; + } + $sthA->finish(); + } + + if ($AGILOG) {$did_string = "-- RECORDING LOG : |$affected_rowsR|$insert_recording_id|$stmtA|"; &did_output;} + } + ### Grab Server values from the database $cbc=0; $stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$VARserver_ip';"; @@ -256,12 +295,12 @@ while ($sthArows > $cbc) { @aryA = $sthA->fetchrow_array; - $DBvoicemail_dump_exten = "$aryA[0]"; - $DBext_context = "$aryA[1]"; - $DBanswer_transfer_agent = "$aryA[2]"; - $DBSERVER_GMT = "$aryA[3]"; - $DBasterisk_version = "$aryA[4]"; - $DBmax_vicidial_trunks = "$aryA[5]"; + $DBvoicemail_dump_exten = $aryA[0]; + $DBext_context = $aryA[1]; + $DBanswer_transfer_agent = $aryA[2]; + $DBSERVER_GMT = $aryA[3]; + $DBasterisk_version = $aryA[4]; + $DBmax_vicidial_trunks = $aryA[5]; if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;} if ($DBext_context) {$ext_context = $DBext_context;} if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;} @@ -286,10 +325,10 @@ if ($did_route =~ /PHONE/) if ($sthArows > 0) { @aryA = $sthA->fetchrow_array; - $dialplan_number = "$aryA[0]"; - $voicemail_id = "$aryA[1]"; - $protocol = "$aryA[2]"; - $ext_context = "$aryA[3]"; + $dialplan_number = $aryA[0]; + $voicemail_id = $aryA[1]; + $protocol = $aryA[2]; + $ext_context = $aryA[3]; } $sthA->finish(); diff --git a/agc_2-X/branches/agc_2.2.0/agi/agi-VDAD_ALL_inbound.agi b/agc_2-X/branches/agc_2.2.0/agi/agi-VDAD_ALL_inbound.agi index 17cac24e..0068d00a 100644 --- a/agc_2-X/branches/agc_2.2.0/agi/agi-VDAD_ALL_inbound.agi +++ b/agc_2-X/branches/agc_2.2.0/agi/agi-VDAD_ALL_inbound.agi @@ -1336,6 +1336,33 @@ else } +########################################################## +### end logging for call_log logged DID_INBOUND calls ### +$CLchannel_group=''; +$stmtA = "SELECT channel_group,start_epoch FROM call_log where uniqueid='$unique_id' order by start_time desc limit 1;"; +$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; + $CLchannel_group = $aryA[0]; + $CLstart_epoch = $aryA[1]; + } +$sthA->finish(); + +if ($CLchannel_group =~ /DID_INBOUND/) + { + $CLlength_in_sec = ($now_date_epoch - $CLstart_epoch); + $CLlength_in_min = ($CLlength_in_sec / 60); + $CLlength_in_min = sprintf("%8.2f", $CLlength_in_min); + + $stmtA = "UPDATE call_log set end_time='$now_date',end_epoch='$now_date_epoch',length_in_sec=$CLlength_in_sec,length_in_min='$CLlength_in_min',extension='$callerid' where uniqueid='$unique_id'"; + $affected_rowsCL = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "DID IVR time logged: $start_time|$now_date_epoch|$affected_rowsCL|$stmtA|"; &agi_output;} + } + + ############################################ ### Loop to try to send call to an agent ### while ( ($drop_timer <= $DROP_TIME) && ($wait_in_queue > 0) ) @@ -1763,8 +1790,8 @@ while ( ($drop_timer <= $DROP_TIME) && ($wait_in_queue > 0) ) $dbhA->disconnect(); - $now_date_epoch = time(); - $now_date = "$year-$mon-$mday $hour:$min:$sec"; + $now_date_epoch = time(); + $now_date = "$year-$mon-$mday $hour:$min:$sec"; if ($AGILOG) {$agi_string = "XXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;} exit; diff --git a/agc_2-X/branches/agc_2.2.0/bin/FastAGI_log.pl b/agc_2-X/branches/agc_2.2.0/bin/FastAGI_log.pl index f3ae864f..b0d14221 100644 --- a/agc_2-X/branches/agc_2.2.0/bin/FastAGI_log.pl +++ b/agc_2-X/branches/agc_2.2.0/bin/FastAGI_log.pl @@ -601,9 +601,9 @@ sub process_request ### get uniqueid and start_epoch from the call_log table $CALLunique_id = $unique_id; - $stmtA = "SELECT uniqueid,start_epoch,channel FROM call_log where uniqueid='$unique_id';"; + $stmtA = "SELECT uniqueid,start_epoch,channel,end_epoch,channel_group FROM call_log where uniqueid='$unique_id';"; if ($callerid =~ /^M/) - {$stmtA = "SELECT uniqueid,start_epoch,channel FROM call_log where caller_code='$callerid' and channel NOT LIKE \"Local\/%\";";} + {$stmtA = "SELECT uniqueid,start_epoch,channel,end_epoch,channel_group FROM call_log where caller_code='$callerid' and channel NOT LIKE \"Local\/%\";";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -611,16 +611,21 @@ sub process_request while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $unique_id = $aryA[0]; - $uniqueid = $aryA[0]; - $start_time = $aryA[1]; - $channel = $aryA[2]; - if ($AGILOG) {$agi_string = "|$aryA[0]|$aryA[1]|"; &agi_output;} + $unique_id = $aryA[0]; + $uniqueid = $aryA[0]; + $start_time = $aryA[1]; + $channel = $aryA[2]; + $end_epoch = $aryA[3]; + $channel_group = $aryA[4]; + if ($AGILOG) {$agi_string = "|$aryA[0]|$aryA[1]|$aryA[2]|$aryA[3]|"; &agi_output;} $rec_count++; } $sthA->finish(); - if ($rec_count) + $did_log=0; + if ( ($channel_group =~ /DID_INBOUND/) && ($end_epoch > 1000) ) + {$did_log=1;} + if ( ($rec_count) && ($did_log < 1) ) { $length_in_sec = ($now_date_epoch - $start_time); $length_in_min = ($length_in_sec / 60); diff --git a/agc_2-X/trunk/agi/agi-VDAD_ALL_inbound.agi b/agc_2-X/trunk/agi/agi-VDAD_ALL_inbound.agi index 17cac24e..0068d00a 100644 --- a/agc_2-X/trunk/agi/agi-VDAD_ALL_inbound.agi +++ b/agc_2-X/trunk/agi/agi-VDAD_ALL_inbound.agi @@ -1336,6 +1336,33 @@ else } +########################################################## +### end logging for call_log logged DID_INBOUND calls ### +$CLchannel_group=''; +$stmtA = "SELECT channel_group,start_epoch FROM call_log where uniqueid='$unique_id' order by start_time desc limit 1;"; +$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; + $CLchannel_group = $aryA[0]; + $CLstart_epoch = $aryA[1]; + } +$sthA->finish(); + +if ($CLchannel_group =~ /DID_INBOUND/) + { + $CLlength_in_sec = ($now_date_epoch - $CLstart_epoch); + $CLlength_in_min = ($CLlength_in_sec / 60); + $CLlength_in_min = sprintf("%8.2f", $CLlength_in_min); + + $stmtA = "UPDATE call_log set end_time='$now_date',end_epoch='$now_date_epoch',length_in_sec=$CLlength_in_sec,length_in_min='$CLlength_in_min',extension='$callerid' where uniqueid='$unique_id'"; + $affected_rowsCL = $dbhA->do($stmtA); + if ($AGILOG) {$agi_string = "DID IVR time logged: $start_time|$now_date_epoch|$affected_rowsCL|$stmtA|"; &agi_output;} + } + + ############################################ ### Loop to try to send call to an agent ### while ( ($drop_timer <= $DROP_TIME) && ($wait_in_queue > 0) ) @@ -1763,8 +1790,8 @@ while ( ($drop_timer <= $DROP_TIME) && ($wait_in_queue > 0) ) $dbhA->disconnect(); - $now_date_epoch = time(); - $now_date = "$year-$mon-$mday $hour:$min:$sec"; + $now_date_epoch = time(); + $now_date = "$year-$mon-$mday $hour:$min:$sec"; if ($AGILOG) {$agi_string = "XXXXX VDAD transferred: start|stop $start_time|$now_date"; &agi_output;} exit; diff --git a/agc_2-X/trunk/bin/FastAGI_log.pl b/agc_2-X/trunk/bin/FastAGI_log.pl index f3ae864f..b0d14221 100644 --- a/agc_2-X/trunk/bin/FastAGI_log.pl +++ b/agc_2-X/trunk/bin/FastAGI_log.pl @@ -601,9 +601,9 @@ sub process_request ### get uniqueid and start_epoch from the call_log table $CALLunique_id = $unique_id; - $stmtA = "SELECT uniqueid,start_epoch,channel FROM call_log where uniqueid='$unique_id';"; + $stmtA = "SELECT uniqueid,start_epoch,channel,end_epoch,channel_group FROM call_log where uniqueid='$unique_id';"; if ($callerid =~ /^M/) - {$stmtA = "SELECT uniqueid,start_epoch,channel FROM call_log where caller_code='$callerid' and channel NOT LIKE \"Local\/%\";";} + {$stmtA = "SELECT uniqueid,start_epoch,channel,end_epoch,channel_group FROM call_log where caller_code='$callerid' and channel NOT LIKE \"Local\/%\";";} $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; $sthArows=$sthA->rows; @@ -611,16 +611,21 @@ sub process_request while ($sthArows > $rec_count) { @aryA = $sthA->fetchrow_array; - $unique_id = $aryA[0]; - $uniqueid = $aryA[0]; - $start_time = $aryA[1]; - $channel = $aryA[2]; - if ($AGILOG) {$agi_string = "|$aryA[0]|$aryA[1]|"; &agi_output;} + $unique_id = $aryA[0]; + $uniqueid = $aryA[0]; + $start_time = $aryA[1]; + $channel = $aryA[2]; + $end_epoch = $aryA[3]; + $channel_group = $aryA[4]; + if ($AGILOG) {$agi_string = "|$aryA[0]|$aryA[1]|$aryA[2]|$aryA[3]|"; &agi_output;} $rec_count++; } $sthA->finish(); - if ($rec_count) + $did_log=0; + if ( ($channel_group =~ /DID_INBOUND/) && ($end_epoch > 1000) ) + {$did_log=1;} + if ( ($rec_count) && ($did_log < 1) ) { $length_in_sec = ($now_date_epoch - $start_time); $length_in_min = ($length_in_sec / 60);