ZenDMD Tip - Rename Devices

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

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