Discussion:
JSON API problems in 4.2?
j053ph4
2012-11-20 20:32:49 UTC
Permalink
j053ph4 [http://community.zenoss.org/people/j053ph4] created the discussion

"JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70028#70028

--------------------------------------------------------------
Hi,

I've been trying to get better acquainted with the new(ish) JSON API . I had gotten pretty comfortable with the DMD but it demands that any scripts using it reside on the Zenoss server, import the appropriate modules, etc...

In addition, i'm planning an upgrade to 4.2 soon, but it will require some scripts be rewritten to deal with the various changes (like event managment).  I'm hoping that using new API will "future-proof" these to some degree.  Plus it looks powerful enough now to support several of the things that weren't included in the 3.x API.

To start I'm looking at the included examples, specifically the "event_curses.py" included with the API docs, along with the API documentation itself.  For starters, the "event_curses.py" (from the 4.2 docs) works fine against a 3.2.1 server, but not against the 4.2 server.  I see the following error when trying to execute the script:

*Traceback (most recent call last):*
*  File "event_curses.py", line 71, in <module>*
*    curses.wrapper(main)*
*  File "/opt/zenoss/lib/python2.7/curses/wrapper.py", line 43, in wrapper*
*    return func(stdscr, *args, **kwds)*
*  File "event_curses.py", line 33, in main*
*    rawEvents = z.get_events()['events']*
*KeyError: 'events'*

Additionally, when trying to use the 'getDevices' method (following the example in "api_example.py"), i see the following when running against the 4.2 server:

*data = [{'uid':'/zport/dmd/Devices/Server/Linux'}]*
*>>> z._router_request('DeviceRouter','getDevices',data)*
*{u'uuid': u'59dac3fb-7085-4e23-b78f-2be7600e9bfd', u'tid': 26, u'result': {u'msg': u"AttributeError: 'DeviceInfo' object has no attribute 'titleOrId'", u'type': u'exception', u'success': False}, u'action': u'DeviceRouter', u'type': u'rpc', u'method': u'getDevices'}*

this method works fine against the 3.2.1 server, however.

BTW, there are only 2 devices in my 4.2 server, and the 'titleOrId' method works fine against them in the DMD.
From the docs, it looks like these methods haven't changed, but hopefully someone can see an obvious mistake or point me in the right direction?
Thanks in Advance,
Joseph
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70028#70028]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jcurry
2012-11-21 09:15:43 UTC
Permalink
jcurry [http://community.zenoss.org/people/jcurry] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70048#70048

--------------------------------------------------------------
Hi Joseph,
This is spooky!  Yesterday I was working on your MQ ZenPack and on this exact same JSON thing, for the first time, with exactly the same result as yourself.  It's on my list for today.  I'll certainly post here if I make it work.

Cheers,
Jane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70048#70048]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jcurry
2012-11-21 13:33:45 UTC
Permalink
jcurry [http://community.zenoss.org/people/jcurry] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70049#70049

--------------------------------------------------------------
This is a known one - see   http://jira.zenoss.com/jira/browse/ZEN-2812 http://jira.zenoss.com/jira/browse/ZEN-2812 .  It says it is fixed but no indication where to get the fix from.  The JIRA report does seem to match exactly and says it DID work with Core 3.  I have added a comment asking if a patch could be made available.

There is a workaround here - http://community.zenoss.org/message/69155#69155 http://community.zenoss.org/message/69155#69155  that seems to work for me.

Cheers,
Jane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70049#70049]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Philip Warren
2012-11-21 14:44:57 UTC
Permalink
Philip Warren [http://community.zenoss.org/people/pwarren] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70051#70051

--------------------------------------------------------------
I have marked this issue as a candidate for the next service release and attached a patch to ZEN-2812 if you want to try the fix against the current release.

Thanks,
Philip
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70051#70051]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jcurry
2012-11-21 14:50:14 UTC
Permalink
jcurry [http://community.zenoss.org/people/jcurry] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70052#70052

--------------------------------------------------------------
Brilliant - thanks Philip.

For the idiots like me, what's the best way to apply this patch (short of cutting and pasting the lines)??

This is particularly welcome as it breaks the JSON API Python examples that both Joseph and I were trying to make work.

Cheers,
Jane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70052#70052]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Philip Warren
2012-11-21 15:28:16 UTC
Permalink
Philip Warren [http://community.zenoss.org/people/pwarren] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70053#70053

--------------------------------------------------------------
To apply the patch, do the following:

$ cd $ZENHOME
$ patch -p0 -u --dry-run < ZEN-2812-42x.patch
# If the previous step is successful, re-apply without the '--dry-run'
$ patch -p0 -u < ZEN-2812-42x.patch
$ zopectl stop
$ zopectl start


Let me know if you have any problems.

Philip
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70053#70053]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
j053ph4
2012-11-21 15:51:53 UTC
Permalink
j053ph4 [http://community.zenoss.org/people/j053ph4] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70041#70041

--------------------------------------------------------------
Thanks for the instructions...the patch works like a champ.

Joseph
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70041#70041]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jcurry
2012-11-21 16:02:56 UTC
Permalink
jcurry [http://community.zenoss.org/people/jcurry] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70055#70055

--------------------------------------------------------------
Did you have to add the extra comma???

I am very confused if you were successful just following Philip's patch.

Presumably the device bit isn't working yet?

Cheers,
Jane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70055#70055]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
j053ph4
2012-11-21 17:47:03 UTC
Permalink
j053ph4 [http://community.zenoss.org/people/j053ph4] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70061#70061

--------------------------------------------------------------
I did have to add the commas...i sent an email reply to this post awhile ago, but looks like it didn't make it.  I had forgotten to mention that it "worked like a champ" AFTER I put the commas in.  You had posted the comment on JIRA so quickly that I fixed it right way and then forgot about it.

Joseph
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70061#70061]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Philip Warren
2012-11-21 19:18:15 UTC
Permalink
Philip Warren [http://community.zenoss.org/people/pwarren] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70058#70058

--------------------------------------------------------------
Updated the patch to add the commas (now named ZEN-2812-42x-2.patch). For some reason SVN merge removed them - thanks for the comments.

Philip
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70058#70058]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Chet Luther
2012-11-22 04:51:25 UTC
Permalink
Chet Luther [http://community.zenoss.org/people/cluther] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70072#70072

--------------------------------------------------------------
I was just looking at these JSON API issues and wanted to summarize what I came to learn in the hopes that it clears things up for others looking at this thread.

Problems running the event_curses.py example in the python directory of the JSON API documentation, or errors such as the following while calling EventsRouter.query through the JSON API are related to issue ZEN-2812. We create maintenance issues in cases where issues like ZEN-2812 need to be fixed in a maintenance release. The maintenance issue for ZEN-2812 is ZEN-4331.

TypeError: 'NoneType' object is not iterable


It has also been pointed out that using the ZenossAPIExample.get_devices method in api_example.py within the JSON API documentation's python directory doesn't work either. It causes the following error.

AttributeError: 'DeviceInfo' object has no attribute 'titleOrId'

This problem is described in ZEN-1817. I've just updated ZEN-1817 with more information from this topic and from my own testing. It'll go through defect review and a corresponding maintenance issue will probably be created for it too.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70072#70072]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
jcurry
2012-11-21 15:56:41 UTC
Permalink
jcurry [http://community.zenoss.org/people/jcurry] created the discussion

"Re: JSON API problems in 4.2?"

To view the discussion, visit: http://community.zenoss.org/message/70054#70054

--------------------------------------------------------------
Well I patched this simply by copying the patch into $ZENHOME/Products/Zuul/routers (where zep.py is).  I copied the original zep.py for safety and then simplay ran
patch <name of patch file>

Stopped and started zenoss.

Barfed in 15 different positions.  I believe the issue is that the patch lines (there are only 2 of them) both need a comma on the end of them.  Having remodified those lines, zenoss now starts fine.

The JSON API event_curses.py now sort-of runs but I doubt it is behaving as it did in 3.2.

I also find that the list_devices.py JSON Python example fails - I suspect it is a similar issue somewhere in the devices router.

It would be really helpful if someone could post some JSON examples that work with Zenoss 4.2 to help get us all started with this interface.

Many thanks,
Jane
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70054#70054]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...