ZenDMD Tip - Rename Devices

From Zenoss Wiki
Revision as of 23:09, 9 October 2012 by Rmatte (Talk | contribs)$7

Jump to: navigation, search

The following is a zendmd script to rename devices to what is set as the SNMP system name.

It could be easily modified to set it in other ways.

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