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

From Zenoss Wiki
Revision as of 19:44, 17 July 2012 by 50.56.228.65 (Talk)$7

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The following code will iterate through all devices and perform a reverse lookup of the proper hostname. If the devices title attribute doesn't match it's set t the hostname returned by DNS.

   for d in dmd.Devices.getSubDevices():
       hostname = socket.gethostbyaddr(d.manageIp)
       if d.titleOrId() != hostname[0]:
           print "Device IP: " + str(d.manageIp)
           print "Device current ID: " + str(d.titleOrId())
           print "Device new ID: " + str(hostname[0])
           d.title = str(hostname[0])


Don't forget to commit().

Best, --Shane (Hackman238)