Create the ZenPack
The first thing we’ll need to do is create the NWS ZenPack. We’ll
zenpacklib script to create this ZenPack from the command line using the
following steps. These commands should be run as the
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
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
cd $ZP_DIR cat zenpack.yaml
You should only see the following line.
Replace the contents of
zenpack.yaml with the following.
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.
namefield is mandatory. It must match the name of the ZenPack’s source directory.
zPropertiesfield contains configuration properties we want the ZenPack to add to the Zenoss system when it is installed.
DEFAULTSis 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
zNwsStatesto 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.
zNwsStatesproperty uses the
linestype 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.
classesfield contains each of the object classes we want the ZenPack to add.
In this case we’re adding
baseis set to
Device,will be a subclass or specialization of the standard Zenoss device type. We’re also adding
baseis set to
Component,will be a subclass of the standard component type.
labelfor 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.
NwsStationare extra bits of data we want to model from the API and show to the user in the web interface. Setting
grid_displayto false for
longitudewill allow them to be shown in the details panel of the component, but not in the component grid.
class_relationshipsuses a simple syntax to define a relationship between
NwsStation. Specifically it is saying that each (1)
NwsDeviceobject can contain many (MC)
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 (
Run the following command to install the ZenPack in developer mode.
zenpack --link --install $ZP_TOP_DIR