TypeError: 'str' object is not callable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charlie of Bolton
    New Member
    • Mar 2007
    • 32

    #16
    Hi Birtonc,

    disregard...I did a stupid mystake,
    was c:/tmp/myprimarylogs.x ls not only myprimarylogs.x ls : )

    Comment

    • Charlie of Bolton
      New Member
      • Mar 2007
      • 32

      #17
      Hi Bartonc,

      The script you provided give the ping to primary IP and than the Secondary,
      but what about, if I want to Ping the primary but ping the Secondary ONLY if packet lost of the Primary if greater or equal.

      The def fil() part that I put, Is filtering OK.

      Brgds/Carl

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #18
        Originally posted by Charlie of Bolton
        Hi Bartonc,

        The script you provided give the ping to primary IP and than the Secondary,
        but what about, if I want to Ping the primary but ping the Secondary ONLY if packet lost of the Primary if greater or equal.

        The def fil() part that I put, Is filtering OK.

        Brgds/Carl
        I modified your fil() function somewhat. I am using re to get the ip address and percentage loss. This will keep trying IPs until the list runs out or pinging is successful.[code=Python]# imports, def validIP()
        def fil(data):
        patt = re.compile(r'\( (\d+)% loss\)')
        patt1 = re.compile(r'(\ d+.\d+.\d+.\d)' )

        for line in data.split('\n' ):

        if line.startswith ("Ping statistics for"):
        ip = patt1.search(li ne).group(1)

        if patt.search(lin e):
        loss_num = int(patt.search (line).group(1) )

        if loss_num >= 2 :
        s = open('myprimary logs.txt', 'a+')
        s.write("%s '%s'\n" % (loss_num, ip))
        s.close()
        # if loss >= 2, return False - then secondary IPs are pinged
        print 'loss_num is >= 2 ', loss_num
        return False
        else:
        print 'loss_num is < 2,', loss_num
        return True

        def ping(*fnames):
        g = open(fnames[0], 'w')
        for fn in fnames[1:]:
        f=open(fn, 'r')
        ipList = [line.strip() for line in f.readlines()]
        f.close()
        resList = []
        for ipAdd in ipList:
        pingaling =os.popen("ping %s" %(ipAdd),"r")
        data = pingaling.read( )
        resList.append( data)
        # if loss > 2, ping secondary IPs
        proceed = fil(data)
        if proceed:
        break
        g.write('/n'.join(resList ))
        if proceed:
        break
        g.close()

        def get_IPs(fnP, fnS):
        while True:
        ipAddP = raw_input("# Enter Primary IP: ")
        if validIP(ipAddP) :
        f = open(fnP, 'w')
        f.write(ipAddP. strip() + "\n")
        f.close()
        break
        else:
        print "Invalid IP."
        ipList = []
        while True:
        while True:
        ipAddS = raw_input("# Enter Secondary IP: ")
        if validIP(ipAddS) :
        ipList.append(i pAddS.strip())
        break
        else:
        print "Invalid IP"
        s = raw_input("# Enter another IP? Y/N: " )
        if s.upper() == "N":
        f = open(fnS, 'w')
        f.write('\n'.jo in(ipList))
        f.close()
        break

        fnP = 'primaryip.txt'
        fnS = 'secip.txt'
        fnW = 'workfile.txt'

        get_IPs(fnP, fnS)
        ping(fnW, fnP, fnS)[/code]

        Comment

        • Charlie of Bolton
          New Member
          • Mar 2007
          • 32

          #19
          Hi bvdet and Bartonc,

          This work perfectly, you are real PROsss...
          [EDIT: I've created a new thread for the additional question here]
          It's here.
          Last edited by bartonc; Oct 25 '07, 11:01 PM.

          Comment

          Working...