j053ph4
2012-11-20 20:32:49 UTC
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.
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]
"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]