Difference between revisions of "ZenDMD Tip - Rename Devices"

From Zenoss Wiki
Jump to: navigation, search
(Added Device Title matching)
 
Line 1: Line 1:
The following is a zendmd script to rename devices to what is set as the SNMP system name.
+
The following are zendmd scripts to rename Device ID's in various ways.
  
It could be easily modified to set it in other ways.
+
= Device Title =
 +
<syntaxhighlight lang="python">
 +
from xmlrpclib import ServerProxy, ProtocolError
 +
baseUrl = 'http://admin:YourPassword@localhost:8080'
 +
for d in dmd.Devices.getSubDevices():
 +
    if d.titleOrId():
 +
        try:
 +
            oldname = d.id
 +
            newname = d.titleOrId()
 +
            if newname != oldname:
 +
                devpath = d.getPrimaryUrlPath()
 +
                print "Renaming %s to %s" % (oldname, newname)
 +
                url = '/'.join([baseUrl, devpath])
 +
                serv = ServerProxy( url )
 +
                serv.renameDevice(newname)
 +
                sync()
 +
                commit()
 +
                sync()
 +
        except:
 +
            pass
 +
</syntaxhighlight>
  
 +
= SNMP System Name =
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
from xmlrpclib import ServerProxy, ProtocolError
 
from xmlrpclib import ServerProxy, ProtocolError

Latest revision as of 21:27, 28 February 2014

The following are zendmd scripts to rename Device ID's in various ways.

Device Title

from xmlrpclib import ServerProxy, ProtocolError
baseUrl = 'http://admin:YourPassword@localhost:8080'
for d in dmd.Devices.getSubDevices():
    if d.titleOrId():
        try:
            oldname = d.id
            newname = d.titleOrId()
            if newname != oldname:
                devpath = d.getPrimaryUrlPath()
                print "Renaming %s to %s" % (oldname, newname)
                url = '/'.join([baseUrl, devpath])
                serv = ServerProxy( url )
                serv.renameDevice(newname)
                sync()
                commit()
                sync()
        except:
            pass

SNMP System Name

from xmlrpclib import ServerProxy, ProtocolError
baseUrl = 'http://admin:YourPassword@localhost:8080'
for d in dmd.Devices.getSubDevices():
    if d.snmpSysName:
        try:
            oldname = d.id
            newname = d.snmpSysName
            if newname != oldname:
                devpath = d.getPrimaryUrlPath()
                print "Renaming %s to %s" % (oldname, newname)
                url = '/'.join([baseUrl, devpath])
                serv = ServerProxy( url )
                serv.renameDevice(newname)
                sync()
                commit()
                sync()
        except:
            pass