python-ami
python-ami copied to clipboard
No event is being captured
#!/usr/bin/python import os import time
from asterisk.ami import AMIClient from asterisk.ami import EventListener
def event_listener(event,**kwargs): print(event)
client = AMIClient(address='127.0.0.1',port=5038) future = client.login(username='astmanager',secret='Xn75CFbVfjRg71v') if future.response.is_error(): raise Exception(str(future.response))
client.add_event_listener(event_listener) try: while True: time.sleep(10) except (KeyboardInterrupt, SystemExit): client.logoff()
this code is running without error but shows no even on the terminal when I run it
Do you have more info about the astmanager
user in your /etc/asterisk/manager.conf
?
I'm asking to be sure that this user can receive events.
astmanager] ; this must be generated automatically secret = Xn75CFbVfjRg71v deny = 0.0.0.0/0.0.0.0 permit= 127.0.0.1/255.255.255.0 read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate writetimeout = 60000 this is the settings for this user
I have even tried read=all and write = all
Your settings looks right for me Do you know if the login command is completing?
I'm running it:
# ...
def event_notification(source, event):
print(event)
client = AMIClient(**connection)
future = client.login(**login)
if future.response.is_error():
raise Exception(str(future.response))
print(future.response)
client.add_event_listener(event_notification)
# ...
And getting this:
Response: Success
ActionID: 0
Message: Authentication accepted
Event : SuccessfulAuth -> {'Privilege': 'security,all', 'EventTV': '2022-04-18T11:44:12.568+0000', 'Severity': 'Informational', 'Service': 'AMI', 'EventVersion': '1', 'AccountID': 'admin', 'SessionID': '0x7fdeec002b60', 'LocalAddress': 'IPV4/TCP/0.0.0.0/5038', 'RemoteAddress': 'IPV4/TCP/127.0.0.1/39788', 'UsingPassword': '0', 'SessionTV': '2022-04-18T11:44:12.568+0000'}
my output is little different from you i cant see this Event thing.
Same trouble. with previous version no problem to get the event. but now no event caugth. I have a look on code and perform some tests, and I get the event if I suppress the line in AMICLient class, connect function self._socket.settimeout(self._timeout)
with no timeout set (as it is in previous version), events are well caught
Same here
You can workarround this problem by passing the timeout parameter to the initialization of client:
client = asterisk.ami.AMIClient(address='127.0.0.1',port=5038,timeout=None)