ZenDMD Tip - Zet manageIp via Host Lookup (A record)

From Zenoss Wiki
Revision as of 16:15, 20 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 lookup of the IP. If the devices manageIp attribute doesn't match it's A record it will be updated. Set makeChanges = True if the script does what you expect.

  debugIt = True
  makeChanges = False
  for d in dmd.Devices.getSubDevices():
      sync()
      ipAddr = socket.gethostbyname(d.titleOrId())
      if d.manageIp != ipAddr or debugIt == True:
         print 'Device ID: ' + str(d.titleOrId())
         print 'Device current IP: ' + str(d.manageIp)
         print 'Device new ID: ' + str(ipAddr)
         if makeChanges == True:
            d.setManageIp(ipAddr)
            print 'IP to: ' + str(ipAddr)
            commit()
         else:
            print 'IP to: Unchanged'
         print '-'*80


Best, --Shane (Hackman238)