0
votes

Below is my python agi script. I'm trying to pass a value from dialplan to agi script and trying to print the value through the script. Everything is working fine but the value is not passing to the script. Please let me know if anything went wrong in it.

#!/usr/bin/python

from asterisk.agi import *

agi = AGI()

agi.verbose("python agi started")

phone_exten = agi.get_variable('PHONE_EXTEN')
agi.verbose("phone number",phone_exten)

agi.set_variable('EXT_CALLERID', '1')

Dailplan code:

[TEST]
exten => _X.,1,Goto(s,1)
exten => s,1,set(PHONE_EXTEN=0904)
exten => s,2,AGI(first.py,${PHONE_EXTEN})
exten => s,3,NoOp(${EXT_CALLERID})
exten => s,4,Hangup()

Output

Connected to Asterisk 14.6.0 currently running on ip-172-31-18-90 (pid = 2539)
Core debug is still 10.
[Feb 20 12:54:39]   == Using SIP RTP CoS mark 5
[Feb 20 12:54:39]     -- Executing [0904@TEST:1] Goto("SIP/0904-00000004", "s,1") in new stack
[Feb 20 12:54:39]     -- Goto (TEST,s,1)
[Feb 20 12:54:39]     -- Executing [s@TEST:1] Set("SIP/0904-00000004", "PHONE_EXTEN=0904") in new stack
[Feb 20 12:54:39]     -- Executing [s@TEST:2] AGI("SIP/0904-00000004", "first.py,0904") in new stack
[Feb 20 12:54:39]     -- Launched AGI Script /var/lib/asterisk/agi-bin/first.py
[Feb 20 12:54:39]  first.py,0904: python agi started
[Feb 20 12:54:39]     -- <SIP/0904-00000004>AGI Script first.py completed, returning 0
[Feb 20 12:54:39]     -- Executing [s@TEST:3] NoOp("SIP/0904-00000004", "1") in new stack
[Feb 20 12:54:39]     -- Executing [s@TEST:4] Hangup("SIP/0904-00000004", "") in new stack
[Feb 20 12:54:39]   == Spawn extension (TEST, s, 4) exited non-zero on 'SIP/0904-00000004'
1
From what you have shared so far, it looks like the python script only logs that it started and does not reach the agi.verbose("phone number", phone_exten) line. This could be because the call to agi.get_variable caused the script to terminate early (variable was not defined maybe?).Brandon Haugen

1 Answers

0
votes

This question is seeking debug help, so it's off topic. But okay.

How to debug AGI script correctly:

  1. Stop asterisk service

  2. Start asterisk service in console using asterisk -vvvgc. This one is required to see error pipe of script.

  3. in asterisk console enable agi debug

    agi set debug on
    
  4. run script