Discussion:
Test if a report exists via script
James Newman
2013-02-12 12:11:51 UTC
Permalink
James Newman [http://community.zenoss.org/people/JimForTheWin] created the discussion

"Test if a report exists via script"

To view the discussion, visit: http://community.zenoss.org/message/71454#71454

--------------------------------------------------------------
So I'm building a Reporting Zenpack:  I can create a report with all the associated datapoints, but the problem is if I try and create a second report with the same name my script errors and dies.  What I need it to do is test if a report with the given name already exists, and if so, add datapoints to that report.

What I have so far:

+profiles = sys.argv[3].split(',') # Comma separated full length profile name+

+# Initiate a connection to zendmd+
+dmd = ZenScriptBase(connect=True).dmd+

+# Specify the root location of our graphs.+
+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+
+    rpt = ro.manage_addMultiGraphReport(customer)+
+    rpt.numColumns = 2 +

+    # Create a graph definition for Traffic in+
+    gd = rpt.manage_addGraphDefinition('Traffic %s in' % (profile))+
+    gd.units = '%s in' % (profile)+
+
+


For example, I might have a customer/profile named Foo-bar-Foo  and Foo-bar-Bar.  Both have different datapoints, but I want them all under a single report.  So during my loop I create a report called   Foo-bar  and add the required datapoints for Foo-bar-Foo.  Then I look at Foo-bar-Bar and shorten it's name, to Foo-bar but when it comes to +    rpt = ro.manage_addMultiGraphReport(customer) + this causes and error as the report already exists.

I need a test something like this pseudo code:


+# Loop over all the things!+
+for profile in profiles:+
+    # Create a shortened customer name+
+    customer = '-'.join(profile.split('-')[0:2])+

*     if report(+'+/Multi-Graph Reports/++customer') doesn't exist:*
*+         # Create a report named after the customer+*
+         rpt = ro.manage_addMultiGraphReport(customer)+
+         rpt.numColumns = 2 +
+
+
+    # Create a graph definition for Traffic in+
+    gd = rpt.manage_addGraphDefinition('Traffic %s in' % (profile))+
+    gd.units = '%s in' % (profile)+



Anyone have any ideas?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/71454#71454]

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]
James Newman
2013-02-12 15:14:00 UTC
Permalink
James Newman [http://community.zenoss.org/people/JimForTheWin] created the discussion

"Re: Test if a report exists via script"

To view the discussion, visit: http://community.zenoss.org/message/71472#71472

--------------------------------------------------------------
So I tried to plough on through the error:

try:
        rpt = ro.manage_addMultiGraphReport(customer)
        rpt.numColumns = 2
    except:
pass

But that of course leaves me with rpt not set so I can't then create the graph definitions.  Any ideas?  Pretty please?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/71472#71472]

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]
Shane Scott
2013-02-12 16:43:13 UTC
Permalink
Shane Scott [http://community.zenoss.org/people/hackman238] created the discussion

"Re: Test if a report exists via script"

To view the discussion, visit: http://community.zenoss.org/message/71487#71487

--------------------------------------------------------------
James:

ro = dmd.Reports.getOrganizer('/Multi-Graph Reports/')
reportName = 'My-Report'

try:
   rpt = ro._getOb(str(reportName))
except:
   rpt = ro.manage_addMultiGraphReport(str(reportName))

Best,
--Shane Scott (Hackman238)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/71487#71487]

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]
James Newman
2013-02-12 16:55:16 UTC
Permalink
James Newman [http://community.zenoss.org/people/JimForTheWin] created the discussion

"Re: Test if a report exists via script"

To view the discussion, visit: http://community.zenoss.org/message/71474#71474

--------------------------------------------------------------
Works like a charm.  Thanks.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/71474#71474]

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]
Loading...