Thursday, April 1, 2010

Using Ruby with Zenoss - Part 1

I have been using Zenoss now for over a year and for the most part have been quite happy with it. It's quite customizable and you can find a way to pretty much monitor anything if you put some thought into it. However, my one point of contention has been with the REST interface. Most things work as you would expect, but somethings blow up and don't give you a very good reason except for a nice Zope stack-trace.  Prior to using Zenoss, I had very little experience with Zope so some of my issues were simply just lack of knowledge of how REST methods were called from within it.  I wrongly thought that there was a translation layer that sat between the web user and the back-end to marshal and unmarshal datatypes.  This does not seem to be what is going on.  So if I can sum up all of the issues that I struggled with it's this:
  •  If the Python method you're calling on the back-end is expecting something other than a string you're probably going to have issues.
So, coupled with my poor knowledge of Zope and my frustration on how to call REST methods in a consistent way, I decided to create a library for Zenoss in Ruby.  My goal was to create that middle layer to correctly marshal and unmarshal data-types.
I chose Ruby because I find it a fun language to program in and well, I guess that pretty much sums it up ;-)
 In order for the library to work there is one thing that you need to do on the Zenoss/Zope side.  To marshal data-types into Python you most certainly need to do it in Python so we have to add a custom script to Zope.
  1. Go to the Zope Management page:
    • http://zenoss:8080/zport/dmd/manage
  2.  Select "Script (Python)" from the upper-right drop-down
    • ID = callZenossMethod
      • "Add and Edit"
    • Title = "Work around for unsupported Zenoss methods"
    • Parameter List = methodName
    • Clear out the code contents from the text box and cut-and-paste the code found here:
    • "Save Changes"
Once the custom Python is in place simply install the ruby gem:
  • gem install -r zenoss_client
That's it, you should be ready to roll.  Check back here soon for the second part of this post for example usage of the zenoss_client library.

addendum: Link to zenoss_client source code: zenoss_client


  1. This looks pretty cool. You'll be happy to know the next major release of Zenoss will have a real, documented API (as opposed to generated code docs). This should make dealing with Zenoss remotely more straightforward.

    Matt Ray
    Zenoss Community Manager

  2. Thanks for the heads up Matt. After you get used to the format API docs aren't so bad, but it would be nice to see a bit more verbosity as to what some of the method parameters expect and what some of the return values are. I look forward to looking through the new API docs.