<?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[nxShell and jython[Solved]]]></title><description><![CDATA[<p dir="auto">Hi to all!</p>
<p dir="auto">I'm sorry if this is the wrong section, but I didn't know where I had to open this topic!</p>
<p dir="auto">I'm starting using nxShell just how it is suggested in the wiki. I'm trying to create a script which will let me set a custom attribute (End User Info) on some interfaces in some map's nodes. My problem is the setting of the modification data. I understood that I should use a Map imported from java.util, but I'm new in python programming so I'm having problem in setting the Constructor of the Map in the right way. Once I run the script I get a "java.lang.ArrayIndexOutOfBoundsException: -3". Here is my code:</p>
<pre><code># coding: utf-8
import csv
import time
from java.util import Map
from java.lang import String
class XXX:
	def YYY(self):
		listaNodi = []
		listaNodi = session.getAllObjects()
		for nodo in listaNodi:
			IPlista = nodo.getPrimaryIP()
			#print "IPlista: "+str(IPlista)
			for infoIP in open("RIGHT/PATH/IP.txt").readlines():
				#print "infoIP: "+infoIP
				#time.sleep(0.2)
				if str(IPlista) == infoIP:
					for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
						ID = interface.getObjectId()
						IDinterfaccia=str(ID)
						#print "IDinterfaccia: "+IDinterfaccia
						for interfaccia in open("RIGHT/PATH/INTERFACCIA.TXT").readlines():
							#print "interfaccia: "+str(interfaccia)
							if IDinterfaccia == interfaccia:
								print "Sono in IDinterfaccia == interfaccia"
								info = open("RIGHT/PATH/EndUserInfo.txt").readlines()
								#print "info: "+str(info)
								modificatore = NXCObjectModificationData(ID)
								#print "modificatore: "+str(modificatore)
								Map&lt;String,String&gt; modifica = """new""" Map() # I SUPPOSE THE MISTAKE IS HERE!!!
								modifica.put("End user Info",info)
								#print "modifica: "+str(modifica)
								modificatore = setCustomAttributes(modifica)
g = XXX()
g.YYY()
</code></pre>
<p dir="auto">Could anyone help me to understand where is my mistake?<br />
Thanks in advance!</p>
]]></description><link>https://forum.netxms.org/topic/2405/nxshell-and-jython-solved</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 11:41:39 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/2405.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 May 2013 11:15:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to nxShell and jython[Solved] on Fri, 14 Jun 2013 09:01:30 GMT]]></title><description><![CDATA[<p dir="auto">After <a href="https://www.netxms.org/forum/general-support/nxshell-setprimaryname-doesn%27t-work/msg10536/#msg10536" rel="nofollow ugc">this</a> suggestion by Victor for a similar task, I solved the problem also in this script. The working code is:</p>
<pre><code>#coding: utf-8

import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String

class XXX4:
	def YYY(self):
		 listaNodi = []
		 listaNodi = session.getAllObjects()
          	 datiFile = open("PATH/Lettura.csv").readlines()
 		 for nodo in listaNodi:
 			IPnodo = str(nodo.getPrimaryIP())
			for riga in datiFile:
 				print "___________starts for on riga_____________\n"
 				print "riga: "+riga
 				for parola in riga.split():
 					print "parola: "+parola
 					if IPnodo ==parola:
 						print "Verified IPnodo = parola"
 						time.sleep(10)
 						for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
 							print "starts interface for "
 							interfaceName = interface.getObjectName()
 							ID = interface.getObjectId()
 							print "interfaceName: "+interfaceName
 							for parola1 in riga.split():
 								print "parola1: "+parola1
 								if interfaceName == parola1:
 									print "Verified interfaceName=parola1"
 									for parola2 in riga.split():
 										EndUserInfo = parola2
 									print "EndUserInfo after for: "+EndUserInfo
									modificatore = NXCObjectModificationData(ID)
 									modifica = HashMap() # CHANGE 2
 									modifica.put("End user Info",EndUserInfo)
									modificatore.setCustomAttributes(modifica)
                                                                        session.modifyObject(modificatore)
                                                                        time.sleep(10)

G = XXX4()
G.YYY()
</code></pre>
]]></description><link>https://forum.netxms.org/post/10543</link><guid isPermaLink="true">https://forum.netxms.org/post/10543</guid><dc:creator><![CDATA[BlackMamba]]></dc:creator><pubDate>Fri, 14 Jun 2013 09:01:30 GMT</pubDate></item><item><title><![CDATA[Reply to nxShell and jython[Solved] on Mon, 03 Jun 2013 10:03:50 GMT]]></title><description><![CDATA[<p dir="auto">Thank you Alex, but I'm still unable to set the custom attributes on the interface. I updated a little my script, because I have to read from a single file written in a certain way, and then I put your suggestions in it. The reading of the file works in the proper way and I don't get any error running the script, but the custom attributes are empty anyway. Here is my code:</p>
<pre><code>#coding: utf-8

