Author Topic: queueDial.agi not working  (Read 8801 times)

tank30

  • Newbie
  • *
  • Posts: 46
  • Karma: 0
    • View Profile
queueDial.agi not working
« on: January 31, 2008, 16:46:34 »
I am using Asterisk 1.4.11 on Debian etch. I am trying to implement outbound queue but it seems that agi is not executing succesfully:

    -- Executing [dial-SIP@macro-KM-Dialout-base:5] DeadAGI("SIP/391-b5766b60", "queueDial.agi|22693314|SIP/22693314@PRDSER|Outbound|Agent/392") in new stack
[Jan 31 17:15:26] WARNING[19519]: res_agi.c:2089 deadagi_exec: Running DeadAGI on a live channel will cause problems, please use AGI
    -- Launched AGI Script /var/lib/asterisk/agi-bin/queueDial.agi
    -- AGI Script queueDial.agi completed, returning 0


I do not see anything on asterisk console being executed by the agi script.  Script is the untouched file that i got from qm.


cassius:/var/lib/asterisk/agi-bin# cat queueDial.agi
#!/usr/bin/perl
$|=1;

print STDERR "started agi script \n"

#
# Outbound call queue events generator
#      (c) 2006, 2007 Loway - All rights reserved.
#          This software is a part of QueueMetrics.
#          http://queuemetrics.com
#
# $Id: queueDial.agi,v 1.5 2007/04/18 12:07:46 lenz Exp $
#
# This script emulates queue_log events for outgoing calls.
# Use:
# exten => 426,1,DeadAGI(queueDial.agi|34|SIP/34|queue-dps|Agent/101)
#
# The following params must be passed:
# - the caller*ID of the number you are trying to dial. Usually the number itself.
# - the actual dial string, like SIP/34, or IAX2/usr:pass@iax.server/34
# - the outbound queue to be used for accounting. Must be defined in QueueMetrics
# - the agent placing the call. Like Agent/123
#
# RESULTS
# If the call can go through, the events ENTERQUEUE, CONNECT and COMPLETEAGENT or
# COMPLETECALLER will be generated on the system queue_log file.
# If the call is not answered, the events ENTERQUEUE and ABANDON are generated.
#
# Extensive debugging output available at $logfile
#

my $logfile  = "/var/log/asterisk/agi-log.txt";
my $queuelog = "/var/log/asterisk/queue_log";

# Entering the program
logit(0,  "QueueDial ---- " . $ARGV[0] . "- " . $ARGV[1] ."----" . (scalar localtime) );

my $NUMBER  = $ARGV[0];
my $CHANNEL = $ARGV[1];
my $QUEUE   = $ARGV[2];
my $AGENT   = $ARGV[3];

logit( 0, "Dial Num: '$NUMBER' Chan: '$CHANNEL' on Queue: '$QUEUE' Agent: '$AGENT'");

#legge stdin
my %AGI_IN;
while ( my $rl = <STDIN>  ){
        chomp $rl;
        $AGI_IN{$1} = $2 if $rl =~ /^(.+?): (.+)/;
#       logit(0, "In:   $1: '$2'");
        last if length( $rl ) == 0;
}
#logit( 0, "-fine args-");
my $callId = $AGI_IN{'agi_uniqueid'};

#imposta le variabili del canale che saranno lette dal manager
setVar( "QDIALER_NUMBER" , $NUMBER );
setVar( "QDIALER_CHANNEL", $CHANNEL);
setVar( "QDIALER_QUEUE"  , $QUEUE  );
setVar( "QueueName"      , $QUEUE  );
setVar( "QDIALER_AGENT"  , $AGENT  );
#setVar( "CDR(accountcode)", "1234" );


my $nowStart = time();
logQueue( $nowStart, $callId, $QUEUE, "NONE", "ENTERQUEUE", "-", $NUMBER );
logQueue( $nowStart, $callId, $QUEUE, $AGENT, "CONNECT", 0, "" );
#logit( 0, "Chiamo $CHANNEL" );

$whoHung = cmd( "EXEC dial \"$CHANNEL||g\"" );

