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.
- Go to http://yourzenoss:8080/zport/dmd/Devices/manage
- Choose "Script (Python)" from the drop-down in the upper-right
- Set the Id to "getIpServicesListAsString" without the quotes
- Click Add and Edit
- Erase the default contents and replace with the following Python code
- 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.
- Go to Reports -> Custom Device Reports
- Choose "Add Device Report" from the Reports menu
- Call it "Inventory - Devices" or whatever makes sense to you
- Setup the report as follows:
Sort Column = getId
Columns =
getId
getIpServicesListAsString
Column Names =
Device
IP Services - 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.