Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import Globals
- from Products.ZenUtils.ZenScriptBase import ZenScriptBase
- from ZODB.transact import transact
- def checkIp(dev):
- print "Checking Ips for %s" % dev.titleOrId()
- for interface in dev.os.interfaces():
- interface.checkRelations(repair=True)
- for ip in interface.ipaddresses():
- try:
- ip.urlLink(ip.getIpAddress())
- except:
- print "Removing ip %s from %s" % ( ip.id,dev.titleOrId())
- try:
- interface.ipaddresses._delObject(ip.id)
- #commit() # don't commit inside the @transact
- except:
- interface.ipaddresses._remove(ip)
- #commit() # don't commit inside the @transact
- def checkRoute(dev):
- print "Checking Routes for %s" % dev.titleOrId()
- for route in dev.os.routes():
- route.checkRelations(repair=True)
- def checkLayer3(dev):
- print "Checking Layer 3 Catalog for %s" % dev.titleOrId()
- cat = dmd.ZenLinkManager._getCatalog(layer=3)
- brains = cat(deviceId=dev.id)
- for brain in brains:
- try:
- unused = brain.getObject()
- except:
- print "Removing bad Catalog object for path %s" % brain.getPath()
- cat.uncatalog_object(brain.getPath())
- def checkLayer2(dev):
- print "Checking Layer 2 Catalog for %s" % dev.titleOrId()
- cat = dmd.ZenLinkManager._getCatalog(layer=2)
- brains = cat(deviceId=dev.id)
- for brain in brains:
- try:
- unused = brain.getObject()
- except:
- print "Removing bad Catalog object for path %s" % brain.getPath()
- cat.uncatalog_object(brain.getPath())
- def checkGlobalCatalog(dev):
- try:
- print "Checking Global Catalog for %s" % dev.titleOrId()
- cat = dmd.global_catalog
- brains = cat(deviceId=dev.id)
- for brain in brains:
- try:
- unused = brain.getObject()
- except:
- print "Removing bad Catalog object for path %s" % brain.getPath()
- cat.uncatalog_object(brain.getPath())
- except:
- print "Skipping Global catalog check, does not exist in dmd."
- def checkDeviceClass(dev):
- print "Checking Device Class linkage for %s" % dev.titleOrId()
- if dev.deviceClass == None:
- dc = dev.getPrimaryParent().getPrimaryParent()
- dev.deviceClass._add(dc)
- # Will commit at the end, and retry up to 5 times if there's a database conflict error.
- @transact
- def processOneDevice(dev):
- print "\n\nChecking %s" % dev.titleOrId()
- dev.checkRelations(repair=True)
- dev.hw.checkRelations(repair=True)
- dev.os.checkRelations(repair=True)
- checkDeviceClass(dev)
- checkIp(dev)
- checkRoute(dev)
- checkGlobalCatalog(dev)
- checkLayer2(dev)
- checkLayer3(dev)
- dev.reindex_all()
- if __name__ == '__main__':
- dmd = ZenScriptBase(connect=True).dmd
- for dev in dmd.Devices.getSubDevicesGen(): # This reads them from the catalog.
- processOneDevice(dev)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement