Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Move container to new server

Move container to new server

Scheduled Pinned Locked Moved Support
3 Posts 3 Posters 14.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C
    C
    curruscanis
    wrote on last edited by
    #1

    Is there a fast way to move or export a "Container" from the Infrastructure Services tree on one server to a new server?

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      Hi!

      No, there are no such standard functionality. However, if you are familiar with Python programming language, you can create simple tool using nxshell that will export node configuration from container into file and then import it into another server. More information about nxshell can be found here: https://wiki.netxms.org/wiki/Using_nxshell_to_automate_bulk_operations.

      Best regards,
      Victor

      1 Reply Last reply
      0
      • T
        T
        technikcst
        wrote on last edited by
        #3

        Hi,

        I want to post a small example script for importing/exporting. Maybe someone can improve this script - it is kinda usefull if you want to migrate to a new server without copying the old database.

        EXPORT

        export_nodes.py:

        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 )
        

        Export nodes with this command:

        java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-M4.jar export_nodes.py

        IMPORT

        import_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!'
        

        Import nodes with this command:

        java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-M4.jar import_nodes.py

        Especially the import script might need some improvement to allow importing of custom attributes and so on.

        I hope this is helpful!

        1 Reply Last reply
        0

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups