Difference between revisions of "ZenDMD Tip - Set Titles via Reverse Lookup (PTR record)"

From Zenoss Wiki
Jump to: navigation, search
Line 1: Line 1:
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. Set makeChanges = True if the script does what you expect.
+
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 it'll update it. Set makeChanges = True if the script does what you expect.
  
 
   debugIt = True
 
   debugIt = True

Revision as of 16:16, 20 July 2012

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 it'll update it. Set makeChanges = True if the script does what you expect.

  debugIt = True
  makeChanges = False
  for d in dmd.Devices.getSubDevices():
      sync()
      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:
            d.title = str(hostname[0])
            print 'ID to: ' + str(hostname[0])
            commit()
         else:
            print 'ID to: Unchanged'
         print '-'*80


Best, --Shane (Hackman238)