1. Calling Methods Using Rest

This section describes some more advanced Zenoss concepts that we have encountered as the product has rolled out. Some may be appropriate for your environment. Usually they require at least a little coding experience, but they are really not that hard.

1.1. How To Call Methods Using Rest

Zenoss's web interface will let you run any method of any object using a simple URL. Calls will be in the following format:

http://USERNAME:PASSWORD@MY_ZENOSS_HOST:8080/PATH_TO_OBJECT/METHOD_NAME?ARG=VAL

  1. USERNAME is the user with the rights to view this information.

  2. PASSWORD is the user's password

  3. MY_ZENOSS_HOST is the hostname or IP of your instance of Zenoss

  4. PATH_TO_OBJECT is the full path to the object you wish to access

  5. METHOD_NAME is the object's method you wish to run

  6. ARG is a method's parameter name

  7. VAL is a methods's parameter value

Another example:

This example will give the most recent load average of a Linux server:

http://USERNAME:PASSWORD@MY_ZENOSS_HOST:8080/zport/dmd/Devices/Server/Linux/devices/angel/getRRDValue?dsname=laLoadInt5_laLoadInt5

Notice the following things about this URL:

  1. /zport/dmd/Devices/Server/Linux/devices/angel is the full path to our object you want to access

  2. getRRDValue is the method in the Device object we wish to run

  3. dsname is a parameter to the getRRDValue method.

  4. laLoadInt5_laLoadInt5 is the value of dsname which is the name of the data source we are interested in.

Watching the URLs as you browse the web interface can give you a place to start searching.

1.2. Sending an Event

This section describes some more advanced Zenoss concepts that we have encountered as the product has rolled out. Some may be appropriate for your environment. Usually they require at least a little coding experience, but they are really not that hard.

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

1.2.1. Using a REST Call

Sending an event through a rest call can be done by a simple web get. In this example we will use wget to send an event. 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/ZenEventManager/manage_addEvent?device=MYDEVICE&component=MYCOMPONENT&summary=MYSUMMARY&severity=4&eventclass=EVENTCLASS'

1.2.2. How to Call Methods Using REST

Zenoss's web interface will let you run any method of any object using a simple URL. Calls will be in the following format:

http://USERNAME:PASSWORD@MY_ZENOSS_HOST:8080/PATH_TO_OBJECT/METHOD_NAME?ARG=VAL

  1. USERNAME is the user with the rights to view this information.

  2. PASSWORD is the user's password

  3. MY_ZENOSS_HOST is the hostname or IP of your instance of Zenoss

  4. PATH_TO_OBJECT is the full path to the object you wish to access

  5. METHOD_NAME is the object's method you wish to run

  6. ARG is a method's parameter name

  7. VAL is a methods's parameter value

The following example thanks to Chet Luther:

This example will give the most recent load average of a Linux server:

http://USERNAME:PASSWORD@MY_ZENOSS_HOST:8080/zport/dmd/Devices/Server/Linux/devices/angel/getRRDValue?dsname=laLoadInt5_laLoadInt5

Notice the following things about this URL:

  1. /zport/dmd/Devices/Server/Linux/devices/angel is the full path to our object you want to access

  2. getRRDValue is the method in the Device object we wish to run

  3. dsname is a parameter to the getRRDValue method.

  4. laLoadInt5_laLoadInt5 is the value of dsname which is the name of the data source we are interested in.

Watching the URLs as you browse the web interface can give you a place to start searching.

1.2.3. Using XML-RPC

To send an event to zenoss using XML-RPC you will first need to create a dictionary (in perl a hash) that will represent the event. Zenoss will need at a minimum the following fields:

* device - the name of the device from which this event originates

* component - the sub-component of the device (for instance eth0, http, etc)

* summary - the text message of the event

* severity - an integer between 0 and 5 with higher numbers being higher severity. Zero is clear.

You can send an event to Zenoss via an interactive session with the python interpreter as follows:

>>> from xmlrpclib import ServerProxy
>>> serv = ServerProxy('http://admin:zenoss@MYHOST:8080/zport/dmd/ZenEventManager')
>>> evt = {'device':'mydevice', 'component':'eth0', 'summary':'eth0 is down','severity':4, 'eventClass':'/Net'}
>>> serv.sendEvent(evt)

See below for examples in other languages.

1.2.4. Example Usage in Other Languages

Please note that we are a python shop and may not be able to answer specific questions about XML-RPC clients written in other languages.

1.2.4.1. Perl

Send an event via perl using RPC::XML::Client


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

$serv = RPC::XML::Client->new('http://YOURZENOSS:8081/');
%evt = ('device' => 'mydevice2', 'component' => 'eth1', 'summary' => 'eth1 is down', 'severity' => 4);
$args = RPC::XML::struct->new(%evt);
$serv->simple_request('sendEvent', $args);
1.2.4.2. Ruby

This is an example of an Interactive Ruby (IRB) session (the returns have been omitted for the sake of clarity). Note, however, that the Ruby standard library is under active development in general, and specifically, the XML-RPC lib in Ruby is not stable. As of Feb 2007, there is a great deal of on-going discussion regarding XML-RPC in Ruby by Ruby developers and contributors. The following is known to work in previous versions of Ruby:


irb(main):001:0> require "xmlrpc/client"
irb(main):002:0> server = XMLRPC::Client.new2('user:pass@http://YOURZENOSS:8080/zport/dmd/DeviceLoader')
irb(main):003:0> evt = {'device' => 'mydevice3', 'component' => 'eth2', 'summary' => 'eth2 is down', 'severity' => 4}
irb(main):004:0> server.call('sendEvent', evt)

1.2.4.3. Java

I spent too much time trying to get a Java example running (using the lastest 3.x XML-RPC libs from Apache). Using their example as well as many I found on the net, I consistently got lots of errors, only some of which I was able to fix. I tried with Java 1.3, 1.4.2, and 1.5 -- all returned nearly identical results.

If someone can provide a modern, working example, we will post it here. But we don't have to time to figure this one out right now.