Nice to hear that this is not hard to implement =) where can I add this feature request?
Regards,
Christoph
Regards,
Christoph
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
from org.netxms.client.objects import GenericObject, Node, Interface, AbstractObject
# START CONFIG
###############################################################################
rootID = 108 #objects.GenericObject.SERVICEROOT # Infrastructure Services Node
##############################################################################
# END CONFIG
rootNode = s.findObjectById(rootID) # the root node object
print 'Changing items from node %s' % ( rootNode.getObjectName() )
def getSubItems(parent, depth):
for node in parent.getChildsAsArray():
nodeClass = node.getObjectClass()
nodeName = node.getObjectName()
if nodeClass == AbstractObject.OBJECT_CONTAINER:
#print 'Checking subnode...'
getSubItems(node, depth + 1)
else:
for interface in node.getAllChilds(GenericObject.OBJECT_INTERFACE): # 3 == interface
name = interface.getObjectName()
if name.startswith('unknown'):
data = NXCObjectModificationData(interface.getObjectId())
#data.setExpectedState(2) # 2 := ignore interface state
newFlags = interface.getFlags() | Interface.IF_EXCLUDE_FROM_TOPOLOGY # set exclude flag
data.setObjectFlags(newFlags)
session.modifyObject(data)
print 'Changed interface of %s' % (nodeName)
#session.applyTemplate(4754, node.getObjectId()) # add node to new template
#print 'Added node to new polling template'
# main
getSubItems(rootNode, 1)
print 'Done changing interfaces!'
from org.netxms.client.objects import GenericObject, Node, Interface, AbstractObject
import sys
import pickle
import codecs
# START CONFIG
###############################################################################
printTree = True
exportFilename = "exported_nodes.nxe"
rootID = objects.GenericObject.SERVICEROOT # Infrastructure Services Node
##############################################################################
# END CONFIG
rootNode = s.findObjectById(rootID) # the root node object
exportHandle = codecs.open(exportFilename, 'w', 'utf-8')
print 'Exporting items from node %s' % ( rootNode.getObjectName() )
def getSubItems(parent, depth):
for node in parent.getChildsAsArray():
name = node.getObjectName()
nodeId = node.getObjectId()
nodeClass = node.getObjectClass()
#print 'Found object: %s (%d) - class: %d' % (name, nodeId, nodeClass)
if nodeClass == AbstractObject.OBJECT_CONTAINER:
#print 'Checking subnode...'
if printTree == True:
print str(nodeClass) * (depth + 2) + ";" + name
exportHandle.write(str(nodeClass) * (depth) + ";" + name + "\n")
getSubItems(node, depth + 1)
else:
if printTree == True:
print str(nodeClass) * (depth) + ";" + name + ";" + node.getPrimaryIP().getHostAddress()
loc = node.getGeolocation()
ip = node.getPrimaryIP().getHostAddress()
attrs = node.getCustomAttributes()
comment = node.getComments()
hassnmp = node.hasSnmpAgent()
hasnx = node.hasAgent()
# generate custom attribute string
attrstr = ''
for key in attrs: # in python 2.x it is iteritems()
if attrstr != '':
attrstr = attrstr + ':#:'
attrstr = attrstr + key + '=-=' + attrs.get(key)
exportHandle.write( str(nodeClass) * (depth) + ";" + name + ";" + ip + ";" + \
loc.getLatitudeAsString() + ";" + loc.getLongitudeAsString() + ";" + attrstr + ";" + \
str(hassnmp) + ";" + str(hasnx) + ";" + comment + "\n" )
#print 'Found device: %s' % (name)
# main
getSubItems(rootNode, 1)
print 'Done! (Exported file: %s)' % ( exportFilename )
Quote
java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-M4.jar export_nodes.py
from org.netxms.client.objects import GenericObject, Node, Interface, AbstractObject
import sys
import java
import codecs
# START CONFIG
###############################################################################
printTree = True
importFilename = "exported_nodes.nxe"
rootID = objects.GenericObject.SERVICEROOT # Infrastructure Services Node
##############################################################################
# END CONFIG
rootNode = s.findObjectById(rootID) # the root node object
print 'Importing items from node %s' % ( importFilename )
parentId = rootID
parentTree = [rootID]
with codecs.open(importFilename, 'r', 'utf-8') as f:
for line in f:
arr = line.split(';')
# first element specifies type and depth
depth = len(arr[0])
nodetype = int(arr[0][0])
print 'found item: type = %d, depth = %d' % (nodetype, depth)
# all fields mapped to variable names
name = arr[1].strip()
if nodetype == AbstractObject.OBJECT_NODE:
ip = arr[2]
ipaddress = java.net.InetAddress.getByName(ip)
ipnetmask = java.net.InetAddress.getByName("255.255.255.0")
lat = arr[3]
lng = arr[4]
attrs = arr[5]
hassnmp = bool(arr[6])
hasnx = bool(arr[7])
comment = arr[8].strip()
flags = 0
if hasnx == False:
flags |= NXCObjectCreationData.CF_DISABLE_NXCP
if hassnmp == False:
flags |= NXCObjectCreationData.CF_DISABLE_SNMP
if nodetype == AbstractObject.OBJECT_CONTAINER:
# create a new container and set it as current root
print 'Creating Folder: %s in parent: %d' % (name, parentId)
cd = NXCObjectCreationData(objects.GenericObject.OBJECT_CONTAINER, name, parentTree[depth-1]);
folderId = session.createObject(cd) # createObject return ID of newly created object
if (len(parentTree)-1) > depth:
parentTree[depth] = folderId
else:
parentTree.insert(depth, folderId)
else:
# create a new node in the current container
print 'Creating Node: %s - %s' % (name, ip)
cd = NXCObjectCreationData(objects.GenericObject.OBJECT_NODE, name, parentTree[depth-1]);
cd.setCreationFlags(flags);
cd.setComments(comment);
#cd.setIpAddress(ipaddress);
#cd.setIpNetMask(ipnetmask);
cd.setPrimaryName(ip) # Create node with IP address
nodeId = session.createObject(cd)
#print 'Line: %s' % (line)
print 'Done!'
Quote
java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-M4.jar import_nodes.py