Asterisk AGI 仅在控制台模式下运行
Asterisk AGI runs in console mode only
我正在尝试 运行 一个 python 脚本,方法是在星号 AGI 接口中调用它。我在测试环境中有此 运行ning,但似乎无法在 Ubuntu 18.04 上将其设置为 运行。
当我用 "sudo asterisk -vvgc"
开始星号时,我可以将 AGI 脚本设置为 运行
我有下面的一些脚本,看看日志记录是否有问题,这就是脚本在控制台视图中打印时终止的原因。
这是 AGI 调试,而星号 运行s 在后台通过 "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***
看起来这是一个路径问题。我也以 root 身份安装了 pyst2,现在它可以工作了。
通常您会检查所有包和配置文件是否可供 asterisk 用户或您 运行 asterisk 的其他用户使用。
您可以尝试为asterisk 用户更改自己的agi-script。查看 'chmod' 和 'chown' 命令。
我正在尝试 运行 一个 python 脚本,方法是在星号 AGI 接口中调用它。我在测试环境中有此 运行ning,但似乎无法在 Ubuntu 18.04 上将其设置为 运行。 当我用 "sudo asterisk -vvgc"
开始星号时,我可以将 AGI 脚本设置为 运行我有下面的一些脚本,看看日志记录是否有问题,这就是脚本在控制台视图中打印时终止的原因。
这是 AGI 调试,而星号 运行s 在后台通过 "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***
看起来这是一个路径问题。我也以 root 身份安装了 pyst2,现在它可以工作了。
通常您会检查所有包和配置文件是否可供 asterisk 用户或您 运行 asterisk 的其他用户使用。
您可以尝试为asterisk 用户更改自己的agi-script。查看 'chmod' 和 'chown' 命令。