James Newman
2013-02-12 12:11:51 UTC
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]
"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]