Reputation: 39
I am trying to run a python script by calling it in the asterisk AGI Interface. I have had this running in a test environment but cannot seem to get this to run on Ubuntu 18.04. I can get the AGI script to run when I start asterisk with "sudo asterisk -vvgc"
I have some of the script below to see if there may be a problem with logging and that is what is killing the script as it prints in the console view.
Here is the AGI debug while asterisk runs in the background accessing the console via "sudo asterisk -vvvvvvr"
AGI Debugging Enabled
== Using SIP RTP CoS mark 5
> 0x7f9288015b20 -- Strict RTP learning after remote address set to:
192.168.21.93:58654
-- Executing [101@default:1] NoOp("SIP/1400-00000001", "Test User") in new
stack
-- Executing [101@default:2] AGI("SIP/1400-00000001", "siptapeth.agi") in new
stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/siptapeth.agi
<SIP/1400-00000001>AGI Tx >> agi_request: siptapeth.agi
<SIP/1400-00000001>AGI Tx >> agi_channel: SIP/1400-00000001
<SIP/1400-00000001>AGI Tx >> agi_language: en
<SIP/1400-00000001>AGI Tx >> agi_type: SIP
<SIP/1400-00000001>AGI Tx >> agi_uniqueid: 1531757391.1
<SIP/1400-00000001>AGI Tx >> agi_version: 14.7.7
<SIP/1400-00000001>AGI Tx >> agi_callerid: 1400
<SIP/1400-00000001>AGI Tx >> agi_calleridname: Test User
<SIP/1400-00000001>AGI Tx >> agi_callingpres: 0
<SIP/1400-00000001>AGI Tx >> agi_callingani2: 0
<SIP/1400-00000001>AGI Tx >> agi_callington: 0
<SIP/1400-00000001>AGI Tx >> agi_callingtns: 0
<SIP/1400-00000001>AGI Tx >> agi_dnid: 101
<SIP/1400-00000001>AGI Tx >> agi_rdnis: unknown
<SIP/1400-00000001>AGI Tx >> agi_context: default
<SIP/1400-00000001>AGI Tx >> agi_extension: 101
<SIP/1400-00000001>AGI Tx >> agi_priority: 2
<SIP/1400-00000001>AGI Tx >> agi_enhanced: 0.0
<SIP/1400-00000001>AGI Tx >> agi_accountcode:
<SIP/1400-00000001>AGI Tx >> agi_threadid: 140270109501184
<SIP/1400-00000001>AGI Tx >>
-- <SIP/1400-00000001>AGI Script siptapeth.agi completed, returning 0
-- Auto fallthrough, channel 'SIP/1400-00000001' status is 'UNKNOWN'
Here is the output when I run asterisk in console mode "sudo asterisk -vvgc"
`*CLI> core set verbose 10
Console verbose was 2 and is now 10.
*CLI> agi set debug on
AGI Debugging Enabled
*CLI> agi set debug 10
Usage: agi set debug [on|off]
Enables/disables dumping of AGI transactions for
debugging purposes.
*CLI> == Using SIP RTP CoS mark 5
> 0x7ff3ac0091e0 -- Strict RTP learning after remote address set to:
192.168.21.93:59514
-- Executing [101@default:1] NoOp("SIP/1400-00000000", "Test User") in new
stack
-- Executing [101@default:2] AGI("SIP/1400-00000000", "siptapeth.agi") in new
stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/siptapeth.agi
<SIP/1400-00000000>AGI Tx >> agi_request: siptapeth.agi
<SIP/1400-00000000>AGI Tx >> agi_channel: SIP/1400-00000000
<SIP/1400-00000000>AGI Tx >> agi_language: en
<SIP/1400-00000000>AGI Tx >> agi_type: SIP
<SIP/1400-00000000>AGI Tx >> agi_uniqueid: 1531758059.0
<SIP/1400-00000000>AGI Tx >> agi_version: 14.7.7
<SIP/1400-00000000>AGI Tx >> agi_callerid: 1400
<SIP/1400-00000000>AGI Tx >> agi_calleridname: Test User
<SIP/1400-00000000>AGI Tx >> agi_callingpres: 0
<SIP/1400-00000000>AGI Tx >> agi_callingani2: 0
<SIP/1400-00000000>AGI Tx >> agi_callington: 0
<SIP/1400-00000000>AGI Tx >> agi_callingtns: 0
<SIP/1400-00000000>AGI Tx >> agi_dnid: 101
<SIP/1400-00000000>AGI Tx >> agi_rdnis: unknown
<SIP/1400-00000000>AGI Tx >> agi_context: default
<SIP/1400-00000000>AGI Tx >> agi_extension: 101
<SIP/1400-00000000>AGI Tx >> agi_priority: 2
<SIP/1400-00000000>AGI Tx >> agi_enhanced: 0.0
<SIP/1400-00000000>AGI Tx >> agi_accountcode:
<SIP/1400-00000000>AGI Tx >> agi_threadid: 140687325234944
<SIP/1400-00000000>AGI Tx >>
ARGS: ['/var/lib/asterisk/agi-bin/siptapeth.agi']
ENV LINE: agi_request: siptapeth.agi
ENV LINE: agi_channel: SIP/1400-00000000
ENV LINE: agi_language: en
ENV LINE: agi_type: SIP
ENV LINE: agi_uniqueid: 1531758059.0
ENV LINE: agi_version: 14.7.7
ENV LINE: agi_callerid: 1400
ENV LINE: agi_calleridname: Test User
ENV LINE: agi_callingpres: 0
ENV LINE: agi_callingani2: 0
ENV LINE: agi_callington: 0
ENV LINE: agi_callingtns: 0
ENV LINE: agi_dnid: 101
ENV LINE: agi_rdnis: unknown
ENV LINE: agi_context: default
ENV LINE: agi_extension: 101
ENV LINE: agi_priority: 2
ENV LINE: agi_enhanced: 0.0
ENV LINE: agi_accountcode:
ENV LINE: agi_threadid: 140687325234944
ENV LINE:
class AGI: self.env = {'agi_accountcode': '',
'agi_callerid': '1400',
'agi_calleridname': 'Test User',
'agi_callingani2': '0',
'agi_callingpres': '0',
'agi_callingtns': '0',
'agi_callington': '0',
'agi_channel': 'SIP/1400-00000000',
'agi_context': 'default',
'agi_dnid': '101',
'agi_enhanced': '0.0',
'agi_extension': '101',
'agi_language': 'en',
'agi_priority': '2',
'agi_rdnis': 'unknown',
'agi_request': 'siptapeth.agi',
'agi_threadid': '140687325234944',
'agi_type': 'SIP',
'agi_uniqueid': '1531758059.0',
'agi_version': '14.7.7'}
INFO:axi:---Pin:101 - Message:Test User - checksum:410
INFO:axi:b'211 Message sent.<CR><ACK><CR>'
INFO:axi:---Page Accepted - checksum:410
-- <SIP/1400-00000000>AGI Script siptapeth.agi completed, returning 0
-- Auto fallthrough, channel 'SIP/1400-00000000' status is 'UNKNOWN'`
Snippet of siptapeth.agi some of it was removed.
#!/usr/bin/python3
import serial
import re
from time import sleep
import logging
import logging.handlers
from configparser import ConfigParser
import sys
import asterisk
import asterisk.agi
from asterisk.agi import *
import socket
import os
import sys
config = ConfigParser()
config.read('/var/www/html/config.ini')
LOG_LEVEL = logging.info('LOGGING', 'level')
# Initialize logging
LOGGER = logging.getLogger('axi')
LOGGER.setLevel(logging.INFO)
formatter = logging.Formatter('|%(asctime)s|%(levelname)-8s|%(name)s|% (message)s')
log_file = logging.handlers.TimedRotatingFileHandler('/var/log/axi/input.csv', when='midnight', backupCount=7)
log_file.setLevel(logging.INFO)
log_file.setFormatter(formatter)
LOGGER.addHandler(log_file)
# Only print to console if at DEBUG level
if LOG_LEVEL == 'DEBUG':
log_console = logging.StreamHandler()
log_console.setLevel(logging.INFO)
log_console.formatter(formatter)
LOGGER.addHandler(log_console)
BAUD = config.get('USB_Settings', 'baudrate')
PTY = config.get('USB_Settings', 'parity')
STPB = int(config.get('USB_Settings', 'stopbits'))
BTSZ = int(config.get('USB_Settings', 'bytesize'))
HOST = config.get('Ethernet_Paging_System', 'IP')
PORT = config.get('Ethernet_Paging_System', 'Port')
agi = AGI()
pin = agi.env['agi_extension']
msg = agi.env['agi_calleridname']
#***SOME CODE REMOVED FOR SECURITY REASONS***
#Socket setup
s = None
for res in socket.getaddrinfo(HOST, PORT, socket.AF_INET, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except OSError as msg:
s = None
continue
try:
s.connect(sa)
except OSError as msg:
s.close()
s = None
continue
break
if s is None:
LOGGER.info('---Could not open socket')
sys.exit(1)
#***SOME CODE REMOVED FOR SECURITY REASONS***
Upvotes: 1
Views: 2089
Reputation: 3
You can try to change the own for you agi-script for asterisk user. Look at 'chmod' and 'chown' commands.
Upvotes: 0
Reputation: 15259
Usually you have check that all packages and config files availible for asterisk user or other user you run asterisk.
Upvotes: 0
Reputation: 39
Looks like this was a path issue. I installed pyst2 as root as well and now it works.
Upvotes: 0