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