Archived community.zenoss.org | full text search
Skip navigation
Currently Being Moderated

Adding Devices Programmatically

VERSION 5  Click to view document history
Created on: Sep 14, 2009 11:16 AM by Noel Brockett - Last Modified:  Mar 18, 2011 6:49 PM by Nick Yeates

How to add a device using a REST or XML-RPC call

 

Devices can be added to Zenoss through the UI but also through a programmatic interface. This how to will describe adding a device using that interface.

Using a REST call

Adding a device 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, as seen in the example below:

 

[zenos@zenoss $] wget 'http://admin:zenoss@MYHOST:8080/zport/dmd/DeviceLoader/loadDevice?deviceName=NEWDEVICE&devicePath=/Server/Linux'

 

The result of this command will be downloaded to a file on the unix system you are in. The file will display a discovery log in html format and you can look for the string "NEWDEVICE loaded!" to see if it was successful. Possible failure messages are: "NEWDEVICE exists" and "no snmp found".

Using an XML-RPC Call from Python

 

This is an example of how to add a device 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 "loadDevice" on your proxy object.

 

>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/DeviceLoader')
>>> dev = {'deviceName':'NEWDEVICE', 'devicePath':'/Server/Linux'}
>>> serv.loadDevice(dev)

 

The return codes from load device are as follows:

 

  • 0 - everything worked
  • 1 - something bad happened that we don't understand check events.log
  • 2 - device exists already
  • 3 - no snmp community found for the device

 

The arguments below are listed in the order of the method signature. Arguments must be passed by position. If you need to pass an argument towards the end, like discoverProto, you will need to also pass the ones that precede it. Like this:

 

serv.loadDevice('DEVICENAME', "/Server/Linux",
        "", "",         # tag="", serialNumber="",
        "", "", "",     # zSnmpCommunity="", zSnmpPort=161, zSnmpVer=None,
        0, 1000, "",    # rackSlot=0, productionState=1000, comments="",
        '', '',         # hwManufacturer="", hwProductName="",
        '', '',         # osManufacturer="", osProductName="",
        '', [], [],     # locationPath="", groupPaths=[], systemPaths=[],
        ['localhost'],  # statusMonitors=["localhost"], 
        'localhost',    # performanceMonitor="localhost',
        'none')         # discoverProto="snmp"

 

You don't need to pass arguments after the one that you are interested in for example

 

serv.loadDevice('DEVICENAME', "/Server/Linux",
        "", "",     # tag="", serialNumber="",
        "private")  # zSnmpCommunity=""

 

You can check on the device with another XML-RPC call:

 

>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/Devices/Server/Linux/devices/NEWDEVICE')
>>> print serv.getManageIp()

 

PERL

 

From Perl, if using Zenoss >= 3.0, the CPAN module Zenoss can be used to programatically interface with *any* part of the Zenoss monitoring system.  Anything the UI can do the Zenoss perl API interface can do.
http://search.cpan.org/dist/Zenoss/

Adding device examples can be found at:
http://search.cpan.org/dist/Zenoss/lib/Zenoss/Examples.pod

 

From Perl the device add command would look like this (older method):

 

require RPC::XML;
require RPC::XML::Client;

$serv = RPC::XML::Client->new('http://admin:zenoss@192.168.1.140:8080/zport/dmd/DeviceLoader');
print $serv->simple_request('loadDevice',
                        RPC::XML::string->new('DEIVCENAME'),
                        RPC::XML::string->new('/Server/Linux'));

Argument Dictionary

  • 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"
Comments (0)