Add a device class
To support adding our special NwsDevice
devices that we defined in
zenpack.yaml
to Zenoss we must create a new device class. This will
give us control of the zPythonClass
configuration property that
defines what type of devices will be created. It will also allow us to
control what modeler plugins and monitoring templates will be used.
Use the following steps to add the device class.
-
Add the following content to the end of
$ZP_DIR/zenpack.yaml
.device_classes: /NWS: zProperties: zPythonClass: ZenPacks.training.NWS.NwsDevice zPingMonitorIgnore: true zSnmpMonitorIgnore: true zCollectorPlugins: - NWS.Stations
Let’s take a look at what we’re doing here.
-
First we’re saying the device class is going to be
/NWS
. We add it at the top level because it doesn’t fall into one of the existing categories like/Server
or/Network
. -
Next we set
zPythonClass
toZenPacks.training.NWS.NwsDevice
. The zPythonClass property controls what type of device will be created in this device class. Note that the value for this is the name of the ZenPack followed by the name of the class we created in the aboveclasses
section. -
We then set both
zPingMonitorIgnore
andzSnmpMonitorIgnore
to true to prevent any ping or SNMP monitoring Zenoss would perform on the device by default. Neither of these make sense since we’re dealing with an HTTP API, not a traditional device. -
Finally we set
zCollectorPlugins
to contain the name of the modeler plugin we created in the previous section. Note thatzCollectorPlugins
is alines
property, meaning it accepts multiple values in a list format.
-
-
Reinstall the ZenPack to create the device class.
zenpack --link --install $ZP_TOP_DIR
Add a device
Now would be a good time to add a device to the new device class. There are many ways to add a device to Zenoss. Either of the following approaches can be easily done from the command line.
Using zendisc
Using zendisc
is the easiest way to add device from the command line.
However, it only lets you specify the device class and the device’s
address.
Run the following command to add api.weather.gov
.
zendisc run --deviceclass=/NWS --device=api.weather.gov
You should see output similar to the following.
INFO zen.ZenDisc: Connecting to localhost:8789
INFO zen.ZenDisc: Connected to the zenhub/0 instance
INFO zen.ZenDisc: Getting configuration from ZenHub...
INFO zen.ZenDisc: Looking for api.weather.gov
INFO zen.ZenDisc: Found IP 184.27.220.20 for device api.weather.gov
INFO zen.ZenDisc: Finished scanning device with address 184.27.220.20
INFO zen.ZenDisc: Discovered device api.weather.gov.
INFO zen.ZenDisc: Result: api.weather.gov
INFO zen.ZenDisc: Starting collector loop #001...
INFO zen.ZenDisc: Got 1 devices to be scanned during collector loop #001
INFO zen.ZenDisc: Counter eventCount, value 2
INFO zen.ZenDisc: Filled collection slots for 1 of 1 devices during collector loop #001
INFO zen.ZenDisc: skipping WMI-based collection, PySamba zenpack not installed
INFO zen.ZenDisc: Collect on device api.weather.gov for collector loop #001
INFO zen.ZenDisc: Python collection device api.weather.gov
INFO zen.ZenDisc: plugins: NWS.Stations
INFO zen.PythonClient: api.weather.gov: collecting data
INFO zen.ZenDisc: No command plugins found for api.weather.gov
INFO zen.ZenDisc: SNMP monitoring off for api.weather.gov
INFO zen.ZenDisc: No portscan plugins found for api.weather.gov
INFO zen.PythonClient: Python client finished collection for api.weather.gov
INFO zen.ZenDisc: Counter eventCount, value 2
INFO zen.ZenDisc: Changes in configuration applied
INFO zen.ZenDisc: Finished processing client within collector loop #001
INFO zen.ZenDisc: Scan time: 37.21 seconds for collector loop #001
INFO zen.ZenDisc: Scanned 1 of 1 devices during collector loop #001
INFO zen.ZenDisc: Daemon ZenDisc shutting down