How to model a device using a REST or XML-RPC call
Devices can be modeled through the UI but also through a programmatic interface. This how to will describe modeling devices using that interface.
Discovering Devices
Using a REST call
Discovering and modeling multiple devices through a rest call can be done by a simple web get. In this example we will use wget to discover devices in a network. If you use wget don't for get to escape the "&" or wrap the URL in single quotes.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Networks/discoverDevices?organizerPaths=MYNETWORK&organizerPaths='
The result of this command will discover devices in the IpNetwork named MYNETWORK. You can discover devices on multiple networks by adding multiple organizerPaths values. Note that the network name should exist in Zenoss. Also, note that if you would like to discover on only one network (like the example above) add a blank organizerPaths value. The discoverDevices method expects organizerPaths to be a list.
Adding Device Components
Using REST calls
Adding and editing device components through a rest call can be done by a simple web get. In this example we will use wget to add and edit an IpInterface to a device. If you use wget don't for get to escape the "&" or wrap the URL in single quotes.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/addIpInterface?id=NEWINTERFACE&userCreated=True'
The result of this command will create a new IpInterface NEWINTERFACE on the device MYDEVICE.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/addIpAddress?ip=NEWIPADDRESS'
The result of this command adds an IpAddress NEWIPADDRESS to IpInterface NEWINTERFACE.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/setZenProperty?propname=PROPNAME&propvalue=PROPVALUE'
The result of this command will set a property PROPNAME to PROPVALUE. Similar commands could be used to add and edit other types of device components such as IpServices, Routes, FIleSystems etc.
Using an XML-RPC Call from Python
This is an example of how to add and edit a device component using python. Because XML-RPC can be used from any language feel free to use your favorite.
>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE')
>>> serv.os.addIpInterface('NEWINTERFACE', True)
>>> serv.os.interfaces.NEWINTERFACE.addIpAddress('NEWIPADDRESS')
>>> serv.os.interfaces.NEWINTERFACE.setZenProperty('PROPNAME', 'PROPVALUE')
These commands will have the same results as the REST call above.
Locking Device Components
Devices and device components can be locked from further modeling. You can lock an object from being deleted by the modeler. You can lock an object from being deleted or updated from the modeler. In addition to locking, you can also set a flag that will send an event when the modeler tries and is blocked from deleting or updating an object. Of course, you are also able to unlock the device and allow the modeler to delete and update the object.Using REST calls
Locking device components through a rest call can be done by a simple web get. In this example we will use wget to lock and unlock an IpInterface. If you use wget don't for get to escape the "&" or wrap the URL in single quotes.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/lockFromDeletion'
This command will lock the IpInterface NEWINTERFACE from being deleted by the modeler.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/lockFromDeletion?sendEventWhenBlocked=True'
This command will lock the IpInterface NEWINTERFACE from being deleted by the modeler. It will send an event when the modeler is blocked from deleting NEWINTERFACE.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/lockFromUpdates'
This command will lock the IpInterface NEWINTERFACE from being deleted or updated by the modeler.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/lockFromUpdates?sendEventWhenBlocked=True'
This command will lock the IpInterface NEWINTERFACE from being deleted or updated by the modeler. It will also send an event when the modeler is blocked from deleting or updating NEWINTERFACE.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE/unlock'
This command will unlock the IpInterface NEWINTERFACE, making it able to be deleted or updated by the modeler.
Using an XML-RPC Call from Python
This is an example of how to lock and unlock a device component using python. Because XML-RPC can be used from any language feel free to use your favorite.>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/os/interfaces/NEWINTERFACE')
>>> serv.lockFromDeletion()
>>> serv.lockFromDeletion(True)
>>> serv.lockFromUpdates()
>>> serv.lockFromUpdates(True)
>>> serv.unlock()
These commands will have the same results as the REST call above.
Modeling a Device
Using REST calls
Modeling a device through a rest call can be done through the web UI or by a simple web get. In this example we will use wget to model a device and it's components. If you use wget don't for get to escape the "&" or wrap the URL in single quotes.
[zenoss@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE/collectDevice'
This command will trigger the modeler to model this device.
Using an XML-RPC Call from Python
This is an example of how to model a device using python. Because XML-RPC can be used from any language feel free to use your favorite.
>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Discovered/devices/MYDEVICE')
>>> serv.collectDevice(False)
These commands will have the same results as the REST call above.