2012-11-12 14:20:05 +04:00
|
|
|
"""
|
|
|
|
Example to get list of active channels
|
|
|
|
"""
|
|
|
|
import asterisk.manager
|
|
|
|
import sys
|
|
|
|
|
|
|
|
manager = asterisk.manager.Manager()
|
|
|
|
|
|
|
|
try:
|
|
|
|
# connect to the manager
|
|
|
|
try:
|
|
|
|
manager.connect('localhost')
|
|
|
|
manager.login('user', 'secret')
|
|
|
|
|
|
|
|
# get a status report
|
|
|
|
response = manager.status()
|
2014-10-07 22:49:54 +04:00
|
|
|
print(response)
|
2012-11-12 14:20:05 +04:00
|
|
|
|
|
|
|
response = manager.command('core show channels concise')
|
2014-10-07 22:49:54 +04:00
|
|
|
print(response.data)
|
2012-11-12 14:20:05 +04:00
|
|
|
|
|
|
|
manager.logoff()
|
2014-10-07 22:49:54 +04:00
|
|
|
except asterisk.manager.ManagerSocketException as e:
|
|
|
|
print "Error connecting to the manager: %s" % e.strerror
|
2012-11-12 14:20:05 +04:00
|
|
|
sys.exit(1)
|
2014-10-07 22:49:54 +04:00
|
|
|
except asterisk.manager.ManagerAuthException as e:
|
|
|
|
print "Error logging in to the manager: %s" % e.strerror
|
2012-11-12 14:20:05 +04:00
|
|
|
sys.exit(1)
|
2014-10-07 22:49:54 +04:00
|
|
|
except asterisk.manager.ManagerException as e:
|
|
|
|
print "Error: %s" % e.strerror
|
2012-11-12 14:20:05 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
# remember to clean up
|
|
|
|
manager.close()
|
|
|
|
|