Community

Zenoss Newsletter
Monitored by Zenoss
SourceForge.net Logo

Edit Device Info

by zenoss last modified 2007-10-30 20:03

How to edit device info using a REST or XML-RPC call

Devices can be edited through the UI but also through a programmatic interface. This how to will describe editing device info using that interface.

Using a REST call

Editing device info through a rest call can be done by a simple web get. In this example we will use wget to add 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/manage_editDevice?serialNumber=MYSERIALNUM&tag=MYTAG'

The result of this command will change the Serial Number to MYSERIALNUM and the Tag to MYTAG for device, MYDEVICE.

Using an XML-RPC Call from Python

This is an example of how to edit device info 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, passing named parameters, and calling "editDevice" on your proxy object.

>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Server/Linux/devices/MYDEVICE')
>>> serv.manage_editDevice('MYTAG', 'MYSERIALNUM')

Here is the signature of manage_editDevice from Device.py

def manage_editDevice(self,
tag="", serialNumber="",
zSnmpCommunity="", zSnmpPort=161, zSnmpVer="v1",
rackSlot=0, productionState=1000, comments="",
hwManufacturer="", hwProductName="",
osManufacturer="", osProductName="",
locationPath="", groupPaths=[], systemPaths=[],
statusMonitors=["localhost"], performanceMonitor="localhost",
priority=3, REQUEST=None):


 

 

Example: Upper casing all Zenoss devices

This is a very crude way of changing the name of all devices to upper case. None the less the idea is to make a call to a URL that looks like this for each device in the system (the script below does so). This script is meant to be executed against the zendmd.

#example URL
#http://admin:zenoss@localhost:8080/zport/dmd/Devices/Web/devices/www.zenoss.com/renameDevice?newId=blah123

import os
for d in dmd.Devices.getSubDevices():
devnewid = d.id.upper()
devurl = 'http://admin:zenoss@localhost:8080%s' % d.getPrimaryUrlPath()
commandstr = "wget --output-document=/dev/null '%s/renameDevice?newId=%s' 1>/dev/null 2>&1" % (devurl, devnewid)
print commandstr
os.system(commandstr)


 

 

Attributes

  • deviceName - the name or IP of the device. If its a name it must resolve in DNS
  • devicePath - the device class where the first "/" starts at "/Devices" like "/Server/Linux" the default is "/Discovered"
  • tag - the tag of the device
  • serialNumber - the serial number of the device
  • zSnmpCommunity - snmp community to use during auto-discovery if none is given the list zSnmpCommunities will be used
  • zSnmpPort - snmp port to use default is 161
  • zSnmpVer - snmp version to use default v1 other valid values are v2
  • rackSlot - the rack slot of the device.
  • productionState - production state of the device default is 1000 (Production)
  • comments - any comments about the device
  • hwManufacturer - hardware manufacturer this must exist in the database before the device is added
  • hwProductName - hardware product this must exist in the manufacturer object specified
  • osManufacturer - OS manufacturer this must exist in the database before the device is added
  • osProductName - OS product this must exist in the manufacturer object specified
  • locationPath - path to the location of this device like "/Building/Floor" must exist before device is added
  • groupPaths - list of groups for this device multiple groups can be specified by repeating the attribute in the url
  • systemPaths - list of systems for this device multiple groups can be specified by repeating the attribute in the url
  • statusMonitors - list of status monitors (zenping) for this device default is "localhost"
  • performanceMonitor - performance monitor to use default is "localhost"
  • discoverProto - discovery protocol default is "snmp" other possible value is "none"
AddThis Social Bookmark Button
Document Actions