Skip to content

Datasource plugin (modeling)

The final capability of Python data source plugins is to make changes to the Zenoss model. This allows a data source to make changes to the model in the same way that zenmodeler does. Having this capability in a data source allows modeling more frequently than the normal 12 hour zenmodeler interval.

To demonstrate this through an exercise, we’ll extend the existing Conditions plugin to capture the what the Observations API calls textDescription which is some text that looks like “Scattered Clouds” or “Sunny”. We’ll then show this value for each location in the web interface.

Model updates are much more expensive operations than creating events or collecting datapoints. It is better to perform as much modeling as possible using modeler plugins on their typical 12 hour interval, and perform only the absolutely necessary smaller model updates more frequently using a PythonDataSourcePlugin. Too much modeling activity can result in the degradation of a Zenoss’ systems overall performance.

Add modeling to conditions datasource plugin

  1. Edit $ZP_DIR/zenpack.yaml.

    Add the following weather property to the NwsStation class between the existing timezone and nws_zone properties.

      label: Current Conditions
  2. Edit $ZP_DIR/

    Add the following needed import to the top of

    from Products.DataCollector.plugins.DataMaps import ObjectMap

    Add the following code to the Conditions class’ collect method right above the returnValue(data) line indented one level further. The returnValue(data) line is included in the following update to show where the new code should be placed.

                'relname': 'nwsStations',
                'modname': '',
                'id': datasource.component,
                'weather': current_observation['textDescription'],
    returnValue(data)  # existing line

    The maps concept here is exactly the same as it is in modeler plugins. data['maps'] can contain anything that a modeler plugin’s process method can return.

  3. Don’t update the Station monitoring template.

    We’re adding capability to a datasource that’s already configured. No updates are required to the monitoring template.

  4. Restart Zenoss.

    If we had only updated the collect method of the Conditions plugin we would only need to restart zenpython. However, because we added the new weather property to the NwsStation class, we must restart nearly everything, so it’s simpler to restart everything.

Test modeling current conditions

  1. Run the following command to collect from

    zenpython run -v10

    There will be a lot of output from this command, but we’re looking for the following line which indicates that our maps were applied:

    2019-05-30 14:28:12,050 DEBUG zen.python: 600 KUNU nws-conditions sending 1 datamaps

    You can use a commmand like the following to see just these log lines:

    zenpython run -v10 | grep "sending" | grep "datamaps"
  2. Navigate to the Stations on the device and verify that each location shows something in its Weather column.