def infoVoIP(): activeLogs('/tmp','astdemo_defs','err') myConnect=connectAMI() s = myConnect.socket s.send('Action: CoreSettings\n\n') time.sleep (0.1) data = s.recv(65536) mgrdict=ManagerDict(data) returnmsg = "VoIP Informations" returnmsg += "\r" returnmsg += "Asterisk Version %s " % mgrdict.getitem('AsteriskVersion') s.send('Action: CoreStatus\n\n') time.sleep (0.1) data = s.recv(65536) mgrdict=ManagerDict(data) returnmsg += "Started: " + mgrdict.getitem('CoreStartupDate').replace('\r','') + ' - ' + mgrdict.getitem('CoreStartupTime') returnmsg += "Last reload: " + mgrdict.getitem('CoreReloadDate').replace('\r','') + ' - ' + mgrdict.getitem('CoreReloadTime') s.close() return returnmsg
def sipPeer(sip): activeLogs('/tmp','astdemo_defs','err') myConnect=connectAMI() s = myConnect.socket s.send('Action: SIPshowpeer\nPeer: %s\n\n' % sip) time.sleep (0.1) data = s.recv(65536) mgrdict=ManagerDict(data) returnmsg = "Extension %s informations: " % sip returnmsg += "\r" if data.find("Peer %s ot found" % sip) > 0: returnmsg += "Extension %s not registered.\n" % sip else: returnmsg += "CallerID: " + mgrdict.getitem('Callerid') returnmsg += "IP: " + mgrdict.getitem('Address-IP') returnmsg += "Codecs: " + mgrdict.getitem('Codecs') returnmsg += "Status: " + mgrdict.getitem('Status') returnmsg += "User Agent: " + mgrdict.getitem('SIP-Useragent') s.close() return returnmsg
def getQueueMembersNumber(queue): activeLogs('/tmp','astdemo_classes','err') members=0 myConnect=connectAMI() s = myConnect.socket s.send('Action: QueueStatus\nQueue: %s\n\n' % queue) time.sleep (0.1) data = s.recv(65536) mgrdict=ManagerDict(data) lines = data.split('\n') for item in lines: data=item.split(":",1) try: title=data[0] except: title="" if title == "Name": members = members + 1 s.close return (members)
def iaxPeers(): myConnect=connectAMI() s = myConnect.socket s.send('Action: IAXpeers\n\n') time.sleep (0.1) data = s.recv(65535) mgrdictev=ManagerDictEvents(data,'PeerEntry') if not mgrdictev.isvalid: returnmsg = "IAX peers not found." return returnmsg else: returnmsg = "IAX peers Informations - %s peers found.\r" % str(mgrdictev.items) for event in mgrdictev.events: returnmsg+="Peer: " + event['ObjectName'] returnmsg+="Type: " + event['ChanObjectType'] returnmsg+="IP: " + event['IPaddress'] returnmsg+="Port: " + event['IPport'] returnmsg+="Trunk: " + event['Trunk'] returnmsg+="Status: " + event['Status'] returnmsg += '\r' s.close() return returnmsg
def call(number,extension,callerid,context,priority): myConnect=connectAMI() s = myConnect.socket s.send('Action: Originate\nChannel: SIP/' + number + '\nExten: ' + extension + '\nCallerID: ' + callerid + '\nContext: ' + context + '\nPriority: ' + priority + '\nAsync: true\n\n') time.sleep (0.1) s.close()
def call(number,extension,callerid,context,priority): myConnect=connectAMI() s = myConnect.socket #s.send('Action: Originate\nChannel: SIP/%s\nExten: %s\nCallerID: %s\nContext: %s\nPriority: %s\n\n') % (number,extension,callerid,context,priority) s.send('Action: Originate\nChannel: SIP/' + number + '\nExten: ' + extension + '\nCallerID: ' + callerid + '\nContext: ' + context + '\nPriority: ' + priority + '\nAsync: true\n\n') % (number,extension,callerid,context,priority) time.sleep (0.1) s.close()
def iaxPeerStatus(iax): myConnect=connectAMI() s = myConnect.socket s.send('Action: IAXpeerlist\n\n') time.sleep (0.1) data = s.recv(65535) mgrdictev=ManagerDictEvents(data,'PeerEntry') returnmsg="" if not mgrdictev.isvalid: returnmsg = "UNAVAILABLE" return returnmsg else: found=False for event in mgrdictev.events: if not found: if (event['ObjectName'].replace("\\","").replace("\r","").replace("\n","")).strip() == iax.strip(): found=True returnmsg=event['Status'].split("(")[0].replace("\\","").replace("\r","").replace("\n","") break if not found: returnmsg = "UNAVAILABLE" s.close() return returnmsg
def sipPeerStatus(sip): activeLogs('/tmp','astdemo_defs','err') myConnect=connectAMI() s = myConnect.socket s.send('Action: SIPshowpeer\nPeer: %s\n\n' % sip) time.sleep (0.1) data = s.recv(65536) mgrdict=ManagerDict(data) if data.find("Peer %s not found" % sip) > 0: returnmsg = "UNAVAILABLE" else: returnmsg = mgrdict.getitem('Status').split("(")[0].replace("\\","").replace("\r","").replace("\n","") s.close() return returnmsg