Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
Two suggestions - 1. Make sure your AGI has the proper syntax/handling -
just because it "works" doesn't mean that it will be happy in the more
"restrictive" environment of a dialplan call. 
2.  If you are 100% certain that #1 has been addressed, change utils.c line
968 from
ast_log(LOG_ERROR, "write() returned error: %s\n", strerror(errno));
to 
ast_log(LOG_WARNING, "write() returned error: %s\n", strerror(errno));

and do a new make;make install.


-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 3:51 AM
To: Asterisk Mailing List
Subject: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

I have upgraded Asterisk from 1.4.22 to 1.4.30 and I have noticed I am 
getting a lot of errors like this on the console :-
ERROR[23912]: utils.c:968 ast_carefulwrite: write() returned error: 
Broken pipe

I have tracked it down to a perl AGI script which performs our own CDR 
recording. It is called before the start of the call, once answered and 
again when the call is hungup.
It works fine when called before dialing and the AGI debugging shows 
asterisk sending the STDIN to the script very fast. When called after 
answering and at the end of the call asterisk is much slower sending the 
STDIN and I can see the debug scrolling up the screen and this is what 
is causing the error as the AGI script finished and exits before all the 
STDIN is sent. Even if I add a pause at the end of the script for 1 
second it only gets half way through sending the STDIN.

Why is asterisk so slow in sending the call info via STDIn in these cases?
Is there any way this can be fixed?

Thanks

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Philipp von Klitzing
Hi!

> Why is asterisk so slow in sending the call info via STDIn in these cases?
> Is there any way this can be fixed?

Your AGI script is faulty: In at least one place you have missed to READ 
the output right after you have issued a command. So go check your script 
("agi debug" might help a little with this).

Others would say: Your script violates the AGI protocol.

