ZenDMD Tip - Set Titles via Reverse Lookup (PTR record)

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

The following code will iterate through all devices and perform a reverse lookup of the proper hostname. If the device's title attribute doesn't match the hostname returned by DNS it'll update it.
Set makeChanges = True if the script does what you expect.

debugIt = True
makeChanges = False
for d in dmd.Devices.getSubDevices():
    hostname = socket.gethostbyaddr(d.manageIp)
    if d.titleOrId() != hostname[0] or debugIt == True:
       print "Device IP: " + str(d.manageIp)
       print "Device current ID: " + str(d.titleOrId())
       print "Device new ID: " + str(hostname[0])
       if makeChanges == True:
          print 'ID to: ' + str(hostname[0])
          print 'ID to: Unchanged'
       print '-'*80