Skip to content

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.

  1. 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.

    1. 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.

    2. Next we set zPythonClass to ZenPacks.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 above classes section.

    3. We then set both zPingMonitorIgnore and zSnmpMonitorIgnore 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.

    4. Finally we set zCollectorPlugins to contain the name of the modeler plugin we created in the previous section. Note that zCollectorPlugins is a lines property, meaning it accepts multiple values in a list format.

  2. 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