Skip to content

Create the ZenPack

The first thing we’ll need to do is create the NWS ZenPack. We’ll use the zenpacklib script to create this ZenPack from the command line using the following steps. These commands should be run as the zenoss user.

cd /z
zenpacklib --create ZenPacks.training.NWS

You should see output similar to the following. Most importantly that zenpack.yaml file is being created.

Creating source directory for ZenPacks.training.NWS:
  - making directory: ZenPacks.training.NWS/ZenPacks/training/NWS
  - creating file: ZenPacks.training.NWS/setup.py
  - creating file: ZenPacks.training.NWS/MANIFEST.in
  - creating file: ZenPacks.training.NWS/ZenPacks/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/datasources/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/thresholds/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/parsers/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/migrate/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/resources/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/modeler/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/tests/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/libexec/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/modeler/plugins/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/lib/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/__init__.py
  - creating file: ZenPacks.training.NWS/ZenPacks/training/NWS/zenpack.yaml

Define zProperties and classes

The zenpack.yaml file that’s created within the ZenPack source directory above contains only the absolute minimum to be a valid YAML file. Let’s take a look at its current contents.

First let’s set a couple of environment variables to reduce some typing.

export ZP_TOP_DIR=/z/ZenPacks.training.NWS
export ZP_DIR=$ZP_TOP_DIR/ZenPacks/training/NWS

Now let’s look at the contents of zenpack.yaml.

cd $ZP_DIR
cat zenpack.yaml

You should only see the following line.

zenpack.yaml
name: ZenPacks.training.NWS

Replace the contents of zenpack.yaml with the following.

zenpack.yaml
name: ZenPacks.training.NWS

zProperties:
  DEFAULTS:
    category: National Weather Service

  zNwsStates:
    type: lines
    default:
      - TX
      - OK

classes:
  NwsDevice:
    base: [zenpacklib.Device]
    label: National Weather Service API

  NwsStation:
    base: [zenpacklib.Component]
    label: Station

    properties:
      country_code:
        label: Country Code

      timezone:
        label: Time Zone

      nws_zone:
        label: Zone

      county:
        label: County

      latitude:
        label: Latitude
        grid_display: False

      longitude:
        label: Longitude
        grid_display: False

class_relationships:
  - NwsDevice 1:MC NwsStation

You can see this YAML defines the following important aspects of our ZenPack.

  1. The name field is mandatory. It must match the name of the ZenPack’s source directory.

  2. The zProperties field contains configuration properties we want the ZenPack to add to the Zenoss system when it is installed.

    Note that DEFAULTS is not added as configuration property. It is a special value that will cause its properties to be added as the default for all of the other listed zProperties. Specifically in this case it will cause the category of zNwsStates to be set to National Weather Service. This is a convenience to avoid having to repeatedly type the category for each added property. Since we're only adding one zProperty, it doesn't really save us anything in this case, but it is still a best practice. In the future, you may need to add additional zProperties, and you'd need to then refactor to set the default.

    The zNwsStates property uses the lines type which allows the user to specify multiple lines of text. Each line will be turned into an element in a list which you can see is also how the default value is specified. The idea here is that unless the user configures otherwise, we will default to monitoring weather alerts and conditions for stations in Texas and Oklahoma.

  3. The classes field contains each of the object classes we want the ZenPack to add.

    In this case we’re adding NwsDevice which, because base is set to Device, will be a subclass or specialization of the standard Zenoss device type. We’re also adding NwsStation which, because base is set to Component, will be a subclass of the standard component type.

    The label for each is simply the human-friendly name that will be used to refer to the resulting objects when they’re seen in the Zenoss web interface.

    The properties for NwsStation are extra bits of data we want to model from the API and show to the user in the web interface. Setting grid_display to false for lattitude and longitude will allow them to be shown in the details panel of the component, but not in the component grid.

  4. class_relationships uses a simple syntax to define a relationship between NwsDevice and NwsStation. Specifically it is saying that each (1) NwsDevice object can contain many (MC) NwsStation objects.

Install the ZenPack

Creating the ZenPack with the zenpacklib script doesn’t install the ZenPack for you. So you must now install the ZenPack in developer (--link) mode.

Run the following command to install the ZenPack in developer mode.

zenpack --link --install $ZP_TOP_DIR