I would like to show Asterisk SIP peers in my Python application.
I can see such list executing:
[pbx:~] # asterisk -rx "sip show peers"
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
212 (Unspecified) D No No 0 UNKNOWN
213 (Unspecified) D No No 0 UNKNOWN
217/217 169.0.5.17 D No No 5060 OK (29 ms)
....
In Python I use pyst 0.8 library:
import asterisk.manager
...
manager = asterisk.manager.Manager()
try:
manager.connect(host, port)
manager.login(usr, passwd)
r = manager.sippeers()
print('------- r ----')
pp.pprint(r)
print('-----------')
# ...
Then I pretty print some fields of the response. But all I get is:
------- r ----
Success
-----------
------ response -----
[ u'Response: Success\r\n',
u'ActionID: pbx-25332-00000001\r\n',
u'EventList: start\r\n',
u'Message: Peer status list will follow\r\n']
-----------
------ data -----
u''
-----------
------ headers -----
{ u'ActionID': u'pbx-25332-00000001',
u'EventList': u'start',
u'Message': u'Peer status list will follow',
u'Response': u'Success'}
-----------
----- multiheaders ------
{ u'ActionID': [u'pbx-25332-00000001'],
u'EventList': [u'start'],
u'Message': [u'Peer status list will follow'],
u'Response': [u'Success']}
-----------
How can I obtain list of SIP peers using pyst?
Asterisk version:
asterisk -r -vvvvv
Asterisk 11.17.1, Copyright (C) 1999 - 2013 Digium, Inc. and others. ...
sippeers()is just a shortcut for sending theSIPpeerscommand directly. It doesn't do any listening for resulting events. According to documentation you getPeerlistandPeerlistCompleteevents after sending the command, so you will need to register a listener for the events. I haven't worked with pyst, so I'm not familiar with the structure of the events, but hopefully this helps.