Difference between revisions of "ZenDMD Tip - Fix Broken Muiltigraph Collections"

From Zenoss Wiki
Jump to: navigation, search
m
 
Line 1: Line 1:
Once in a blue moon Collections in MjultiGraph reports can stop working as expected. Here's some quick DMD code to rebuild them.
+
Occasionally collections in MultiGraph reports can stop working as expected. Here's some zendmd code to rebuild them...
  
 
<syntaxhighlight lang=python>
 
<syntaxhighlight lang=python>

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()