def sendPoll(IP, pollType="callstate"):
    """
  The handlers Polycom offers are:
  polling/callStateHandler
  polling/deviceHandler
  polling/networkHandler

  """
    global AUTH
    global USER
    global PWD
    count = 0
    log = setLogging(__name__)
    log.debug('%s called from %s with %s' %
              (getFunctionName(), getCallingModuleName(),
               getArguments(inspect.currentframe())))
    payload = "http://" + IP + "/polling/" + pollType + "Handler"
    result = requests.get(payload, auth=AUTH)
    while result.status_code != 200:
        if count > 5:
            sys.exit()
        log.debug('%s returned from sendPoll; regenerating Authorization' %
                  (result.status_code, ))
        AUTH = digest(USER, PWD)
        result = requests.get(payload, auth=AUTH)
        count += 1
    XMLstring = result.text.splitlines()
    log.debug("Result of poll is %s" % (XMLstring, ))
    pattern = re.compile(r".*<(.*)>(.*)<.*")
    state = {}
    for line in XMLstring:
        log.debug("checking %s for XML" % (line))
        m = pattern.match(line)
        if m:
            log.debug("found match in %s" % (line, ))
            log.debug("Adding key-value pair %s:%s" % (m.group(1), m.group(2)))
            state.update({m.group(1): m.group(2)})

    lineState = ""
    while lineState not in ['Active', 'Inactive']:
        try:
            lineState = state["LineState"]
        except:
            log.warn('No headers returned from poll')
    log.debug('Valid poll response to %s at %s' %
              ((getFunctionName(), getArguments(inspect.currentframe()))))
    return state
def sendPoll(IP, pollType="callstate"):
  """
  The handlers Polycom offers are:
  polling/callStateHandler
  polling/deviceHandler
  polling/networkHandler

  """
  global AUTH
  global USER
  global PWD
  count=0
  log=setLogging(__name__)
  log.debug('%s called from %s with %s' %(getFunctionName(), getCallingModuleName(),  getArguments(inspect.currentframe())))
  payload="http://" + IP + "/polling/"+pollType+"Handler"
  result=requests.get(payload, auth=AUTH)
  while result.status_code!=200:
    if count>5:
      sys.exit()
    log.debug('%s returned from sendPoll; regenerating Authorization'%(result.status_code,))
    AUTH=digest(USER, PWD)
    result=requests.get(payload, auth=AUTH)
    count+=1
  XMLstring=result.text.splitlines()
  log.debug("Result of poll is %s" %(XMLstring,))
  pattern=re.compile(r".*<(.*)>(.*)<.*")
  state={}
  for line in XMLstring:
    log.debug("checking %s for XML" %(line))
    m=pattern.match(line)
    if m:
      log.debug("found match in %s" %(line,))
      log.debug("Adding key-value pair %s:%s" %(m.group(1),m.group(2)))
      state.update({m.group(1):m.group(2)})

  lineState=""
  while lineState not in ['Active', 'Inactive']:
    try:
      lineState=state["LineState"]
    except:
      log.warn('No headers returned from poll')
  log.debug('Valid poll response to %s at %s'% ((getFunctionName(), getArguments(inspect.currentframe()))))
  return state 
Esempio n. 3
0
#
#  Beautiful is better than ugly
#  Explicit is better than implicit
#  Simple is better than complex
#  Complex is better than complicated
#  Readability counts
#
###############################################################################
import requests
import json
from requests.auth import HTTPDigestAuth as digest

#Set globals
USER = '******'
PWD = 'Push'
AUTH = digest(USER, PWD)
URL = r"http://10.17.220.218/push"
HEADERS = {"Content-Type": "application/x-com-polycom-spipx"}
PAYLOAD = r"<PolycomIPPhone><Data priority=\"Critical\">tel:\\5552112</Data></PolycomIPPhone>"
DATA = json.dumps(PAYLOAD)


def main():
    #r=requests.post(URL, auth=AUTH, verify=False, data=DATA, headers=HEADERS)
    r = requests.get("http://10.17.220.218/polling/callstateHandler",
                     auth=AUTH)
    print r
    print r.text

    #make a phone call from 5551111 at 10.17.220.217 to 5551112 (10.17.220.218)
from sys import exit

#Requires requests which is not a standard module
try:
  import requests
  from requests.auth import HTTPDigestAuth as digest
except Exception:
  print "This library requires the installation of requests!  /n (debian package: python-requests)"
  exit()


#Set globals
username, password, enable = 'adtran\n', 'adtran\n', 'adtran\n' #Login credentials telnet to Neo and Bulk Callers
USER='******'
PWD='Push'
AUTH=digest(USER, PWD)
URL_A=r"http://"
URL_B=r"/push"
HEADERA="Content-Type: application/x-com-polycom-spipx"
HEADERB="User-Agent: DVT User Agent"
PAYLOAD_A="<PolycomIPPhone><Data priority=\"Critical\">"
PAYLOAD_B="</Data></PolycomIPPhone>"
BC_RESPONSE=re.compile(r".*fxo\s(.*) - 0x(\d+)\s\((.*)\)\s\((.*)\).*\((.*)\)")
PROMPT=""
RESULTS=[]
pType="pType"
BC="BC"
name="name"
IP="IP"
TrunkID="TrunkID"
number="number"