<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Find switch ports in script]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have been attempting to use nxshell and a script to iterate through each object in my network and tell me switch port information.</p>
<p dir="auto">However I am stuck at using the ConnectionPoint class and findConnectionPoint.<br />
<a href="https://www.netxms.org/documentation/javadoc/latest/org/netxms/client/topology/class-use/ConnectionPoint.html" rel="nofollow ugc">https://www.netxms.org/documentation/javadoc/latest/org/netxms/client/topology/class-use/ConnectionPoint.html</a></p>
<pre><code>import org.netxms.client

for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
	NXCSession.findConnectionPoint(node.ZONE0, node.getPrimaryIP())
</code></pre>
<p dir="auto">the code errors out with the following TypeError: findConnectionPoint(): self arg can't be coerced to org.netxms.client<br />
.NXCSession</p>
<p dir="auto">Trying to use macAddr or just ObjectId complains that it requires 2-3 arguments rather than just 1.</p>
<p dir="auto">Has anyone else successfully used findConnectionPoint or have any tips to point me in the right direction?</p>
]]></description><link>https://forum.netxms.org/topic/3137/find-switch-ports-in-script</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 16:59:33 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/3137.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 May 2014 13:46:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Find switch ports in script on Tue, 06 May 2014 16:10:54 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Alex, that works <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">for anyone else interested in this, here is the code i used.</p>
<p dir="auto">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...<br />
NAME,IP,MAC,SWITCH,PORT,DIRECTLYCONNECTED</p>
<pre><code>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
		])
</code></pre>
<p dir="auto">Again, thanks for the help!</p>
]]></description><link>https://forum.netxms.org/post/13802</link><guid isPermaLink="true">https://forum.netxms.org/post/13802</guid><dc:creator><![CDATA[greensmith]]></dc:creator><pubDate>Tue, 06 May 2014 16:10:54 GMT</pubDate></item><item><title><![CDATA[Reply to Find switch ports in script on Tue, 06 May 2014 14:11:19 GMT]]></title><description><![CDATA[<p dir="auto">You are trying to call static method — code should be like this:</p>
<pre><code>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
</code></pre>
<p dir="auto">And you don't need to import org.netxms.client, it's done automatically by nxshell.</p>
<pre><code>from org.netxms.client import *
from org.netxms.api.client import *
</code></pre>
]]></description><link>https://forum.netxms.org/post/13798</link><guid isPermaLink="true">https://forum.netxms.org/post/13798</guid><dc:creator><![CDATA[alk]]></dc:creator><pubDate>Tue, 06 May 2014 14:11:19 GMT</pubDate></item></channel></rss>