Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

Creating Methods for Custom Reports

VERSION 1 
Created on: Sep 14, 2009 11:21 AM by Noel Brockett - Last Modified:  Sep 14, 2009 11:21 AM by Noel Brockett

Need data in a custom device report that isn't already available? No problem!

Creating Methods for Custom Reports

Zenoss allows you to create "Custom Device Reports" that operate on the simple principal that you want a tabular report that has one device per row. The columns are flexible and can contain anything Zenoss knows about your devices. The only built-in limitation is that the device "object" has to have an existing property or method that allows retrieval of the data you're interested in. One further limitation is that any method you use can take no parameters and must return a single value that can be converted into a string.

 

Thanks to the wonderful flexibility of the Zope framework we can very easily get by these limitations by creating our own methods to return absolutely any data we want to see on a custom device report right from the web interface. Because these new methods are stored in the Zope database they are also automatically backed up by the zenbackup program and are upgrade-safe.

 

A good HowTo needs a good example. This one comes from a question David Sloboda asked to the zenoss-users mailing list. The basic gist is that he wants to list out all of the IP services monitored for all devices. So let's get started.

Creating the Custom Method

We'll create a custom method called "getIpServicesListAsString" to do this. This may seem long-winded, but it leaves nothing to the imagination and will be easier to understand when someone goes back and looks at your custom device report definition in the future. This method is applicable to all devices, so we'll create it at the root of the device class tree.

  1. Go to http://yourzenoss:8080/zport/dmd/Devices/manage
  2. Choose "Script (Python)" from the drop-down in the upper-right
  3. Set the Id to "getIpServicesListAsString" without the quotes
  4. Click Add and Edit
  5. Erase the default contents and replace with the following Python code
  6. Click Save

return ','.join([ s.name() for s in context.os.ipservices() if s.monitored() ])

Creating the Custom Device Report

Now that we have a method that gives us the data we're looking for, we can use it in a custom devices report using the following steps.

 

  1. Go to Reports -> Custom Device Reports
  2. Choose "Add Device Report" from the Reports menu
  3. Call it "Inventory - Devices" or whatever makes sense to you
  4. Setup the report as follows:
    Sort Column = getId
    Columns =
        getId
        getIpServicesListAsString

    Column Names =
        Device
        IP Services
  5. Save

 

That's all there is to it! You can probably see how this could be expanded on to get any data you want into a custom device report.

Comments (0)