Advertisement
Guest User

Untitled

a guest
Oct 14th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import Globals
  3. from Products.ZenUtils.ZenScriptBase import ZenScriptBase
  4. from ZODB.transact import transact
  5.  
  6. def checkIp(dev):
  7. print "Checking Ips for %s" % dev.titleOrId()
  8. for interface in dev.os.interfaces():
  9. interface.checkRelations(repair=True)
  10. for ip in interface.ipaddresses():
  11. try:
  12. ip.urlLink(ip.getIpAddress())
  13. except:
  14. print "Removing ip %s from %s" % ( ip.id,dev.titleOrId())
  15. try:
  16. interface.ipaddresses._delObject(ip.id)
  17. #commit() # don't commit inside the @transact
  18. except:
  19. interface.ipaddresses._remove(ip)
  20. #commit() # don't commit inside the @transact
  21.  
  22.  
  23. def checkRoute(dev):
  24. print "Checking Routes for %s" % dev.titleOrId()
  25. for route in dev.os.routes():
  26. route.checkRelations(repair=True)
  27.  
  28.  
  29. def checkLayer3(dev):
  30. print "Checking Layer 3 Catalog for %s" % dev.titleOrId()
  31. cat = dmd.ZenLinkManager._getCatalog(layer=3)
  32. brains = cat(deviceId=dev.id)
  33. for brain in brains:
  34. try:
  35. unused = brain.getObject()
  36. except:
  37. print "Removing bad Catalog object for path %s" % brain.getPath()
  38. cat.uncatalog_object(brain.getPath())
  39.  
  40.  
  41. def checkLayer2(dev):
  42. print "Checking Layer 2 Catalog for %s" % dev.titleOrId()
  43. cat = dmd.ZenLinkManager._getCatalog(layer=2)
  44. brains = cat(deviceId=dev.id)
  45. for brain in brains:
  46. try:
  47. unused = brain.getObject()
  48. except:
  49. print "Removing bad Catalog object for path %s" % brain.getPath()
  50. cat.uncatalog_object(brain.getPath())
  51.  
  52.  
  53. def checkGlobalCatalog(dev):
  54. try:
  55. print "Checking Global Catalog for %s" % dev.titleOrId()
  56. cat = dmd.global_catalog
  57. brains = cat(deviceId=dev.id)
  58. for brain in brains:
  59. try:
  60. unused = brain.getObject()
  61. except:
  62. print "Removing bad Catalog object for path %s" % brain.getPath()
  63. cat.uncatalog_object(brain.getPath())
  64. except:
  65. print "Skipping Global catalog check, does not exist in dmd."
  66.  
  67. def checkDeviceClass(dev):
  68. print "Checking Device Class linkage for %s" % dev.titleOrId()
  69. if dev.deviceClass == None:
  70. dc = dev.getPrimaryParent().getPrimaryParent()
  71. dev.deviceClass._add(dc)
  72.  
  73. # Will commit at the end, and retry up to 5 times if there's a database conflict error.
  74. @transact
  75. def processOneDevice(dev):
  76. print "\n\nChecking %s" % dev.titleOrId()
  77. dev.checkRelations(repair=True)
  78. dev.hw.checkRelations(repair=True)
  79. dev.os.checkRelations(repair=True)
  80. checkDeviceClass(dev)
  81. checkIp(dev)
  82. checkRoute(dev)
  83. checkGlobalCatalog(dev)
  84. checkLayer2(dev)
  85. checkLayer3(dev)
  86. dev.reindex_all()
  87.  
  88. if __name__ == '__main__':
  89. dmd = ZenScriptBase(connect=True).dmd
  90.  
  91. for dev in dmd.Devices.getSubDevicesGen(): # This reads them from the catalog.
  92. processOneDevice(dev)
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement