Difference between revisions of "ZenDMD Tip - Fix Broken Muiltigraph Collections"
From Zenoss Wiki
|Line 1:||Line 1:|
in reports can stop working as expected. Here's some code to rebuild them.
Latest revision as of 16:17, 30 September 2014
Occasionally collections in MultiGraph reports can stop working as expected. Here's some zendmd 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() commit()