Community

Zenoss Newsletter
Monitored by Zenoss
SourceForge.net Logo

How to Check if a Device Exists

by zenoss last modified 2007-06-08 14:35

How to check if a device exists using a REST or XML-RPC call

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.

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.

[zenos@zenoss $] 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.

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
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Server/Linux/devices/MYDEVICE')
>>> try:
>>> serv.getId()
>>> exists = True
>>> except:
>>> exists = False
AddThis Social Bookmark Button
Document Actions