Create the ZenPack

The first thing we’ll need to do is create the Weather Underground ZenPack. We’ll use zenpacklib 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

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

Creating source directory for
  - making directory:
  - creating file:
  - creating file:
  - creating file:
  - creating file:
  - creating file:
  - creating file:
  - copying: ./ to

Define zProperties and Classes

The zenpack.yaml 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.

  1. First let’s set a couple of environment variables to reduce some typing.
export ZP_TOP_DIR=/z/
export ZP_DIR=$ZP_TOP_DIR/ZenPacks/training/WeatherUnderground
  1. Now let’s look at the contents of zenpack.yaml.
cd $ZP_DIR
cat zenpack.yaml

You should only see the following line.

  1. Replace the contents of zenpack.yaml with the following.

    category: Weather Underground

  zWundergroundAPIKey: {}
    type: lines
      - Austin, TX
      - San Jose, CA
      - Annapolis, MD

    base: [zenpacklib.Device]
    label: Weather Underground API

    base: [zenpacklib.Component]
    label: Location

        label: Country Code

        label: Time Zone

        label: API Link
        grid_display: False

  - WundergroundDevice 1:MC WundergroundLocation

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 it’s properties to be added as the default for all of the other listed zProperties. Specifically in this case it will cause the category of zWundergroundAPIKey and zWundergroundLocations to be set to Weather Underground. This is a convenience to avoid having to repeatedly type the category for each added property.

    The zWundergroundAPIKey zProperty has an empty dictionary ({}). This is because we want it to be a string type with an empty default value. These happen to be the defaults so they don’t need to be specified.

    The zWundergroundLocations 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 Austin, TX, San Jose, CA, and Annapolis, MD.

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

    In this case we’re adding WundergroundDevice which because base is set to Device will be a subclass or specialization of the standard Zenoss device type. We’re also adding WundergroundLocation 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 WundergroundLocation are extra bits of data we want to model from the API and show to the user in the web interface. order will be used to show the properties in the defined order, and setting grid_display to false for api_link will allow it 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 WundergroundDevice and WundergroundLocation. Specifically it is saying that each (1) WundergroundDevice object can contain many (MC) WundergroundLocation objects.

Install the ZenPack

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

  1. Run the following command to install the ZenPack in developer mode.
zenpack --link --install $ZP_TOP_DIR