import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String

class XXX4:
	def YYY(self):
		 listaNodi = []
		 listaNodi = session.getAllObjects()
          	 datiFile = open("PATH/Lettura.csv").readlines()
 		 for nodo in listaNodi:
 			IPnodo = str(nodo.getPrimaryIP())
			for riga in datiFile:
 				print "___________starts for on riga_____________\n"
 				print "riga: "+riga
 				for parola in riga.split():
 					print "parola: "+parola
 					if IPnodo ==parola:
 						print "Verified IPnodo = parola"
 						time.sleep(10)
 						for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
 							print "starts interface for "
 							interfaceName = interface.getObjectName()
 							ID = interface.getObjectId()
 							print "interfaceName: "+interfaceName
 							for parola1 in riga.split():
 								print "parola1: "+parola1
 								if interfaceName == parola1:
 									print "Verified interfaceName=parola1"
 									for parola2 in riga.split():
 										EndUserInfo = parola2
 									print "EndUserInfo after for: "+EndUserInfo
									modificatore = NXCObjectModificationData(ID)
 									modifica = HashMap() # CHANGE 2
 									modifica.put("End user Info",EndUserInfo)
									modificatore.setCustomAttributes(modifica)
									time.sleep(10)

G = XXX4()
G.YYY()
</code></pre>
<p dir="auto">Any suggestion?</p>
<p dir="auto">EDIT: I found out something interesting. I modified the script and my last lines of it now are:</p>
<pre><code>                                                               for parola2 in riga.split():
										EndUserInfo = str(parola2)
									print "EndUserInfo dopo cilclo for: "+EndUserInfo
									modificatore = NXCObjectModificationData(ID)
									"""modifica = HashMap() # CHANGE 2
									modifica.put("End User Info",EndUserInfo)
									print "modifica: "+str(modifica)
									modificatore.setCustomAttributes(modifica)"""
									customAttributes = modificatore.getCustomAttributes()
									print "customAttributes: "+str(customAttributes)
									#customAttributes.put("End User Info",EndUserInfo)
									#modificatore.setCustomAttributes(customAttributes)
</code></pre>
<p dir="auto">My thought was that, instead of creating a new HasMap, I could get the existing one, supposed to be empty, and use the put metod on it. But the command	<code>print "customAttributes: "+str(customAttributes)</code> returns "none", which is the same result I get using the solution you suggested. Also, if I try to run <code>customAttributes.put("End User Info",EndUserInfo)</code> on the terminal I get:</p>
<p dir="auto">customAttributes.put("End User Info",EndUserInfo)<br />
AttributeError: 'NoneType' object has no attribute 'put'</p>
<p dir="auto">It seems like modificatore.getCustomAttributes() is not a Map&lt;String,String&gt; object.<br />
Help!</p>
]]></description><link>https://forum.netxms.org/post/10421</link><guid isPermaLink="true">https://forum.netxms.org/post/10421</guid><dc:creator><![CDATA[BlackMamba]]></dc:creator><pubDate>Mon, 03 Jun 2013 10:03:50 GMT</pubDate></item><item><title><![CDATA[Reply to nxShell and jython[Solved] on Sat, 01 Jun 2013 16:37:40 GMT]]></title><description><![CDATA[<p dir="auto">Try to change it like this:</p>
<pre><code># coding: utf-8
import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String
class XXX:
	def YYY(self):
		listaNodi = []
		listaNodi = session.getAllObjects()
		for nodo in listaNodi:
			IPlista = nodo.getPrimaryIP()
			#print "IPlista: "+str(IPlista)
			for infoIP in open("RIGHT/PATH/IP.txt").readlines():
				#print "infoIP: "+infoIP
				#time.sleep(0.2)
				if str(IPlista) == infoIP:
					for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
						ID = interface.getObjectId()
						IDinterfaccia=str(ID)
						#print "IDinterfaccia: "+IDinterfaccia
						for interfaccia in open("RIGHT/PATH/INTERFACCIA.TXT").readlines():
							#print "interfaccia: "+str(interfaccia)
							if IDinterfaccia == interfaccia:
								print "Sono in IDinterfaccia == interfaccia"
								info = open("RIGHT/PATH/EndUserInfo.txt").readlines()
								#print "info: "+str(info)
								modificatore = NXCObjectModificationData(ID)
								#print "modificatore: "+str(modificatore)
								modifica = HashMap() # CHANGE 2
								modifica.put("End user Info",info)
								#print "modifica: "+str(modifica)
								modificatore = setCustomAttributes(modifica)
g = XXX()
g.YYY()
</code></pre>
]]></description><link>https://forum.netxms.org/post/10420</link><guid isPermaLink="true">https://forum.netxms.org/post/10420</guid><dc:creator><![CDATA[alk]]></dc:creator><pubDate>Sat, 01 Jun 2013 16:37:40 GMT</pubDate></item></channel></rss>