James Newman
2013-03-04 15:51:28 UTC
James Newman [http://community.zenoss.org/people/JimForTheWin] created the discussion
"Fully create Multi-Graph"
To view the discussion, visit: http://community.zenoss.org/message/72266#72266
--------------------------------------------------------------
So this has been kicking my butt for the last two weeks.
I want to programatically create a multigraph report. I am at the point where I can add datasources and collections, but I need to figure out how to add items to the collections and then Groups to the report.
If anyone has a working example of all of this, that would be great, if not, what I'm working on right now is the following:
(Assume all variables and lists are properly defined elsewhere)
# Function to add Collections to the multi-graph report
def addCollection(location, type, report):
   collectionName = str(location.split('/')[1] + " " + type)
if collectionName not in str(rpt.getCollections()):
       report.manage_addCollection(collectionName)
   addCollectionItem(location, collectionName, type)
# Function to add Collection Items to Collections within the multi-graph report  Â
def addCollectionItem(location, colName, type):
try:
for dev in dmd.Devices.Server.Linux.BLAH.Clustered.type.getSubDevices_recursive():
if dev.getLocationName in location:
               colName.manage_addCollectionItem(dev)
   except:
for dev in dmd.Devices.Server.Linux.BLAH.NonClustered.type.getSubDevices_recursive():
if dev.getLocationName in location:
               colName.manage_addCollectionItem(dev)
ro = dmd.Reports.getOrganizer('/Multi-Graph Reports/')
# Loop over all the things!
for profile in profiles:
   # Create a shortened customer name
   customer = '-'.join(profile.split('-')[0:2])
   # Create a report named after the customer short name. If one already exists, we try and continue anyway.  Â
   ro = dmd.Reports.getOrganizer('/Multi-Graph Reports/')
try:
       rpt = ro._getOb(str(customer))
   except:
       rpt = ro.manage_addMultiGraphReport(str(customer))
for loc in listLocations:
if options == "smtp":
           addCollection(loc, "SMTP", rpt)
elif "eps" in options:
           addCollection(loc, "EPS", rpt)
       addCollection(loc, "TM1", rpt)
So This creates the report, creates the collection, and then _doesn't_ add the CollectionItem.
I've found a couple of places in the Zenoss source that use manage_addCollectionItem(), but I can't seem to get the usage correct for my example:
from /opt/zenoss/ZenModel/CollectionItem.py
def manage_addCollectionItem(context, id, deviceId, compPath, sequence,
                                                           REQUEST = None):
from /opt/zenoss/ZenModel/Collection.py
def manage_addCollectionItem(self, itemType,
           deviceIds=(), componentPaths=(), deviceClasses=(), systems=(),
           groups=(), locations=(), recurse=False, REQUEST=None):
Anyone help me out? And then if possible, also provide an example for adding a Graph Group?
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/72266#72266]
Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
"Fully create Multi-Graph"
To view the discussion, visit: http://community.zenoss.org/message/72266#72266
--------------------------------------------------------------
So this has been kicking my butt for the last two weeks.
I want to programatically create a multigraph report. I am at the point where I can add datasources and collections, but I need to figure out how to add items to the collections and then Groups to the report.
If anyone has a working example of all of this, that would be great, if not, what I'm working on right now is the following:
(Assume all variables and lists are properly defined elsewhere)
# Function to add Collections to the multi-graph report
def addCollection(location, type, report):
   collectionName = str(location.split('/')[1] + " " + type)
if collectionName not in str(rpt.getCollections()):
       report.manage_addCollection(collectionName)
   addCollectionItem(location, collectionName, type)
# Function to add Collection Items to Collections within the multi-graph report  Â
def addCollectionItem(location, colName, type):
try:
for dev in dmd.Devices.Server.Linux.BLAH.Clustered.type.getSubDevices_recursive():
if dev.getLocationName in location:
               colName.manage_addCollectionItem(dev)
   except:
for dev in dmd.Devices.Server.Linux.BLAH.NonClustered.type.getSubDevices_recursive():
if dev.getLocationName in location:
               colName.manage_addCollectionItem(dev)
ro = dmd.Reports.getOrganizer('/Multi-Graph Reports/')
# Loop over all the things!
for profile in profiles:
   # Create a shortened customer name
   customer = '-'.join(profile.split('-')[0:2])
   # Create a report named after the customer short name. If one already exists, we try and continue anyway.  Â
   ro = dmd.Reports.getOrganizer('/Multi-Graph Reports/')
try:
       rpt = ro._getOb(str(customer))
   except:
       rpt = ro.manage_addMultiGraphReport(str(customer))
for loc in listLocations:
if options == "smtp":
           addCollection(loc, "SMTP", rpt)
elif "eps" in options:
           addCollection(loc, "EPS", rpt)
       addCollection(loc, "TM1", rpt)
So This creates the report, creates the collection, and then _doesn't_ add the CollectionItem.
I've found a couple of places in the Zenoss source that use manage_addCollectionItem(), but I can't seem to get the usage correct for my example:
from /opt/zenoss/ZenModel/CollectionItem.py
def manage_addCollectionItem(context, id, deviceId, compPath, sequence,
                                                           REQUEST = None):
from /opt/zenoss/ZenModel/Collection.py
def manage_addCollectionItem(self, itemType,
           deviceIds=(), componentPaths=(), deviceClasses=(), systems=(),
           groups=(), locations=(), recurse=False, REQUEST=None):
Anyone help me out? And then if possible, also provide an example for adding a Graph Group?
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/72266#72266]
Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]