Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Find switch ports in script

Find switch ports in script

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 8.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G
    G
    greensmith
    wrote on last edited by
    #1

    Hello,

    I have been attempting to use nxshell and a script to iterate through each object in my network and tell me switch port information.

    However I am stuck at using the ConnectionPoint class and findConnectionPoint.
    https://www.netxms.org/documentation/javadoc/latest/org/netxms/client/topology/class-use/ConnectionPoint.html

    import org.netxms.client
    
    for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
    	NXCSession.findConnectionPoint(node.ZONE0, node.getPrimaryIP())
    

    the code errors out with the following TypeError: findConnectionPoint(): self arg can't be coerced to org.netxms.client
    .NXCSession

    Trying to use macAddr or just ObjectId complains that it requires 2-3 arguments rather than just 1.

    Has anyone else successfully used findConnectionPoint or have any tips to point me in the right direction?

    1 Reply Last reply
    0
    • A
      A
      Alex Kirhenshtein
      wrote on last edited by
      #2

      You are trying to call static method — code should be like this:

      for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
      	point = s.findConnectionPoint(node.ZONE0, node.getPrimaryIP())
      	print node.getObjectName(), point
      

      And you don't need to import org.netxms.client, it's done automatically by nxshell.

      from org.netxms.client import *
      from org.netxms.api.client import *
      
      1 Reply Last reply
      0
      • G
        G
        greensmith
        wrote on last edited by
        #3

        Thanks Alex, that works 🙂

        for anyone else interested in this, here is the code i used.

        it checks the ip address of each node - if it matches regex (i am only interested in nodes from one subnet) it prints the data in csv format...
        NAME,IP,MAC,SWITCH,PORT,DIRECTLYCONNECTED

        import re
        import csv
        import sys
        
        w = csv.writer(sys.stdout, dialect='excel')
        w.writerow(['NAME', 'IP', 'MAC', 'SWT', 'PORT', 'DIR'])
        
        for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
        	#set node information
        	#convert ip to string and remove slash
        	vnodeIp = str(node.getPrimaryIP())
        	vnodeIp = vnodeIp.replace("/","")
        	vnodeName = node.getObjectName()
        	vnodeMac = node.getPrimaryMAC()
        
        	#regex to match anything in .2. subnet
        	subnetRegex = re.match("^\d{1,3}\.\d{1,3}\.2\.\d{1,3}$",vnodeIp)
        
        	#if in this subnet run...
        	if subnetRegex:
        
        		#get connectionpoint
        		point = s.findConnectionPoint(node.ZONE0, node.getPrimaryIP())
        
        		#handle connectionpoint data exceptions
        		try:
        			vswitchID = s.getObjectName(point.nodeId)
        		except:
        			vswitchID = "null"
        		try:
        			vportID = s.getObjectName(point.interfaceId)
        		except:
        			vportID = "null"
        		try:
        			vdirCon = point.directlyConnected
        		except:
        			vdirCon = "False"
        
        		#print data
        		w.writerow([
        			vnodeName,
        			vnodeIp,
        			vnodeMac,
        			vswitchID,
        			vportID,
        			vdirCon
        		])
        

        Again, thanks for the help!

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups