Difference between revisions of "Using nxshell to automate bulk operations"

Jump to navigation Jump to search
Line 66: Line 66:
     nodeId = session.createObject(cd)
     nodeId = session.createObject(cd)
     print '"%s" created, id=%d' % (name, nodeId)
     print '"%s" created, id=%d' % (name, nodeId)
</pre>
== Change Object comments ==
<pre>for name in open("nodes.txt").readlines():
    node = session.findObjectByName(name.strip())
    if node:
        comments = "New Comment"
        existingComments = node.getComments() # will return null if there are no comments
        if existingComments:
            comments += "\n" + existingComments
        session.updateObjectComments(node.getObjectId(), comments)
</pre>
== Manage / Unmanage interfaces based on the name ==
(works for any Object).
<pre>from org.netxms.client.objects import GenericObject, Node, Interface
for name in open("nodes.txt").readlines():
    node = session.findObjectByName(name.strip())
    if node:
        for interface in node.getAllChilds(GenericObject.OBJECT_INTERFACE): # 3 == interface
            name = interface.getObjectName()
            if name.startswith('lo'):
                session.setObjectManaged(interface.getObjectId(), True)
            else:
                session.setObjectManaged(interface.getObjectId(), False)
</pre>
== Disable SNMP polling for node ==
<pre>from org.netxms.client.objects import Node
for name in open("nodes.txt").readlines():
    node = session.findObjectByName(name.strip())
    if node:
        md = NXCObjectModificationData(node.getObjectId())
        newFlags = node.getFlags() | Node.NF_DISABLE_SNMP
        md.setObjectFlags(newFlags)
        session.modifyObject(md)
</pre>
</pre>

Navigation menu