[asterisk-users] AGI problem using mono (.Net)

Steve Edwards asterisk.org at sedwards.com
Wed Feb 25 17:47:35 CST 2009


On Wed, 25 Feb 2009, Douglas Mortensen wrote:

> I have a software developer creating a .Net / mono program to use as an 
> AGI script. We are having problems getting it to stream files. From what 
> we can tell, it is talking to asterisk correctly when called from the 
> dial plan. Its stderr output goes to the asterisk console. But asterisk 
> doesn't give any indication that it receives the STREAM FILE command. 
> Asterisk simply quickly executes the program and moves to the next step 
> of the dial plan, as though it didn't receive any commands from the 
> program.

Maybe you need a new developer? (Just kidding...)

The "agi debug" command may shed some light on the problem. I'm not a big 
fan of AGIs outputting to STDERR. I like to "pepper" my AGIs with syslog() 
statements to show the program state and variables.

> We know it is running, and outputting its results, because we have 
> called it from within a bash script, and in doing so, I set the script 
> to output stdout to a txt file for testing (like this > 
> /var/log/asterisk/querylog). When we do this, the file does end up with 
> the first line showing STREAM FILE filename.

You can configure Asterisk to log a whole bunch of cruft to syslog with 
the following statement in logger.conf:

         syslog.local0 = debug,dtmf,error,event,info,notice,verbose,warning

I'll apologize in advance if the text below underestimates your AGI 
skills.

The AGI interface (is that redundant?) can be summarized as:

1) Asterisk sends a bunch of cruft (the AGI environment variables) to your 
program's STDIN.

2) Your program sends a request to Asterisk via STDOUT.

3) Asterisk sends a result to your program via STDIN.

4) Your program does something else.

5) go to step 2.

It's very simple, but not very forgiving.

Let's imagine a simple AGI that reads the ANI as a channel variable, 
parses out the area code and sets it as a channel variable named NPA.

Thus, you can simulate the AGI environment with a shell script. For an 
example, imagine the following script named test-my-agi.sh:

# the standard AGI environment variables
         echo "agi_accountcode: "
         echo "agi_callerid: 1234567890"
         echo "agi_calleridname: sedwards"
         echo "agi_callingani2: 0"
         echo "agi_callingpres: 0"
         echo "agi_callingtns: 0"
         echo "agi_callington: 0"
         echo "agi_channel: SIP/201-09456478"
         echo "agi_context: newline"
         echo "agi_dnid: *"
         echo "agi_enhanced: 0.0"
         echo "agi_extension: *"
         echo "agi_language: en"
         echo "agi_priority: 1"
         echo "agi_rdnis: unknown"
         echo "agi_request: block-ani"
         echo "agi_type: SIP"
         echo "agi_uniqueid: 1195070681.28"
         echo ""

# result for AGI command GET VARIABLE ANI
         echo "200 result=1 (5551234567)"

# result for AGI command SET VARIABLE NPA
         echo "200 result=1"

# (end of test-my-agi.sh)

You can test your agi by executing:

 	./test-my-agi.sh | my-agi

Since your AGI requires specific interaction with Asterisk to play the 
file this method will not allow you to fully test it, but it may help 
identify where you are violating the protocol.

This technique can even be used in an actual debugger like gdb so you can 
step through your code line by line.

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



More information about the asterisk-users mailing list