Administration Guide

  • Docs Home
  • Community Home

4. Exporting Reports

You can export data from any Zenoss report, as comma-separated value (.csv) files.

To export report data, click Export All (located at the bottom of a report).

4.1. Advanced: Add An Export Button to a Report

You can edit any report to add an Export All button to export data.

The report format appears similar to the following:

<tal:block tal:define="
objects python:here.ZenUsers.getAllThingsForReport();
objects python: (hasattr(request, 'doExport') and list(objects)) or objects;
tableName string: thisIsTheTableName;
batch python:here.ZenTableManager.getBatch(tableName,objects, sortedHeader='getUserid'
);
exportFields python:['getUserid', 'id', 'delay',
'enabled', 'nextActiveNice', 'nextDurationNice',
'repeatNice', 'where'];
">
<tal:block metal:use-macro="here/reportMacros/macros/exportableReport"> \
<tal:block metal:fill-slot="report">

The normal report markup goes here:

</tal:block>

</tal:block>

</tal:block

The first definition is a call to some method that retrieves the objects for the report. This might be a list, tuple or an iterable class.

If we are doing an export then we need this to be a list, so the second tal:define line makes sure we have a list in the event that we are doing an export. It's good to not do this if we are not doing an export. Large reports might run into performance issues if an iterable is converted to a list unnecessarily.

tablename is defined here for use by the getBatch() call that follows.

exportFields is a list of data to be included in the export. These can be attribute names or names of methods to call. See DataRoot?.writeExportRows() for more details on what can be included in this list.

Within the <tal:block metal:fill-slot="report"></tal:block> block goes the report markup you would use when not including the export functionality.

If the Export All button does not appear to function, you may need to use zenTableNavigation/macros/navtool rather than zenTableNavigation/macros/navbody in your report. The former includes the <form> tag; the latter does not. If you are not providing a <form> tag then you need to use navtool so the export button is within a form.