my $nowEnd = time();
my $asweredTime = getVar( "ANSWEREDTIME" )  ;
my $dialStatus  = getVar( "DIALSTATUS" );
$answeredTime = getVar( "ANSWEREDTIME" ) ;

logit(0, "Hangup: '$whoHung' AT: '$answeredTime' DS: '$dialStatus'" );

if ( $answeredTime == 0 ) {
        my $waitTime = ( $nowEnd - $nowStart );
        logit( 0, "EXITTIMEOUT $nowEnd" );
        logQueue( $nowEnd, $callId, $QUEUE, "NONE", "ABANDON", "1", "1|$waitTime" );
} else {
        my $waitTime = ( $nowEnd - $nowStart ) - $answeredTime;
        my $connectTime = $nowEnd - $answeredTime;
        my $verb = ( $whoHung ? "COMPLETEAGENT" : "COMPLETECALLER" );

        logit( 0, "$connectTime - $nowEnd - $verb - $waitTime - $answeredTime ");

        logQueue( $connectTime, $callId, $QUEUE, $AGENT, "CONNECT", $waitTime, "" );
        logQueue( $nowEnd,      $callId, $QUEUE, $AGENT, $verb, $waitTime, $answeredTime );
}

logit( 0, "Terminating" );

exit;



#
# appoggio
#

sub logit {
        my ($level, $string) = @_;
        open L, ">>$logfile" or die "$! $logfile";
        print L "*" . $string . "\n";
        close L;
}

sub cmd {
        my ( $c ) = @_;
        print $c . "\n";
        my $rIn = <STDIN>;
        my $res = "";
        logit( 1, "Cmd: $c\n" );
        logit( 1, "  A: $rIn\n" );
        $res = $1 if $rIn =~ /^200 result=(.+)/;
        return $res;
}

sub getVar {
        my ( $v ) = @_;
        print "GET VARIABLE $v\n";
        my $rIn = <STDIN>;
        my $rOut = "";
        $rOut = "$1" if $rIn =~ /^200 result=1 \((.+)\)/;
        logit( 0, "GetVar: '$v' = '$rOut'");
        return $rOut;
}

sub setVar {
        my ( $var, $val ) = @_;
        print "SET VARIABLE $var $val\n";
        my $rIn = <STDIN>;
        logit( 0, "SetVar: '$var' = '$val' - $rIn" );
}

sub logQueue {
        my ( $t, $c, $q, $a, $p1, $p2, $p3 ) = @_;
        open F, ">>$queuelog" or die "$!";
        print F "$t|$c|$q|$a|$p1|$p2|$p3\n";
        close F;
}



# ===================================================================
# $Log: queueDial.agi,v $
# Revision 1.5  2007/04/18 12:07:46  lenz
# Copyright messages.
#
# Revision 1.4  2007/04/14 10:09:11  lenz
# Aggiunta var standard QueueName al canale.
#
# Revision 1.3  2007/03/29 21:29:43  lenz
# Channel variables per Manager
#
#

Any help would be appreciated    ;)

KM

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: queueDial.agi not working
« Reply #1 on: February 01, 2008, 10:45:00 »

tank30

  • Newbie
  • *
  • Posts: 46
  • Karma: 0
    • View Profile
Re: queueDial.agi not working
« Reply #2 on: February 04, 2008, 15:47:49 »
dos2unix actually made the script being executed, thank you!

I missed this in the faq... ::)

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: queueDial.agi not working
« Reply #3 on: February 06, 2008, 09:16:50 »
Don't worry, that's why we have FAQs  ;D

Wessel

  • Newbie
  • *
  • Posts: 18
  • Karma: 2
    • View Profile
Re: queueDial.agi not working
« Reply #4 on: June 13, 2008, 18:16:20 »
Addition to the FAQ
4. Check if the file /var/log/asterisk/agi-log.txt is read/writeable by Asterisk


Wessel

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: queueDial.agi not working
« Reply #5 on: June 14, 2008, 13:53:33 »
We're going to move to a full-scripting solution anyway.