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. nxShell: setPrimaryName doesn't work [Solved]

nxShell: setPrimaryName doesn't work [Solved]

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 11.7k 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.
  • B
    B
    BlackMamba
    wrote on last edited by
    #1

    Hi to all!

    I'm trying to create a script for nxShell which will allow me to set the primary name of some hosts in my network. Both primary name to set and hostnames to be modified are stored in two files. I created this script:

    # coding: utf-8
    
    class SetPrimaryName:
    	def out(self):
    		i=0
    		PrimaryNames = open("/PATH/TO/FILE/PRIMARYNAME").readlines()
    		for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY").readlines():
    			nodo = session.findObjectByName(nome.strip())
    			primaryName = PrimaryNames[i]
    			if nodo:
    				nodeID =nodo.getObjectId()
    				print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
    				modificatore = NXCObjectModificationData(nodeID)
    				print
    				modificatore.setPrimaryName(primaryName)
    				i+=1
    spn = SetPrimaryName()
    spn.out()
    

    Everything works fine but nothing happens in NetXMS and the primary name of the selected hosts stays the same. Am I doing something wrong? My doubt is focused on "modificatore", because it's the second time I try to modify data already stored in NetXMS (does anyone remember my still unresolved problem posted here? ) but I'm unable to accomplish this goal.
    Thanks in advance for the support!

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

      Hi!

      It seems that you don't do real modification. Creating NXCObjectModificationData is not enough - after populating it you should call session.modifyObject with your NXCObjectModificationData object as argument. Should be something like

      session.modifyObject(modificatore)

      in your case.

      Best regards,
      Victor

      1 Reply Last reply
      0
      • B
        B
        BlackMamba
        wrote on last edited by
        #3

        Thank you Victor! With one answer you solved two problems! Just in case anyone has the same problem I'll post the working code as example of both script:

        # coding: utf-8
        
        class SetPrimaryName:
        	def out(self):
        		i=0
        		PrimaryNames = open("PATH/TO/FILE/PRIMARYNAME.TXT").readlines()
        		for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY.TXT").readlines():
        			nodo = session.findObjectByName(nome.strip())
        			primaryName = PrimaryNames[i]
        			if nodo:
        				nodeID =nodo.getObjectId()
        				print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
        				modificatore = NXCObjectModificationData(nodeID)
        				modificatore.setPrimaryName(primaryName)
        				session.modifyObject(modificatore)
        				i+=1
        spn = SetPrimaryName()
        spn.out()
        

        If you want to set custom attributes in already existing nodes, or if you want another example, you can find the script here.

        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