Developer's Guide

  • Docs Home
  • Community Home

4. Checking If A Device Exists

Devices can be checked for existence through the UI but also through a programmatic interface. This how to will describe how to check if a device exists using that interface.

4.1. Using a REST call

Checking if a device exists through a rest call can be done by a simple web get. In this example we will use wget to check of the existence of a device. If you use wget don't for get to escape the "&" or wrap the URL in single quotes.

$ wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Server\
/Linux/devices/MYDEVICE'

If this command results with an exit code of 1 and a server response code of 404, then MYDEVICE does not exist in Zenoss. If this command results with an exit code of 0 and a server response code of 200, the MYDEVICE does exist in Zenoss.

4.2. Using an XML-RPC Call from Python

This is an example of how to check if a device exists using Python. Because XML-RPC can be used from any language feel free to use your favorite. What is important here is the base URL in ServerProxy.

>>> from xmlrpclib import ServerProxy
>>> cp = 'Devices/Server/Linux/devices'
>>> url = 'http://admin:zenoss@MYHOST:8080/zport/dmd/%s/NEWDEVICE' % cp
>>> serv = ServerProxy(url)
>>> try:
>>>     serv.getId()
>>>     exists = True
>>> except:
>>>     exists = False