ZenDMD Tip - Fix Broken Muiltigraph Collections

From Zenoss Wiki
Revision as of 19:36, 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

Once in a blue moon Collections in MjultiGraph reports can stop working as expected. Here's some quick DMD code to rebuild them.

   from Acquisition import aq_base
   from Products.ZenRelations.ToManyContRelationship import ToManyContRelationship
   reportclass = dmd.Reports._getOb('Multi-Graph Reports')
   for organizer in reportclass.getSubOrganizers():
       for report in organizer.reports():
           try:
               rptcolls = report.collections
           except AttributeError:
               continue
           for coll in rptcolls():
               rel = coll.items
               if isinstance(rel, ToManyContRelationship):
                   obs = []
                   for ob in rel():
                       obs.append(aq_base(ob))
                       remote_rel = ob.collection
                       remote_rel._remove(coll)
                       rel._remove(ob)
                   coll._delObject('items')
                   coll.buildRelations()
                   newrel = coll.collection_items.primaryAq()
                   for ob in obs:
                       newrel._setObject(ob.getId(), ob)
                       ob = newrel._getOb(ob.getId())
                       print ob.__primary_parent__
                       assert ob.__primary_parent__ == newrel
                       assert ob.collection() == coll
                       assert ob in newrel()

Don't forget to commit().

Best, --Shane (Hackman238)