jcurry
2012-11-23 15:41:26 UTC
jcurry [http://community.zenoss.org/people/jcurry] created the discussion
"JSON API - using generator methods"
To view the discussion, visit: http://community.zenoss.org/message/70139#70139
--------------------------------------------------------------
I want to use JSON to get events out of Zenoss. I have a working example that uses the qiery method (which returns a dictionary) but I think it would be better to use the queryGenerator method that returns a generator as this should be more efficient when getting lots of events. Just swapping the method and omitting the start and limit parameters (not wanted by queryGenerator) results in an error message like:
Traceback (most recent call last):
 File "get_events_generator.py", line 214, in <module>
   for e in events.get_events_generator(filter=option_dict, sort=s, dir=d):
 File "get_events_generator.py", line 138, in get_events_generator
   return self._router_request('EventsRouter', 'queryGenerator', [data])['result']
 File "get_events_generator.py", line 78, in _router_request
   return json.loads(self.urlOpener.open(req, reqData).read())
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 400, in open
   response = meth(req, response)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 513, in http_response
   'http', request, response, code, msg, hdrs)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 438, in error
   return self._call_chain(*args)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 372, in _call_chain
   result = func(*args)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 521, in http_error_default
   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
I started from the api_example.py code shipped with the JSON API documentation. I am suspecting that you need to change the _router_request parameters to use a generator function? And how do you handle what is returned??
A modified example of api_example.py that works with queryGenerator would be delightful....
Cheers,
Jane
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70139#70139]
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 - using generator methods"
To view the discussion, visit: http://community.zenoss.org/message/70139#70139
--------------------------------------------------------------
I want to use JSON to get events out of Zenoss. I have a working example that uses the qiery method (which returns a dictionary) but I think it would be better to use the queryGenerator method that returns a generator as this should be more efficient when getting lots of events. Just swapping the method and omitting the start and limit parameters (not wanted by queryGenerator) results in an error message like:
Traceback (most recent call last):
 File "get_events_generator.py", line 214, in <module>
   for e in events.get_events_generator(filter=option_dict, sort=s, dir=d):
 File "get_events_generator.py", line 138, in get_events_generator
   return self._router_request('EventsRouter', 'queryGenerator', [data])['result']
 File "get_events_generator.py", line 78, in _router_request
   return json.loads(self.urlOpener.open(req, reqData).read())
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 400, in open
   response = meth(req, response)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 513, in http_response
   'http', request, response, code, msg, hdrs)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 438, in error
   return self._call_chain(*args)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 372, in _call_chain
   result = func(*args)
 File "/opt/zenoss/lib/python2.7/urllib2.py", line 521, in http_error_default
   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
I started from the api_example.py code shipped with the JSON API documentation. I am suspecting that you need to change the _router_request parameters to use a generator function? And how do you handle what is returned??
A modified example of api_example.py that works with queryGenerator would be delightful....
Cheers,
Jane
--------------------------------------------------------------
Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/70139#70139]
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]