我试图通过在星号AGI界面中调用python脚本来运行它。我已经在测试环境中运行了它,但是似乎无法在Ubuntu 18.04上运行它。 当我使用“ sudo asterisk -vvgc”启动星号时,我可以运行AGI脚本
我下面有一些脚本,以查看日志记录是否存在问题,这就是杀死脚本的原因,因为该脚本在控制台视图中打印。
这是AGI调试,而星号通过“ 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'
这是我在控制台模式“ 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'`
siptapeth.agi的片段已被删除。
#!/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***
答案 0 :(得分:0)
看起来这是路径问题。我也以根用户身份安装了pyst2,现在可以正常工作了。
答案 1 :(得分:0)
通常,您已经检查了星号用户或其他运行星号的用户是否可以使用所有软件包和配置文件。
答案 2 :(得分:0)
您可以尝试为星号用户更改自己的agi脚本。查看“ chmod”和“ chown”命令。