NetXMS Support Forum

English Support => General Support => Topic started by: m1975Michael on June 11, 2014, 10:49:07 PM

Title: Import List of IP Addresses
Post by: m1975Michael on June 11, 2014, 10:49:07 PM
Hello Everyone,

I am new to NetXMS.  I would like to import a list of IP addresses.  The devices are on different networks and I only want to add that specific device to NetXMS.  We have about 600 networks connected through VPN connections.   Any assistance would be greatly appreciated.  Thank you.
Title: Re: Import List of IP Addresses
Post by: Victor Kirhenshtein on June 12, 2014, 10:44:30 PM
Hi!

Your best bet is to create simply script with nxshell (http://wiki.netxms.org/wiki/Using_nxshell_to_automate_bulk_operations (http://wiki.netxms.org/wiki/Using_nxshell_to_automate_bulk_operations)) to read list of addresses and create node objects. If you are not good at Python - just ask, I'm quite sure that somebody will create such script.

Best regards,
Victor
Title: Re: Import List of IP Addresses
Post by: m1975Michael on June 12, 2014, 11:17:07 PM
Quote from: Victor Kirhenshtein on June 12, 2014, 10:44:30 PM
Hi!

Your best bet is to create simply script with nxshell (http://wiki.netxms.org/wiki/Using_nxshell_to_automate_bulk_operations (http://wiki.netxms.org/wiki/Using_nxshell_to_automate_bulk_operations)) to read list of addresses and create node objects. If you are not good at Python - just ask, I'm quite sure that somebody will create such script.

Best regards,
Victor

Hello Victor thank you for replying.  Actually I know nothing about Python.  Any assistance would be great.
Title: Re: Import List of IP Addresses
Post by: andrey--k on June 13, 2014, 08:20:55 AM
I have ready script for similar purpose.
from org.netxms.client.objects import GenericObject, Node, Template

rootObject = session.findObjectByName("FromFile")
#print rootObject
#print "\n"
if rootObject:
for nodeIP in open("discover.txt").readlines():
test = s.findObjectByName(nodeIP.strip())
if test:
print "Object exists\n"
else:
name = "IP%s" % nodeIP.strip()
newNode = NXCObjectCreationData(objects.GenericObject.OBJECT_NODE, name, rootObject.getObjectId());
newNode.setPrimaryName(nodeIP.strip())
try:
nodeId = session.createObject(newNode)
except:
print "exception create node\n"
pass
else:
if nodeId:
try:
s.pollNode(nodeId,2,None)
except:
print "exception make pool\n"
pass

Create file with ip list, delimited by newline (without whitespaces).
rename it to discover.txt

put all in one folder. (/home/nxuser/nxShell/)

Create folder "FromFile" via nxmc. New objects will be added there.
Run

java -Djava.io.tmpdir=/tmp/ -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar /home/nxuser/nxShell/nxshell-1.2.14.jar nodesRemoveSoftwareScan.py


Script work slowly. For 600 ip it will take 3-5 hours but all nodes will be polled.
If you want to do it faster - comment or delete next lines from script:

if nodeId:
try:
s.pollNode(nodeId,2,None)
except:
print "exception make pool\n"
pass
Title: Re: Import List of IP Addresses
Post by: m1975Michael on June 13, 2014, 04:16:02 PM
Quote from: andrey--k on June 13, 2014, 08:20:55 AM
I have ready script for similar purpose.
from org.netxms.client.objects import GenericObject, Node, Template

rootObject = session.findObjectByName("FromFile")
#print rootObject
#print "\n"
if rootObject:
for nodeIP in open("discover.txt").readlines():
test = s.findObjectByName(nodeIP.strip())
if test:
print "Object exists\n"
else:
name = "IP%s" % nodeIP.strip()
newNode = NXCObjectCreationData(objects.GenericObject.OBJECT_NODE, name, rootObject.getObjectId());
newNode.setPrimaryName(nodeIP.strip())
try:
nodeId = session.createObject(newNode)
except:
print "exception create node\n"
pass
else:
if nodeId:
try:
s.pollNode(nodeId,2,None)
except:
print "exception make pool\n"
pass

Create file with ip list, delimited by newline (without whitespaces).
rename it to discover.txt

put all in one folder. (/home/nxuser/nxShell/)

Create folder "FromFile" via nxmc. New objects will be added there.
Run

java -Djava.io.tmpdir=/tmp/ -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar /home/nxuser/nxShell/nxshell-1.2.14.jar nodesRemoveSoftwareScan.py


Script work slowly. For 600 ip it will take 3-5 hours but all nodes will be polled.
If you want to do it faster - comment or delete next lines from script:

if nodeId:
try:
s.pollNode(nodeId,2,None)
except:
print "exception make pool\n"
pass


Thank you for the script.  I am running the windows version of NetXMS anything I need to change in the script?  How do you run the script?
Title: Re: Import List of IP Addresses
Post by: andrey--k on June 13, 2014, 04:22:24 PM
Sorry, but am running linux-only versions.
Title: Re: Import List of IP Addresses
Post by: Victor Kirhenshtein on June 13, 2014, 05:28:08 PM
Script should be run in a same manner on Windows, just omit -Djava.io.tmpdir=/tmp/ and use \ instaed of / in path separators.

Best regards,
Victor
Title: Re: Import List of IP Addresses
Post by: m1975Michael on June 13, 2014, 11:59:34 PM
Quote from: andrey--k on June 13, 2014, 04:22:24 PM
Sorry, but am running linux-only versions.

Hello, did some of the script get cut off.  Do you need closing statements for IF and For?
Title: Re: Import List of IP Addresses
Post by: andrey--k on June 14, 2014, 11:19:26 AM
See indentation example on wiki:
Quote
http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation
Title: Re: Import List of IP Addresses
Post by: m1975Michael on June 14, 2014, 02:04:57 PM
Quote from: andrey--k on June 14, 2014, 11:19:26 AM
See indentation example on wiki:
Quote
http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Indentation

Thank you Andrey I understand now.  I was able to get your script to work.  It is much appreciated.