python-ami icon indicating copy to clipboard operation
python-ami copied to clipboard

No event is being captured

Open nouman-ux opened this issue 2 years ago • 8 comments

#!/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

nouman-ux avatar Apr 12 '22 08:04 nouman-ux

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.

ettoreleandrotognoli avatar Apr 14 '22 18:04 ettoreleandrotognoli

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

nouman-ux avatar Apr 15 '22 03:04 nouman-ux

I have even tried read=all and write = all

nouman-ux avatar Apr 15 '22 03:04 nouman-ux

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'}

ettoreleandrotognoli avatar Apr 18 '22 11:04 ettoreleandrotognoli

image

my output is little different from you i cant see this Event thing.

nouman-ux avatar Apr 19 '22 03:04 nouman-ux

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

Mmtt-DDE avatar Aug 31 '22 14:08 Mmtt-DDE

Same here

mmaridev avatar Jan 04 '23 21:01 mmaridev

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)

palmtop avatar Feb 23 '23 18:02 palmtop