Find switch ports in script
-
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.htmlimport 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
.NXCSessionTrying 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?
-
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(), pointAnd 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 * -
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,DIRECTLYCONNECTEDimport 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!
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