Hi. I have the next configuration... I dial from my analog phone in the TDM400P to extension 102, and the second agi works about 1 out of 10 times, the other nine it gives me these error on the asterisk console: -- Starting simple switch on 'Zap/2-1' -- Executing Macro("Zap/2-1", "receivecall") in new stack -- Executing AGI("Zap/2-1", "receivecall.tcl") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/receivecall.tcl -- AGI Script receivecall.tcl completed, returning 0 -- Executing Macro("Zap/2-1", "followme|s|92624663") in new stack -- Executing AGI("Zap/2-1", "followme.tcl") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/followme.tcl == Spawn extension (macro-followme, s, 1) exited non-zero on 'Zap/2-1' in macro 'followme' == Spawn extension (macro-receivecall, s, 2) exited non-zero on 'Zap/2-1' in macro 'receivecall' == Spawn extension (home, 102, 1) exited non-zero on 'Zap/2-1' -- Hungup 'Zap/2-1' and these in /var/log/asterisk/messages: Sep 19 00:31:08 WARNING[458770]: File app_agi.c, Line 1277 (run_agi): No channel, no fd? Any idea on what might be wrong ? I have tested these way of doing a follow me routine on 3 different asterisk boxes, with different setups and i got the same result on all of them. The AGI's are suppoused to do a more complex task, like search in a database for a followme enabled/disable and the number to wich forward the call, etc. but, just for testing purposes, these is giving the same error. Thank's. ============================================== 1) 1 X100P. 2) 1 TDM400P with 1 fxs. ----------------- zaptel.conf ----------------- fxsks=1 fxoks=2 loadzone = us defaultzone=us ------------------- zapata.conf ------------------- [channels] usecallerid=yes hidecallerid=no musiconhold=default callwaiting=yes callwaitingcallerid=yes threewaycalling=yes transfer=yes cancallforward=yes echocancel=yes echocancelwhenbridged=no rxgain=0.1 txgain=0.0 group=1 immediate=no callerid=asreceived context=bell signalling=fxs_ks channel=1 musiconhold=default callerid="Telefono de Estudio"<100> context=home signalling=fxo_ks channel=2 -------------------------------- extensions.conf -------------------------------- [general] NContexto = home NExten = s NPrioridad = 1 NMacro = none NPar1 = s Npar2 = s Extension = s static=yes writeprotect=no [dialout] exten => _9X.,1,StripMSD,1 exten => _X.,2,Dial,Zap/1/BYEXTENSION exten => 500,1,Playback(demo-abouttotry); Let them know what's going on exten => 500,2,Dial(IAX2/guest@misery.digium.com/s@default) ; Call the Asterisk demo exten => 500,3,Playback(demo-nogo) ; Couldn't connect to the demo site [bell] include => mailboxes exten => s,1,setmusiconhold,default exten => s,2,responsetimeout,20 exten => s,3,Dial,Zap/2&SIP/angel&SIP/danny|15|tTm exten => s,4,BackGround,thanks exten => s,104,BackGround,thanksbusy exten => i,1,hangup [mailboxes] exten => 100,1,Voicemail,100 exten => 100,2,Hangup exten => 101,1,Voicemail,101 exten => 101,2,Voicemail, exten => 102,1,Voicemail,102 exten => 102,2,Voicemail, exten => 103,1,Voicemail,103 exten => 103,2,Voicemail, [home] ignorepat => 9 include => dialout include => parkedcalls exten => 004,1,Echo() exten => 004,2,Hangup() exten => 005,1,Meetme() exten => 005,2,Hangup() exten => 008,1,VoicemailMain exten => 008,2,Hangup exten => 007,1,Record,thanks:gsm exten => 007,2,Wait,1 exten => 007,3,Playback,thanks exten => 009,1,MusicOnHold(random) exten => 100,1,setmusiconhold,default exten => 100,2,Dial,Zap/2|20|tTm exten => 100,3,Congestion exten => 100,4,Hangup() exten => 101,1,Dial,SIP/danny|20|tTm exten => 101,2,Congestion exten => 102,1,Macro(receivecall) [macro-receivecall] exten => s,1,agi(receivecall.tcl) exten => s,2,macro(${NMacro}|${NPar1}|${NPar2}) [macro-followme] exten => s,1,agi(followme.tcl) exten => s,2,noop exten => s,3,goto(${NContexto}|${NExten}|1) ------------------------- receivecall.tcl ------------------------- #!/usr/bin/tclsh source /var/lib/asterisk/agi-bin/agilib.tcl parametros puts stdout "SET VARIABLE Extension $agi(extension)" gets stdin linea puts stdout "SET VARIABLE NMacro followme" gets stdin linea puts stdout "SET VARIABLE NPar1 $agi(extension)" gets stdin linea puts stdout "SET VARIABLE NPar2 92624663" gets stdin linea exit 0 -------------------------- followme.tcl -------------------------- #!/usr/bin/tclsh source /var/lib/asterisk/agi-bin/agilib.tcl parametros puts stdout "VERBOSE \"mensaje 1\" 1" gets stdin linea puts stdout "SET VARIABLE NContexto dialout" gets stdin linea puts stdout "VERBOSE \"mensaje 2\" 1" gets stdin linea puts stdout "SET VARIABLE NExten 96388210" gets stdin linea puts stdout "VERBOSE \"mensaje 3\" 1" gets stdin linea exit 0 -------------------------- agilib.tcl ---------------------- proc parametros {} { global agi set linea [gets stdin] while { [string length $linea] > 0 } { set subindice [string first ":" $linea] if { $subindice > 0 } { set agi([string range $linea 4 [expr $subindice-1]]) \ [string trimleft [string range $linea \ [expr $subindice+1] \ [string length $linea]]] } set linea [gets stdin] } } ==============================================================
hi; am using an agi script to do some call forwarding. I got the following pyton script off http://home.cogeco.ca/~camstuff/agi.html: #!/usr/bin/python import sys,string class AGI: """ Class AGI facilitates writing AGI scripts in Python. Exported functions: Write(message): Writes message to Asterisk Console. Cmd(command): Send command to Asterisk, read result. The result is a two element tuple: [0] A text string giving the entire result returned by Asterisk [1] The "result=" integer extracted from the result line If we get an unhappy response from Asterisk or if the result returned to the right of the equals sign is not an integer we issue an error message and terminate the script. Exported Variables: env Dictionary containing the various environment startup items, as passed to us by Asterisk. """ def Write(self,data): """ Write unbuffered line output to STDERR. Ensures data is flushed out. """ sys.stderr.write(str(data) + "\n") sys.stderr.flush() def Cmd(self,command): """ Send an AGI command to Asterisk; read back the response. The result is a two element tuple: [0] A text string giving the entire result returned by Asterisk [1] The "result=" integer extracted from the result line If we get an unhappy response from Asterisk or if the result returned to the right of the equals sign is not an integer we issue an error message and terminate the script. """ try: sys.stdout.write(str(command) + "\n") sys.stdout.flush() Response = sys.stdin.readline() if Response[:11] <> '200 result=': #we didn't get a happy response for AGI raise "AgiError" #accumulate integer portion J = 11 while J < len(Response) and (Response[J] in '0123456789'): J += 1 res = Response[11:J] try: ResInt = int(res) except ValueError: #there is no integer immediatly to the right of the equal sign raise "AgiError" except "AgiError": self.Error('Unexpected response to AGI command.') self.Error('Command: %s'%command) self.Error('Response: %s'%Response) self.Error('Script terminated.') sys.exit() return (Response,ResInt) def __init__(self): """ Read until blank line to get the AGI environment. The lines read are used to build the dictionary 'env'. """ self.env = {1:'moe',2:'joe'} while 1: line = string.strip(sys.stdin.readline()) if line == '': #blank line signals end break key,data = string.split(line,':') key = string.strip(key) data = string.strip(data) if key <> '': self.env[key] = data ================ however i think there is something wrong with initialization code, namely: def __init__(self): """ Read until blank line to get the AGI environment. The lines read are used to build the dictionary 'env'. """ self.env = {1:'moe',2:'joe'} while 1: line = string.strip(sys.stdin.readline()) if line == '': #blank line signals end break key,data = string.split(line,':') key = string.strip(key) data = string.strip(data) if key <> '': self.env[key] = data because when i replace that piece of code with my own hardcode variables things work just fine. Now my question is does anybody have a clue why this code is not working? or alternatively how can i read the environment variables in python? thanks m.smadi
Hmm still have problems with the get variable with PHP i have this error now separated with a script: Sending string GET VARIABLE CALLERIDNUM\n to Asterisk... Wroten bytes to STDOUT: 25 Reading 80 bytes response from Asterisk... Received response: 510 Invalid or unknown command
Quoting "Ren? Enskat [Teamware GmbH]" <ren@teamware-gmbh.de>: In my experience most AGI problems I had came from other info sent to the terminal via verbose commands and other stdout output. There is some info on the voip-info wiki about using AGI. I use the phpagi 2 library, and carefully setting up the agi->verbose commmands fixes my 510 problems> > Hmm still have problems with the get variable with PHP i have this error > now separated with a script: > > Sending string GET VARIABLE CALLERIDNUM\n to Asterisk... > Wroten bytes to STDOUT: 25 > > Reading 80 bytes response from Asterisk... > Received response: 510 Invalid or unknown command > > > > _______________________________________________ > --Bandwidth and Colocation sponsored by Easynews.com -- > > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
I have the phpagi 2 library too. So what did you change in details there to mute the vebrose things?> -----Urspr?ngliche Nachricht----- > Von: asterisk-users-bounces@lists.digium.com > [mailto:asterisk-users-bounces@lists.digium.com] Im Auftrag von Obelix > Gesendet: Montag, 17. Oktober 2005 11:02 > An: Asterisk Users Mailing List - Non-Commercial Discussion > Betreff: Re: [Asterisk-Users] AGI Problem > > Quoting "Ren? Enskat [Teamware GmbH]" <ren@teamware-gmbh.de>: > > In my experience most AGI problems I had came from other info > sent to the terminal via verbose commands and other stdout > output. There is some info on the voip-info wiki about using AGI. > > I use the phpagi 2 library, and carefully setting up the > agi->verbose commmands fixes my 510 problems > > > > > Hmm still have problems with the get variable with PHP i have this > > error now separated with a script: > > > > Sending string GET VARIABLE CALLERIDNUM\n to Asterisk... > > Wroten bytes to STDOUT: 25 > > > > Reading 80 bytes response from Asterisk... > > Received response: 510 Invalid or unknown command > > > > > > > > _______________________________________________ > > --Bandwidth and Colocation sponsored by Easynews.com -- > > > > Asterisk-Users mailing list > > Asterisk-Users@lists.digium.com > > http://lists.digium.com/mailman/listinfo/asterisk-users > > To UNSUBSCRIBE or update options visit: > > http://lists.digium.com/mailman/listinfo/asterisk-users > > > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > --Bandwidth and Colocation sponsored by Easynews.com -- > > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >
Quoting "Ren? Enskat [Teamware GmbH]" <ren@teamware-gmbh.de>: What I normally do now with agi->verbose is to pass it a variable using print_r($outputvariable, true). thus if I want to output a string "xxxx" or an array of some sort it goes out in the form $output = "xxxx" $agi->verbose(print_r($output, true)) What I suggest now is to suppress screen output as much as you can and see if the 510 errors go away. I also realised after using phpagi 1 before that the variable hashes had changed in phpagi 2. So if you are adapting some code from phpagi 1 check the hashes. Do a print_r on the result variables and see if the hashes are what you expect them to be.> I have the phpagi 2 library too. > So what did you change in details there to mute the vebrose things? > > > > > > -----Urspr?ngliche Nachricht----- > > Von: asterisk-users-bounces@lists.digium.com > > [mailto:asterisk-users-bounces@lists.digium.com] Im Auftrag von Obelix > > Gesendet: Montag, 17. Oktober 2005 11:02 > > An: Asterisk Users Mailing List - Non-Commercial Discussion > > Betreff: Re: [Asterisk-Users] AGI Problem > > > > Quoting "Ren? Enskat [Teamware GmbH]" <ren@teamware-gmbh.de>: > > > > In my experience most AGI problems I had came from other info > > sent to the terminal via verbose commands and other stdout > > output. There is some info on the voip-info wiki about using AGI. > > > > I use the phpagi 2 library, and carefully setting up the > > agi->verbose commmands fixes my 510 problems > > > > > > > > Hmm still have problems with the get variable with PHP i have this > > > error now separated with a script: > > > > > > Sending string GET VARIABLE CALLERIDNUM\n to Asterisk... > > > Wroten bytes to STDOUT: 25 > > > > > > Reading 80 bytes response from Asterisk... > > > Received response: 510 Invalid or unknown command > > > > > > > > > > > > _______________________________________________ > > > --Bandwidth and Colocation sponsored by Easynews.com -- > > > > > > Asterisk-Users mailing list > > > Asterisk-Users@lists.digium.com > > > http://lists.digium.com/mailman/listinfo/asterisk-users > > > To UNSUBSCRIBE or update options visit: > > > http://lists.digium.com/mailman/listinfo/asterisk-users > > > > > > > > > > > > > ---------------------------------------------------------------- > > This message was sent using IMP, the Internet Messaging Program. > > > > _______________________________________________ > > --Bandwidth and Colocation sponsored by Easynews.com -- > > > > Asterisk-Users mailing list > > Asterisk-Users@lists.digium.com > > http://lists.digium.com/mailman/listinfo/asterisk-users > > To UNSUBSCRIBE or update options visit: > > http://lists.digium.com/mailman/listinfo/asterisk-users > > > > > > _______________________________________________ > --Bandwidth and Colocation sponsored by Easynews.com -- > > Asterisk-Users mailing list > Asterisk-Users@lists.digium.com > http://lists.digium.com/mailman/listinfo/asterisk-users > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Hi, I'm running the last CVS asterisk version (I was running an older version before with the same problem) and I've a problem with agi scripts. Commands results are not always correct. I've made a small agi test script that execute ChanIsAvail on an inexistent extension: ---------------------------------------------------- #!/usr/bin/perl $|=1; while(<STDIN>) { chomp; last unless length($_); if (/^agi_(\w+)\:\s+(.*)$/) { $AGI{$1} = $2; } } # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; ---------------------------------------------------- Result is : ---------------------------------------------------- -- Executing DeadAGI("SIP/200-60d2", "b") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/b -- AGI Script Executing Application: (ChanIsAvail) Options: (IAX/24) Dec 2 10:29:37 WARNING[15776]: channel.c:2520 ast_request: No channel type registered for 'IAX' b: 200 result=-1 -- AGI Script Executing Application: (ChanIsAvail) Options: (IAX/24) Dec 2 10:29:37 WARNING[15776]: channel.c:2520 ast_request: No channel type registered for 'IAX' b: 200 result=1 -- AGI Script Executing Application: (ChanIsAvail) Options: (IAX/24) Dec 2 10:29:37 WARNING[15776]: channel.c:2520 ast_request: No channel type registered for 'IAX' b: 510 Invalid or unknown command -- AGI Script b completed, returning 0 ---------------------------------------------------- The first result is ok (-1) but not the second and the third. Why do I get different results for the same command? Thank you, Regards, Cyrille
Hi!> The first result is ok (-1) but not the second and the third. > Why do I get different results for the same command?Hm... u might want to try this: # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; $result = <STDIN>; # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; $result = <STDIN>; # Check print "EXEC ChanIsAvail IAX/24\n"; $result = <STDIN>; print "VERBOSE \"$result\" 0\n"; $result = <STDIN>; Philipp