Philipp


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
Check out this snippet from "Tilghman Lesher" (one of the true Asterisk
Guru's)
http://www.mail-archive.com/asterisk-users@lists.digium.com/msg220482.html

It's a "NAG" (my term) introduced in the jump from 1.4.22 to 1.4.23 and
carried out through the rest of the 1.4 tree.

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 3:51 AM
To: Asterisk Mailing List
Subject: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

I have upgraded Asterisk from 1.4.22 to 1.4.30 and I have noticed I am 
getting a lot of errors like this on the console :-
ERROR[23912]: utils.c:968 ast_carefulwrite: write() returned error: 
Broken pipe

I have tracked it down to a perl AGI script which performs our own CDR 
recording. It is called before the start of the call, once answered and 
again when the call is hungup.
It works fine when called before dialing and the AGI debugging shows 
asterisk sending the STDIN to the script very fast. When called after 
answering and at the end of the call asterisk is much slower sending the 
STDIN and I can see the debug scrolling up the screen and this is what 
is causing the error as the AGI script finished and exits before all the 
STDIN is sent. Even if I add a pause at the end of the script for 1 
second it only gets half way through sending the STDIN.

Why is asterisk so slow in sending the call info via STDIn in these cases?
Is there any way this can be fixed?

Thanks

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Danny Nicholas wrote:
> Check out this snippet from "Tilghman Lesher" (one of the true Asterisk
> Guru's)
> http://www.mail-archive.com/asterisk-users@lists.digium.com/msg220482.html
> 

Thanks but that appears related to AMI not AGI.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Philipp von Klitzing wrote:
> Hi!
> 
>> Why is asterisk so slow in sending the call info via STDIn in these cases?
>> Is there any way this can be fixed?
> 
> Your AGI script is faulty: In at least one place you have missed to READ 
> the output right after you have issued a command. So go check your script 
> ("agi debug" might help a little with this).
> 
> Others would say: Your script violates the AGI protocol.

The script performs call logging to a database. Similar to the built in 
CDR but it updates at the start and answering of a call aswell so the 
database can be used to show current call status.

The script does not issue any commands. The same script is called at all 
3 stages but with different parameters on the command line to indicate 
the call status. Works fine before the call is answered but during and 
at the end of the call it quits before asterisk has finished sending the 
information about the current call via STDIN.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
Can you post the script?

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 9:00 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

Philipp von Klitzing wrote:
> Hi!
> 
>> Why is asterisk so slow in sending the call info via STDIn in these
cases?
>> Is there any way this can be fixed?
> 
> Your AGI script is faulty: In at least one place you have missed to READ 
> the output right after you have issued a command. So go check your script 
> ("agi debug" might help a little with this).
> 
> Others would say: Your script violates the AGI protocol.

The script performs call logging to a database. Similar to the built in 
CDR but it updates at the start and answering of a call aswell so the 
database can be used to show current call status.

The script does not issue any commands. The same script is called at all 
3 stages but with different parameters on the command line to indicate 
the call status. Works fine before the call is answered but during and 
at the end of the call it quits before asterisk has finished sending the 
information about the current call via STDIN.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Danny Nicholas wrote:
> Can you post the script?
> 

Yes private stuff is in a separate file. $mode=start works fine but 
answered and completed cause the problem.
I dont know if it is a problem with teh AGI script or just the newer 
asterisk reporting it as an error. It doesnt effect functionality but 
just gives a lot of console output and logging which is undesireable.

Thanks
Gareth



#!/usr/bin/perl -I /var/lib/asterisk/agi-bin/includes

package Asterisk::AGIwrap;
use strict;
use base 'Asterisk::AGI';

sub set_variable
   {
 my ($self, %vars) = @_;
 while (my($var,$val) = each %vars)
   {
 if (!defined($val))
   { warn "AGI->set_variable: not setting '$var' because value 
was undef\n"; next; }
 #warn "AGI->set_variable('$var','$val')\n";
 $self->SUPER::set_variable($var, $val);
   }
   }

package main;
use strict;

our $application = "service_nts_nextgen";
our $subagent = "AGI - $application";
open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
open(STDERR,">>/var/log/agi_$application.err") or die "Failed to 
redirect STDERR";

my $settings = require '/var/lib/asterisk/agi-bin/skycom_gw_settings.pl';
our $gatewayID = $settings->{'gatewayID'};
my ($dbname, $dbhost, $dbport, $dbuser, $dbpass) = 
@{%{$settings->{'db'}}}{'name','host','port','user','pass'};

my $db;

eval
   {
 use DBI;
 $db = DBI->connect("DBI:mysql:$dbname:$dbhost:$dbport", $dbuser, 
$dbpass, $settings->{'dbopt'}) || die "Cannot connect to database: 
$DBI::errstr";

 our $AGI = new Asterisk::AGIwrap;

 print STDERR scalar localtime, "  RUNNING:$0 ", (map {"\"$_\" "} 
@ARGV), "\n";
 our $mode = $ARGV[0];
 my %ARG = ();
 if ($mode =~ /mode=(.*)/)
   {
 $ARG{'mode'} = $mode = $1;
 foreach my $arg (@ARGV)
   {
 $arg =~ /^(\w+)=(.*)$/ || next;
 $ARG{$1} = $arg = $2;
   }
   }

 our $not_recognised = 0;
 my $func;

 if ($mode eq "start")
   {
 $func = require 
'/var/lib/asterisk/agi-bin/service_nts_nextgen-start.pl';
 &$func('db'=>$db, 'AGI'=>$AGI, 'settings'=>$settings);
   }

 elsif ($mode eq "answered")
   {
 my $uniqueID = $ARGV[1];
 my $uniqueIDB = $ARGV[2];
 my $destination = $ARGV[3];
 my $destination_type = $ARGV[4];
 my $destination_args = $ARGV[5];
 my $destination_carrier = $ARGV[6];
 $destination =~ s/^00//; # International
 $destination =~ s/^0([1-9]+)/44$1/; # UK
 my $args = {
 #'destination_type_id' => '"'.$destination_type.'"',
 'answer_time' => 'NOW()',
 'answer_epoch' => 'UNIX_TIMESTAMP()',
 'uniqueIDB' => '"'.$uniqueIDB.'"',
 'ddi' => '"'.$destination.'"',
 'carriernameID' => carriernameID($destination_carrier)
};
 if ($destination_type)
   { $args->{'destination_type_id'} = '"'.$destination_type.'"'; }
 if ($destination_args ne '') { $args->{'destination_args'} = 
'"'.$destination_args.'"'; }
 if (defined($ARG{'params'}))
   { $args->{'extra_params'} = 
$db->quote(urlstr_to_miniserial($ARG{'params'})); }
 &updateCDR($uniqueID,$args,$db);
   }

 elsif ($mode eq "completed")
   {
 my $uniqueID = $ARGV[1];
 my $status = $ARGV[2];
 my $failedpredial = $ARGV[4];
 if ($uniqueID eq "") { $uniqueID = $ARGV[3]; }
 if ($status eq "" && $failedpredial ne "1") { $status = "FAILED"; }
 my $destination_type = ($ARGV[6] =~ /^\d+$/ ? $ARGV[6] : 0);
 my $dest_arg = $ARGV[7];
 my $connect_epoch = $ARGV[8] || 0;

 my $args = {
 'end_time' => 'NOW()',
 'end_epoch' => 'UNIX_TIMESTAMP()',
 'duration' => '(UNIX_TIMESTAMP(NOW()) - 
UNIX_TIMESTAMP(start_time))',
 'carriernameID' => carriernameID($ARGV[5]),
 'connect_epoch'=>$connect_epoch,
 ($destination_type ? 
('destination_type_id'=>$destination_type) : ()),
};
 if (defined($ARG{'params'}))
   { $args->{'extra_params'} = 
$db->quote(urlstr_to_miniserial($ARG{'params'})); }
 if ($status eq "VOICEMAIL")
   {
 $args->{'destination_type_id'} = 3;
 $status = "ANSWER";
   }
 if ($status eq "ANNOUNCEMENT")
   {
 $args->{'destination_type_id'} = 6;
 $status = "ANSWER";
   }
 if ($destination_type == 1)
   {
 if ($dest_arg =~ /^\d+$/)
   {
 if ($dest_arg =~ /^00/)
   { $dest_arg =~ s/^00//; }
 elsif ($dest_arg =~ /^0[1-9]/)
   { $dest_arg =~ s/^0/44/; }
 $args->{'ddi'} = $db->quote($dest_arg);
   }
   }
 elsif ($destination_type > 1)
 

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
Just a hunch - add ; after line 15 and give it a whirl.

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 9:47 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

Danny Nicholas wrote:
> Can you post the script?
> 

Yes private stuff is in a separate file. $mode=start works fine but 
answered and completed cause the problem.
I dont know if it is a problem with teh AGI script or just the newer 
asterisk reporting it as an error. It doesnt effect functionality but 
just gives a lot of console output and logging which is undesireable.

Thanks
Gareth



#!/usr/bin/perl -I /var/lib/asterisk/agi-bin/includes

package Asterisk::AGIwrap;
use strict;
use base 'Asterisk::AGI';

sub set_variable
   {
 my ($self, %vars) = @_;
 while (my($var,$val) = each %vars)
   {
 if (!defined($val))
   { warn "AGI->set_variable: not setting '$var' because value 
was undef\n"; next; }
 #warn "AGI->set_variable('$var','$val')\n";
 $self->SUPER::set_variable($var, $val);
   }
   }

package main;
use strict;

our $application = "service_nts_nextgen";
our $subagent = "AGI - $application";
open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
open(STDERR,">>/var/log/agi_$application.err") or die "Failed to 
redirect STDERR";

my $settings = require '/var/lib/asterisk/agi-bin/skycom_gw_settings.pl';
our $gatewayID = $settings->{'gatewayID'};
my ($dbname, $dbhost, $dbport, $dbuser, $dbpass) = 
@{%{$settings->{'db'}}}{'name','host','port','user','pass'};

my $db;

eval
   {
 use DBI;
 $db = DBI->connect("DBI:mysql:$dbname:$dbhost:$dbport", $dbuser, 
$dbpass, $settings->{'dbopt'}) || die "Cannot connect to database: 
$DBI::errstr";

 our $AGI = new Asterisk::AGIwrap;

 print STDERR scalar localtime, "  RUNNING:$0 ", (map {"\"$_\" "} 
@ARGV), "\n";
 our $mode = $ARGV[0];
 my %ARG = ();
 if ($mode =~ /mode=(.*)/)
   {
 $ARG{'mode'} = $mode = $1;
 foreach my $arg (@ARGV)
   {
 $arg =~ /^(\w+)=(.*)$/ || next;
 $ARG{$1} = $arg = $2;
   }
   }

 our $not_recognised = 0;
 my $func;

 if ($mode eq "start")
   {
 $func = require 
'/var/lib/asterisk/agi-bin/service_nts_nextgen-start.pl';
 &$func('db'=>$db, 'AGI'=>$AGI, 'settings'=>$settings);
   }

 elsif ($mode eq "answered")
   {
 my $uniqueID = $ARGV[1];
 my $uniqueIDB = $ARGV[2];
 my $destination = $ARGV[3];
 my $destination_type = $ARGV[4];
 my $destination_args = $ARGV[5];
 my $destination_carrier = $ARGV[6];
 $destination =~ s/^00//; # International
 $destination =~ s/^0([1-9]+)/44$1/; # UK
 my $args = {
 #'destination_type_id' => '"'.$destination_type.'"',
 'answer_time' => 'NOW()',
 'answer_epoch' => 'UNIX_TIMESTAMP()',
 'uniqueIDB' => '"'.$uniqueIDB.'"',
 'ddi' => '"'.$destination.'"',
 'carriernameID' => carriernameID($destination_carrier)
};
 if ($destination_type)
   { $args->{'destination_type_id'} = '"'.$destination_type.'"'; }
 if ($destination_args ne '') { $args->{'destination_args'} = 
'"'.$destination_args.'"'; }
 if (defined($ARG{'params'}))
   { $args->{'extra_params'} = 
$db->quote(urlstr_to_miniserial($ARG{'params'})); }
 &updateCDR($uniqueID,$args,$db);
   }

 elsif ($mode eq "completed")
   {
 my $uniqueID = $ARGV[1];
 my $status = $ARGV[2];
 my $failedpredial = $ARGV[4];
 if ($uniqueID eq "") { $uniqueID = $ARGV[3]; }
 if ($status eq "" && $failedpredial ne "1") { $status = "FAILED"; }
 my $destination_type = ($ARGV[6] =~ /^\d+$/ ? $ARGV[6] : 0);
 my $dest_arg = $ARGV[7];
 my $connect_epoch = $ARGV[8] || 0;

 my $args = {
 'end_time' => 'NOW()&#x

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
You mean as in :- ?

sub set_variable
   {
 my ($self, %vars) = @_;
 while (my($var,$val) = each %vars)
   {
 if (!defined($val))
   { warn "AGI->set_variable: not setting '$var' because value 
was undef\n"; next; }
 #warn "AGI->set_variable('$var','$val')\n";
 $self->SUPER::set_variable($var, $val);
 ;
   }
   }

It didnt work. The AGI script hung the dialplan before attempting to dial

Thanks

Danny Nicholas wrote:
> Just a hunch - add ; after line 15 and give it a whirl.
> 
> -Original Message-
> From: asterisk-users-boun...@lists.digium.com
> [mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
> Sent: Wednesday, April 28, 2010 9:47 AM
> To: Asterisk Users Mailing List - Non-Commercial Discussion
> Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
> script
> 
> Danny Nicholas wrote:
>> Can you post the script?
>>
> 
> Yes private stuff is in a separate file. $mode=start works fine but 
> answered and completed cause the problem.
> I dont know if it is a problem with teh AGI script or just the newer 
> asterisk reporting it as an error. It doesnt effect functionality but 
> just gives a lot of console output and logging which is undesireable.
> 
> Thanks
> Gareth
> 
> 
> 
> #!/usr/bin/perl -I /var/lib/asterisk/agi-bin/includes
> 
> package Asterisk::AGIwrap;
> use strict;
> use base 'Asterisk::AGI';
> 
> sub set_variable
>{
>  my ($self, %vars) = @_;
>  while (my($var,$val) = each %vars)
>{
>  if (!defined($val))
>{ warn "AGI->set_variable: not setting '$var' because value 
> was undef\n"; next; }
>  #warn "AGI->set_variable('$var','$val')\n";
>  $self->SUPER::set_variable($var, $val);
>}
>}
> 
> package main;
> use strict;
> 
> our $application = "service_nts_nextgen";
> our $subagent = "AGI - $application";
> open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
> open(STDERR,">>/var/log/agi_$application.err") or die "Failed to 
> redirect STDERR";
> 
> my $settings = require '/var/lib/asterisk/agi-bin/skycom_gw_settings.pl';
> our $gatewayID = $settings->{'gatewayID'};
> my ($dbname, $dbhost, $dbport, $dbuser, $dbpass) = 
> @{%{$settings->{'db'}}}{'name','host','port','user','pass'};
> 
> my $db;
> 
> eval
>{
>  use DBI;
>  $db = DBI->connect("DBI:mysql:$dbname:$dbhost:$dbport", $dbuser, 
> $dbpass, $settings->{'dbopt'}) || die "Cannot connect to database: 
> $DBI::errstr";
> 
>  our $AGI = new Asterisk::AGIwrap;
> 
>  print STDERR scalar localtime, "  RUNNING:$0 ", (map {"\"$_\" "} 
> @ARGV), "\n";
>  our $mode = $ARGV[0];
>  my %ARG = ();
>  if ($mode =~ /mode=(.*)/)
>{
>  $ARG{'mode'} = $mode = $1;
>  foreach my $arg (@ARGV)
>{
>  $arg =~ /^(\w+)=(.*)$/ || next;
>  $ARG{$1} = $arg = $2;
>}
>}
> 
>  our $not_recognised = 0;
>  my $func;
> 
>  if ($mode eq "start")
>{
>  $func = require 
> '/var/lib/asterisk/agi-bin/service_nts_nextgen-start.pl';
>  &$func('db'=>$db, 'AGI'=>$AGI, 'settings'=>$settings);
>}
> 
>  elsif ($mode eq "answered")
>{
>  my $uniqueID = $ARGV[1];
>  my $uniqueIDB = $ARGV[2];
>  my $destination = $ARGV[3];
>  my $destination_type = $ARGV[4];
>  my $destination_args = $ARGV[5];
>  my $destination_carrier = $ARGV[6];
>  $destination =~ s/^00//; # International
>  $destination =~ s/^0([1-9]+)/44$1/; # UK
>  my $args = {
>  #'destination_type_id' => '"'.$destination_type.'"',
>  'answer_time' => 'NOW()',
>  'answer_epoch' => 'UNIX_TIMESTAMP()',
>  'uniqueIDB' => '"'.$uniqueIDB.'"',
>  'ddi' => '"'.$destination.'"',
>  'carriernameID' => carriernameID($destination_carrier)
> };
>

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
Darn, that should have worked.  The "improvement" from 1.4.22 to 1.4.23+
basically requires that every "print STDOUT" line be followed by a 
to make util.c not choke when doing commands/setting variables.  I wonder
how this "rewrite" would work?
sub set_variable
   {
 my ($self, %vars) = @_;
 while (my($var,$val) = each %vars)
   {
 if (!defined($val))
   { warn "AGI->set_variable: not setting '$var' because value 
was undef\n"; next; }
 print STDOUT "SET VARIABLE $var \"$val\" \r\n";
 ;
   }
   }

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 10:05 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

You mean as in :- ?

sub set_variable
   {
 my ($self, %vars) = @_;
 while (my($var,$val) = each %vars)
   {
 if (!defined($val))
   { warn "AGI->set_variable: not setting '$var' because value 
was undef\n"; next; }
 #warn "AGI->set_variable('$var','$val')\n";
 $self->SUPER::set_variable($var, $val);
 ;
   }
   }

It didnt work. The AGI script hung the dialplan before attempting to dial

Thanks

Danny Nicholas wrote:
> Just a hunch - add ; after line 15 and give it a whirl.
> 
> -Original Message-
> From: asterisk-users-boun...@lists.digium.com
> [mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth
Blades
> Sent: Wednesday, April 28, 2010 9:47 AM
> To: Asterisk Users Mailing List - Non-Commercial Discussion
> Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
> script
> 
> Danny Nicholas wrote:
>> Can you post the script?
>>
> 
> Yes private stuff is in a separate file. $mode=start works fine but 
> answered and completed cause the problem.
> I dont know if it is a problem with teh AGI script or just the newer 
> asterisk reporting it as an error. It doesnt effect functionality but 
> just gives a lot of console output and logging which is undesireable.
> 
> Thanks
> Gareth
> 
> 
> 
> #!/usr/bin/perl -I /var/lib/asterisk/agi-bin/includes
> 
> package Asterisk::AGIwrap;
> use strict;
> use base 'Asterisk::AGI';
> 
> sub set_variable
>{
>  my ($self, %vars) = @_;
>  while (my($var,$val) = each %vars)
>{
>  if (!defined($val))
>{ warn "AGI->set_variable: not setting '$var' because value 
> was undef\n"; next; }
>  #warn "AGI->set_variable('$var','$val')\n";
>  $self->SUPER::set_variable($var, $val);
>}
>}
> 
> package main;
> use strict;
> 
> our $application = "service_nts_nextgen";
> our $subagent = "AGI - $application";
> open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
> open(STDERR,">>/var/log/agi_$application.err") or die "Failed to 
> redirect STDERR";
> 
> my $settings = require '/var/lib/asterisk/agi-bin/skycom_gw_settings.pl';
> our $gatewayID = $settings->{'gatewayID'};
> my ($dbname, $dbhost, $dbport, $dbuser, $dbpass) = 
> @{%{$settings->{'db'}}}{'name','host','port','user','pass'};
> 
> my $db;
> 
> eval
>{
>  use DBI;
>  $db = DBI->connect("DBI:mysql:$dbname:$dbhost:$dbport", $dbuser, 
> $dbpass, $settings->{'dbopt'}) || die "Cannot connect to database: 
> $DBI::errstr";
> 
>  our $AGI = new Asterisk::AGIwrap;
> 
>  print STDERR scalar localtime, "  RUNNING:$0 ", (map {"\"$_\" "} 
> @ARGV), "\n";
>  our $mode = $ARGV[0];
>  my %ARG = ();
>  if ($mode =~ /mode=(.*)/)
>{
>  $ARG{'mode'} = $mode = $1;
>  foreach my $arg (@ARGV)
>{
>  $arg =~ /^(\w+)=(.*)$/ || next;
>  $ARG{$1} = $arg = $2;
>}
>}
> 
>  our $not_recognised = 0;
>  my $func;
> 
>  if ($mode eq "start")
>{
>  $func = require 
> '/var/lib/asterisk/agi-bin/service_nts_nextgen-start.pl';
>  &$func('db'=>$db, 'AGI'=>$AGI, 'settings'=>$settings);
>}
> 
>  elsif ($mode eq "answered")
>{
>  my $uniqueID = $ARGV[1];
&g

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Steve Edwards
On Wed, 28 Apr 2010, Gareth Blades wrote:

> The script does not issue any commands. The same script is called at all 
> 3 stages but with different parameters on the command line to indicate 
> the call status. Works fine before the call is answered but during and 
> at the end of the call it quits before asterisk has finished sending the 
> information about the current call via STDIN.

As others have said -- you are violating the protocol.

Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
read it, you are violating the protocol.

For a AGI that is called repeatedly, maybe you should consider 
implementing it in a compiled language.

You can execute XXX AGIs written in C in the time it takes to load the 
Perl interpreter and parse your script.

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Steve Edwards wrote:
> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
>> The script does not issue any commands. The same script is called at all 
>> 3 stages but with different parameters on the command line to indicate 
>> the call status. Works fine before the call is answered but during and 
>> at the end of the call it quits before asterisk has finished sending the 
>> information about the current call via STDIN.
> 
> As others have said -- you are violating the protocol.
> 
> Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
> read it, you are violating the protocol.
> 
> For a AGI that is called repeatedly, maybe you should consider 
> implementing it in a compiled language.
> 
> You can execute XXX AGIs written in C in the time it takes to load the 
> Perl interpreter and parse your script.
> 

We are reading in the STDIN (assume its part of the asterisk perl 
module). If I add a 3 second pause to the end of the perl code then it 
works fine. But if this is the case then for a system with a high call 
volume this significantly increases the number of running AGI programs 
which is not good for system load.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Fred Posner
On Apr 28, 2010, at 11:30 AM, Steve Edwards wrote:

> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
>> The script does not issue any commands. The same script is called at all 
>> 3 stages but with different parameters on the command line to indicate 
>> the call status. Works fine before the call is answered but during and 
>> at the end of the call it quits before asterisk has finished sending the 
>> information about the current call via STDIN.
> 
> As others have said -- you are violating the protocol.
> 
> Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
> read it, you are violating the protocol.
> 
> For a AGI that is called repeatedly, maybe you should consider 
> implementing it in a compiled language.
> 
> You can execute XXX AGIs written in C in the time it takes to load the 
> Perl interpreter and parse your script.
> 
> -- 


Of course this will turn into a religious war ;)

Bottom line, if you like perl, use perl. Even though C is faster, there are 
benefits to using a language you know as well as implementing it for other 
reasons. I end up using perl 99% of the time just for simple ability with MySQL 
stored procedures or connecting ease with MSSQL databases. That being said...

Try starting your script with something such as:

$|=1;

while() {
chomp;
last unless length($_);
}

(of course you can add whatever you want in there to pull the variables...

For setting multiple asterisk variables, I like using a sub:

sub setvariable {
my ($variable, $value) = @_;
print STDOUT "SET VARIABLE $variable \"$value\" \n";
while() {
m/200 result=1/ && last;
}
return;
}

then just call it with something like:

&setvariable("MAILBOX", $mailbox);


--fred
http://qxork.com
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Danny Nicholas wrote:
> Darn, that should have worked.  The "improvement" from 1.4.22 to 1.4.23+
> basically requires that every "print STDOUT" line be followed by a 
> to make util.c not choke when doing commands/setting variables.  I wonder
> how this "rewrite" would work?
> sub set_variable
>{
>  my ($self, %vars) = @_;
>  while (my($var,$val) = each %vars)
>{
>  if (!defined($val))
>{ warn "AGI->set_variable: not setting '$var' because value 
> was undef\n"; next; }
>  print STDOUT "SET VARIABLE $var \"$val\" \r\n";
>  ;
>}
>}
> 

I dont think that routine is the issue. Its only called when setting the 
  variables and that is only done before the call is dialed and in that 
case the script generates no errors :-

 -- Executing [08454632...@service_nts_nextgen_v2:1] AGI("Zap/5-1", 
"service_nts_nextgen|mode=start|") in new stack
 -- Launched AGI Script /var/lib/asterisk/agi-bin/service_nts_nextgen
AGI Tx >> agi_request: service_nts_nextgen
AGI Tx >> agi_channel: Zap/5-1
AGI Tx >> agi_language: en
AGI Tx >> agi_type: Zap
AGI Tx >> agi_uniqueid: 1272469456.5
AGI Tx >> agi_callerid: 1276459900
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 1
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 33
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 08454632504
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: service_nts_nextgen_v2
AGI Tx >> agi_extension: 08454632504
AGI Tx >> agi_priority: 1
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >> >
AGI Rx << SET VARIABLE __item_count "0"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __custid "13361"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __dniascli "0"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE __cliorig
AGI Tx >> 200 result=0
AGI Rx << VERBOSE "Route To Number: 447584255419" 1
   service_nts_nextgen|mode=start|: Route To Number: 447584255419
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1 "07584255419"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_type_1 "number"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_type_id_1 "1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1 "Zap/g1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __numcarriers_1 "2"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_carrier_1_2 "PSTN:DEFAULT"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1_2 "07584255419"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1_2 "Zap/g1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_carrier_1_1 "SIP:MAGRATHEA"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1_1 "07584255...@magrathea"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1_1 "SIP"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __item_count "1"
AGI Tx >> 200 result=1
 -- AGI Script service_nts_nextgen completed, returning 0

The problem is with where the mode is answered or completed when I get 
errors like this :-

 -- Executing [...@macro-service-nts-nextgenv2-register-answer:3] 
AGI("SIP/magrathea-0002", 
"service_nts_nextgen|mode=answered|1272469456.5|1272469457.6|07584255419|1||SIP:MAGRATHEA|params=")
 
in new stack
 -- Launched AGI Script /var/lib/asterisk/agi-bin/service_nts_nextgen
AGI Tx >> agi_request: service_nts_nextgen
AGI Tx >> agi_channel: SIP/magrathea-0002
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1272469457.6
AGI Tx >> agi_callerid: 08454632504
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 33
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: unknown
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_rdnis: unknown
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_context: macro-service-nts-nextgenv2-register-answer
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_extension: s
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_priority: 3
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_enhanced: 0.0
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >> agi_accountcode:
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
AGI Tx >>
[Apr 28 16:44:34] ERROR[23465]: utils.c:968 ast_carefulwrite: write() 
returned error: Broken pipe
 -- AGI Script service_nts_nextgen completed, returning 0

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a l

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Ryan Bullock
Looking at the Asterisk::AGI docs, maybe try calling ReadParse() early
in the script to read in anything from stdin?

(From the docs)
# pull AGI variables into %input
%input = $AGI->ReadParse();

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Danny Nicholas
FWIW, I would take your STDERR references and give them another handle,
since you're not really trying to produce a CLI/Console output.

The symptoms you have described in this thread are 100% compliant with "AGI
protocol violation (their term not mine)" - the last suggest I would give
you is to do an implicit AGI usage like this:
my $agi;
my %input;
$agi = new Asterisk::AGI;
%input = $agi->ReadParse();

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Gareth Blades
Sent: Wednesday, April 28, 2010 10:50 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

Danny Nicholas wrote:
> Darn, that should have worked.  The "improvement" from 1.4.22 to 1.4.23+
> basically requires that every "print STDOUT" line be followed by a 
> to make util.c not choke when doing commands/setting variables.  I wonder
> how this "rewrite" would work?
> sub set_variable
>{
>  my ($self, %vars) = @_;
>  while (my($var,$val) = each %vars)
>{
>  if (!defined($val))
>{ warn "AGI->set_variable: not setting '$var' because value 
> was undef\n"; next; }
>  print STDOUT "SET VARIABLE $var \"$val\" \r\n";
>  ;
>}
>}
> 

I dont think that routine is the issue. Its only called when setting the 
  variables and that is only done before the call is dialed and in that 
case the script generates no errors :-

 -- Executing [08454632...@service_nts_nextgen_v2:1] AGI("Zap/5-1", 
"service_nts_nextgen|mode=start|") in new stack
 -- Launched AGI Script /var/lib/asterisk/agi-bin/service_nts_nextgen
AGI Tx >> agi_request: service_nts_nextgen
AGI Tx >> agi_channel: Zap/5-1
AGI Tx >> agi_language: en
AGI Tx >> agi_type: Zap
AGI Tx >> agi_uniqueid: 1272469456.5
AGI Tx >> agi_callerid: 1276459900
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 1
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 33
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 08454632504
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: service_nts_nextgen_v2
AGI Tx >> agi_extension: 08454632504
AGI Tx >> agi_priority: 1
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >> >
AGI Rx << SET VARIABLE __item_count "0"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __custid "13361"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __dniascli "0"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE __cliorig
AGI Tx >> 200 result=0
AGI Rx << VERBOSE "Route To Number: 447584255419" 1
   service_nts_nextgen|mode=start|: Route To Number: 447584255419
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1 "07584255419"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_type_1 "number"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_type_id_1 "1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1 "Zap/g1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __numcarriers_1 "2"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_carrier_1_2 "PSTN:DEFAULT"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1_2 "07584255419"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1_2 "Zap/g1"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_carrier_1_1 "SIP:MAGRATHEA"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_number_1_1 "07584255...@magrathea"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __destination_channel_1_1 "SIP"
AGI Tx >> 200 result=1
AGI Rx << SET VARIABLE __item_count "1"
AGI Tx >> 200 result=1
 -- AGI Script service_nts_nextgen completed, returning 0

The problem is with where the mode is answered or completed when I get 
errors like this :-

 -- Executing [...@macro-service-nts-nextgenv2-register-answer:3] 
AGI("SIP/magrathea-0002", 
"service_nts_nextgen|mode=answered|1272469456.5|1272469457.6|07584255419|1||
SIP:MAGRATHEA|params=") 
in new stack
 -- Launched AGI Script /var/lib/asterisk/agi-bin/service_nts_nextgen
AGI Tx >> agi_request: service_nts_nextgen
AGI Tx >> agi_channel: SIP/magrathea-0002
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1272469457.6
AGI Tx >> agi_c

Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Steve Edwards
>> On Wed, 28 Apr 2010, Gareth Blades wrote:

>>> The script does not issue any commands. The same script is called at 
>>> all 3 stages but with different parameters on the command line to 
>>> indicate the call status. Works fine before the call is answered but 
>>> during and at the end of the call it quits before asterisk has 
>>> finished sending the information about the current call via STDIN.

> Steve Edwards wrote:

>> Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
>> read it, you are violating the protocol.

On Wed, 28 Apr 2010, Gareth Blades wrote:

> We are reading in the STDIN (assume its part of the asterisk perl 
> module). If I add a 3 second pause to the end of the perl code then it 
> works fine. But if this is the case then for a system with a high call 
> volume this significantly increases the number of running AGI programs 
> which is not good for system load.

How do you reconcile your assumption that the Perl module is reading STDIN 
and your statement that your AGI "quits before asterisk has finished 
sending the information about the current call via STDIN."

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Steve Edwards
On Wed, 28 Apr 2010, Ryan Bullock wrote:

> Looking at the Asterisk::AGI docs, maybe try calling ReadParse() early
> in the script to read in anything from stdin?
>
> (From the docs)
> # pull AGI variables into %input
> %input = $AGI->ReadParse();

"early" == "before (any interaction with Asterisk || exit)"

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Steve Edwards wrote:
>>> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
 The script does not issue any commands. The same script is called at 
 all 3 stages but with different parameters on the command line to 
 indicate the call status. Works fine before the call is answered but 
 during and at the end of the call it quits before asterisk has 
 finished sending the information about the current call via STDIN.
> 
>> Steve Edwards wrote:
> 
>>> Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
>>> read it, you are violating the protocol.
> 
> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
>> We are reading in the STDIN (assume its part of the asterisk perl 
>> module). If I add a 3 second pause to the end of the perl code then it 
>> works fine. But if this is the case then for a system with a high call 
>> volume this significantly increases the number of running AGI programs 
>> which is not good for system load.
> 
> How do you reconcile your assumption that the Perl module is reading STDIN 
> and your statement that your AGI "quits before asterisk has finished 
> sending the information about the current call via STDIN."
> 
Only that if I put a 3 second pause in the script at the end then I get 
no errors. If I put in a 1 second pause I get errors about half way 
through asterisk sending the input.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Steve Edwards
> Steve Edwards wrote:
>>
>> How do you reconcile your assumption that the Perl module is reading 
>> STDIN and your statement that your AGI "quits before asterisk has 
>> finished sending the information about the current call via STDIN."

On Wed, 28 Apr 2010, Gareth Blades wrote:

> Only that if I put a 3 second pause in the script at the end then I get 
> no errors. If I put in a 1 second pause I get errors about half way 
> through asterisk sending the input.

The fact that you have to introduce a pause means that you are doing 
something wrong. It may just mean that Asterisk has finished writing the 
cruft to the created process's STDIN instead of being interrupted in the 
middle, but whatever you are doing is still wrong.

There is an outside chance that you have discovered a bug in Asterisk, but 
considering nobody else has experienced this behavior implies the bug is 
in your code.

Why are you so resistant to this? What evidence do you have that your code 
is correct?

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Gareth Blades
Steve Edwards wrote:
>> Steve Edwards wrote:
>>> How do you reconcile your assumption that the Perl module is reading 
>>> STDIN and your statement that your AGI "quits before asterisk has 
>>> finished sending the information about the current call via STDIN."
> 
> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
>> Only that if I put a 3 second pause in the script at the end then I get 
>> no errors. If I put in a 1 second pause I get errors about half way 
>> through asterisk sending the input.
> 
> The fact that you have to introduce a pause means that you are doing 
> something wrong. It may just mean that Asterisk has finished writing the 
> cruft to the created process's STDIN instead of being interrupted in the 
> middle, but whatever you are doing is still wrong.
> 
> There is an outside chance that you have discovered a bug in Asterisk, but 
> considering nobody else has experienced this behavior implies the bug is 
> in your code.
> 
> Why are you so resistant to this? What evidence do you have that your code 
> is correct?
> 

I am not resistant to it. I didnt write the code and I an not that 
familiar with perl.

It just seemed strange that the debug output from the mode-start script 
run appeared instantly on the screen but for the other AGI code 
executions I could see the debug output scroll up slowly.

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Fred Posner
On Apr 28, 2010, at 1:00 PM, Gareth Blades wrote:

> Steve Edwards wrote:
>>> Steve Edwards wrote:
 How do you reconcile your assumption that the Perl module is reading 
 STDIN and your statement that your AGI "quits before asterisk has 
 finished sending the information about the current call via STDIN."
>> 
>> On Wed, 28 Apr 2010, Gareth Blades wrote:
>> 
>>> Only that if I put a 3 second pause in the script at the end then I get 
>>> no errors. If I put in a 1 second pause I get errors about half way 
>>> through asterisk sending the input.
>> 
>> The fact that you have to introduce a pause means that you are doing 
>> something wrong. It may just mean that Asterisk has finished writing the 
>> cruft to the created process's STDIN instead of being interrupted in the 
>> middle, but whatever you are doing is still wrong.
>> 
>> There is an outside chance that you have discovered a bug in Asterisk, but 
>> considering nobody else has experienced this behavior implies the bug is 
>> in your code.
>> 
>> Why are you so resistant to this? What evidence do you have that your code 
>> is correct?
>> 
> 
> I am not resistant to it. I didnt write the code and I an not that 
> familiar with perl.
> 
> It just seemed strange that the debug output from the mode-start script 
> run appeared instantly on the screen but for the other AGI code 
> executions I could see the debug output scroll up slowly.

Did I miss where the code was posted?

---fred
http://qxork.com






-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Steve Edwards
On Wed, 28 Apr 2010, Fred Posner wrote:

> Did I miss where the code was posted?

Yes. In my mail reader it is Gareth's second post.

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-28 Thread Fred Posner
On Apr 28, 2010, at 1:12 PM, Steve Edwards wrote:

> On Wed, 28 Apr 2010, Fred Posner wrote:
> 
>> Did I miss where the code was posted?
> 
> Yes. In my mail reader it is Gareth's second post.
> 

Thanks. Wish I hadn't looked now.


--fred
http://qxork.com

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-29 Thread Tzafrir Cohen
On Wed, Apr 28, 2010 at 09:34:18AM -0700, Steve Edwards wrote:
> On Wed, 28 Apr 2010, Ryan Bullock wrote:
> 
> > Looking at the Asterisk::AGI docs, maybe try calling ReadParse() early
> > in the script to read in anything from stdin?
> >
> > (From the docs)
> > # pull AGI variables into %input
> > %input = $AGI->ReadParse();
> 
> "early" == "before (any interaction with Asterisk || exit)"

Any reason Asterisk::AGI shouldn't do that automatically?

-- 
   Tzafrir Cohen
icq#16849755  jabber:tzafrir.co...@xorcom.com
+972-50-7952406   mailto:tzafrir.co...@xorcom.com
http://www.xorcom.com  iax:gu...@local.xorcom.com/tzafrir

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-29 Thread Steve Edwards
>> On Wed, 28 Apr 2010, Ryan Bullock wrote:
>>
>>> Looking at the Asterisk::AGI docs, maybe try calling ReadParse() early 
>>> in the script to read in anything from stdin?
>>>
>>> (From the docs)
>>> # pull AGI variables into %input
>>> %input = $AGI->ReadParse();

> On Wed, Apr 28, 2010 at 09:34:18AM -0700, Steve Edwards wrote:
>>
>> "early" == "before (any interaction with Asterisk || exit)"

On Thu, 29 Apr 2010, Tzafrir Cohen wrote:

> Any reason Asterisk::AGI shouldn't do that automatically?

A good question for the author of Asterisk::AGIwrap.

When I wrote my AGI library for C, I thought about it but ultimately 
didn't. If I ever get around to "publishing" my code I would add it just 
to raise the success rate for first time users.

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-29 Thread Danny Nicholas
Speaking from a "Perl'er" perspective, there's no good reason that
Asterisk::AGI shouldn't do the ReadParse automatically except that it
requires the module author to do something that the user should be doing as
a "best practice" and could lead to unexpected errors in a reuse
environment.  IMO there could be more and better Perl modules out there for
use, but I think that most serious Asterisk users probably take Steve's
advice and leave Perl for C once they pass point X.  That or they are
masochistic PHP users :)

-Original Message-
From: asterisk-users-boun...@lists.digium.com
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Steve Edwards
Sent: Thursday, April 29, 2010 1:00 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI
script

>> On Wed, 28 Apr 2010, Ryan Bullock wrote:
>>
>>> Looking at the Asterisk::AGI docs, maybe try calling ReadParse() early 
>>> in the script to read in anything from stdin?
>>>
>>> (From the docs)
>>> # pull AGI variables into %input
>>> %input = $AGI->ReadParse();

> On Wed, Apr 28, 2010 at 09:34:18AM -0700, Steve Edwards wrote:
>>
>> "early" == "before (any interaction with Asterisk || exit)"

On Thu, 29 Apr 2010, Tzafrir Cohen wrote:

> Any reason Asterisk::AGI shouldn't do that automatically?

A good question for the author of Asterisk::AGIwrap.

When I wrote my AGI library for C, I thought about it but ultimately 
didn't. If I ever get around to "publishing" my code I would add it just 
to raise the success rate for first time users.

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-04-29 Thread Steve Edwards
Un-top-posting...

>>> On Wed, 28 Apr 2010, Ryan Bullock wrote:
>>>
 Looking at the Asterisk::AGI docs, maybe try calling ReadParse() 
 early in the script to read in anything from stdin?

 (From the docs)
 # pull AGI variables into %input
 %input = $AGI->ReadParse();
>
>> On Wed, Apr 28, 2010 at 09:34:18AM -0700, Steve Edwards wrote:
>>>
>>> "early" == "before (any interaction with Asterisk || exit)"
>
> On Thu, 29 Apr 2010, Tzafrir Cohen wrote:
>
>> Any reason Asterisk::AGI shouldn't do that automatically?
>
> A good question for the author of Asterisk::AGIwrap.
>
> When I wrote my AGI library for C, I thought about it but ultimately 
> didn't. If I ever get around to "publishing" my code I would add it just 
> to raise the success rate for first time users.

On Thu, 29 Apr 2010, Danny Nicholas wrote:

> Speaking from a "Perl'er" perspective, there's no good reason that 
> Asterisk::AGI shouldn't do the ReadParse automatically except that it 
> requires the module author to do something that the user should be doing 
> as a "best practice" and could lead to unexpected errors in a reuse 
> environment.  IMO there could be more and better Perl modules out there 
> for use, but I think that most serious Asterisk users probably take 
> Steve's advice and leave Perl for C once they pass point X.  That or 
> they are masochistic PHP users :)

The OP's code was using Asterisk::AGIwrap. I'm not a Perl weenie, but I 
think this is an "in-house" package -- Google can't find anything 
relevant.

Adding a simple "have I been initialized?" check at the start of each 
function would help the first time user and would not lead to a reuse 
issue.

-- 
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
Newline  Fax: +1-760-731-3000

-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-05-11 Thread Kingsley Tart
On Wed, 2010-04-28 at 11:07 -0500, Danny Nicholas wrote:
> FWIW, I would take your STDERR references and give them another handle,
> since you're not really trying to produce a CLI/Console output.
> 
> The symptoms you have described in this thread are 100% compliant with "AGI
> protocol violation (their term not mine)" - the last suggest I would give
> you is to do an implicit AGI usage like this:
> my $agi;
> my %input;
> $agi = new Asterisk::AGI;
> %input = $agi->ReadParse();

Hi,

I work with Gareth - we have been working with this together.

Thanks for the suggestion about calling ReadParse() - we didn't need to
use the result of it when calling our AGI script on call answer or
hangup but adding a call to this anyway did remove the "broken pipe"
errors that Gareth was referring to.

I have noticed thought that at the start of the call, we are (in a
separate included file that wasn't posted here) doing a ReadParse()
before doing anything else and in a small percentage of cases, this
appeared to be missing at least some of the variables.

The strange thing is that none of these problems arose with Asterisk
1.4.23 which we have been running for several years prior to this
upgrade to 1.4.30.

Cheers,
Kingsley.


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-05-11 Thread Kingsley Tart
On Wed, 2010-04-28 at 11:47 -0400, Fred Posner wrote:
> > For a AGI that is called repeatedly, maybe you should consider 
> > implementing it in a compiled language.
> > 
> > You can execute XXX AGIs written in C in the time it takes to load the 
> > Perl interpreter and parse your script.

Yes agreed but I don't know C. We are however planning to make this into
a daemon at some point to get around the Perl compiler overhead.

> For setting multiple asterisk variables, I like using a sub:
> 
> sub setvariable {
>   my ($variable, $value) = @_;
>   print STDOUT "SET VARIABLE $variable \"$value\" \n";
>   while() {
>   m/200 result=1/ && last;
>   }
>   return;
> }
> 
> then just call it with something like:
> 
> &setvariable("MAILBOX", $mailbox);

This is essentially what we can do with the AGIwrap package, and for
debugging we can uncomment the "warn" line so that we can see what is
being set at call time. It was done this way because the scripts already
have many references to $AGI->set_variable(blah) so it was easier to put
a wrapper around the method call.


package Asterisk::AGIwrap;
use strict;
use base 'Asterisk::AGI';

sub set_variable
  {
my ($self, %vars) = @_;
while (my($var,$val) = each %vars)
  {
if (!defined($val))
  { warn "AGI->set_variable: not setting '$var' because value was 
undef\n"; next; }
#warn "AGI->set_variable('$var','$val')\n";
$self->SUPER::set_variable($var, $val);
  }
  }

Cheers,
Kingsley.


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users


Re: [asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

2010-05-12 Thread Kingsley Tart
Hi,

I still think we've either got a bug in Asterisk or a bug in the
Asterisk::AGI module.

In a separate part of the dialplan we have a call to a (much simpler)
script that begins with the below code.

In the last 1000 calls, I've had a couple of "extension not returned by
AGI" errors from the script.

Prior to upgrading from Asterisk 1.4.23 we never saw this error in over
10 million calls.

Unless we're doing something obviously wrong here, it would seem that
there's either a bug somewhere in Asterisk or that the Asterisk Perl
modules we have are somehow incompatible with the version of Asterisk
we're now running. $Asterisk::AGI::VERSION returns 1.01 in our
installation.

Any ideas?

#!/usr/bin/perl -w
use strict;
use Asterisk::AGI;

our $AGI = new Asterisk::AGI;
my $cwd = '/var/lib/asterisk/agi-bin';
our $gatewayID;

open(STDERR,">>/var/log/agi_$application.err") or die "Failed to redirect 
STDERR";

eval
  {
my $settings = require "$cwd/gw_settings.pl" || die "Cannot load settings 
from $cwd/gw_settings.pl";
$gatewayID = $settings->{'gatewayID'};

my %input = ($AGI->ReadParse());
my $dni = $input{'extension'} || die 'extension not returned by AGI';
...


-- 
Cheers,
Kingsley.


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
   http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users