The first thing we’ll need to do is install the zenpacklib ZenPack into our development system. This is done in the same way as it would be in any Zenoss system.
The zenpacklib ZenPack provides the zenpacklib command line tool, which will allow us to create ZenPacks.
This tutorial assumes your system is already set up.
The latest version of ZenPackLib can be downloaded from its entry in the ZenPack Catalog. Note that you may already have the latest version installed on your system. The following commands show how you would download and install version 2.1.1.
From here on all commands should be run as the
unless otherwise noted. If you don't log in to the host as the
su - zenoss to get a login shell.
cd /tmp wget https://storage.googleapis.com/zenpacks/ZenPacks.zenoss.ZenPackLib/2.1.1/ZenPacks.zenoss.ZenPackLib-2.1.1.egg serviced service run zope zenpack-manager install ZenPacks.zenoss.ZenPackLib-2.1.1.egg
zenpacklib requires a live Zenoss environment.
To ensure you have the right environment, always run it
zenoss user in your Zope container, as demonstrated
in the following commands:
serviced service attach zope # attach to zope container su - zenoss # become zenoss user in zope container zenpacklib --version exit # back to root in container exit # back to host
If you set up the helper aliases and functions, the preceding commands can be replaced with the following command:
Creating a ZenPack
There are two ways to get started with
zenpacklib. You can either use it
to create a new ZenPack from the command line, or you can update an
existing ZenPack to use it. We’ll start by creating a ZenPack from the
Run the following commands to create a new ZenPack.
## Create ZenPacks in /z so the host and containers can access them. cd /z zenpacklib --create ZenPacks.acme.Widgeter
This will print several lines to let you know what has been created. Note that the ZenPack’s source directory has been created, but it has not yet been installed.
Creating source directory for ZenPacks.acme.Widgeter: - making directory: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter - creating file: ZenPacks.acme.Widgeter/setup.py - creating file: ZenPacks.acme.Widgeter/MANIFEST.in - creating file: ZenPacks.acme.Widgeter/ZenPacks/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/datasources/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/thresholds/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/parsers/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/migrate/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/resources/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/modeler/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/tests/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/libexec/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/modeler/plugins/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/lib/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/__init__.py - creating file: ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/zenpack.yaml
Now let’s take a look at
zenpack.yaml. This is the file that will
define a large part of what our ZenPack is.
Let’s add a device class and a monitoring template to our ZenPack.
zenpack.yaml to contain the following:
name: ZenPacks.acme.Widgeter device_classes: /Server/ACME/Widgeter: zProperties: zDeviceTemplates: - WidgeterHealth templates: WidgeterHealth: description: ACME Widgeter monitoring. datasources: health: type: COMMAND parser: Nagios commandTemplate: "echo OK|percent=100" datapoints: percent: rrdtype: GAUGE rrdmin: 0 rrdmax: 100 thresholds: unhealthy: dsnames: [health_percent] eventClass: /Status severity: Warning minval: 90 graphs: Health: units: percent miny: 0 maxy: 0 graphpoints: Health: dpName: health_percent format: "%7.2lf%%"
Check for Correctness
Now that we have a more interesting
zenpack.yaml, let’s have
zenpacklib check that it’s correct. This can be done using
zenpacklib --lint ZenPacks.acme.Widgeter/ZenPacks/acme/Widgeter/zenpack.yaml
Lint will print information about errors it finds in the YAML file. If nothing is printed, lint thinks the YAML is correct.
Installing a ZenPack
Now that we’ve created a ZenPack
/z, we can install it into our
Zenoss system by running the following command.
z zenpack --link --install ZenPacks.acme.Widgeter
Zenoss must be restarted anytime a new ZenPack is installed.
serviced service restart Zenoss.resmgr
Technically it isn’t necessary to restart everything. A lot of the infrastructure services don’t use ZenPack code. The following is a smaller list of services that you’re likely to need to restart after installing and modifying ZenPacks during development.
The following command will quickly restart just these services.
echo Zope zenhub zeneventd zenactiond zenjobs | xargs -n1 serviced service restart