TECHZEN Zenoss User Community ARCHIVE  

XHR Request to the JSON API

Subject: XHR Request to the JSON API
Author: [Not Specified]
Posted: 2015-02-20 20:16

Hello,

I'm creating a simple Javascript based web app (a map)... I need to get the device list via JSON API which I know how to do from Java or Python... But since Javascript uses a XHR request, browsers won't let me query Zenoss because I'm doing it from a different domain (CORS, love to hate it)...

I've dealt with this problem many times and usually it requires a simple line on the server side, like this on PHP:
header("Access-Control-Allow-Origin: *");

Is there a way to deal with this problem with Zenoss

There was a TV plataform that I had to deal with the same problem but it was a closed source proprietary software... Since I couldn't set the header, I actually made a "proxy" Java app that doesn't care about CORS and would do the requests for me...

Any help would be appreciated... Trying to avoid the whole proxy thing this time...



Subject: IMHO proxy app is the best
Author: Jan Garaj
Posted: 2015-02-21 13:12

IMHO proxy app is the best solution for you. It's your code, under your control/domain.

OR
1.) Nginx as a HTTP(s) proxy for Zope/Zenoss
and Nginx will "inject" required headers
http://wiki.zenoss.org/Newsletter:5/Encrypt_All_the_Bits
http://enable-cors.org/server_nginx.html

2.) Zope code modification
I don't have idea what and where you need to modify.
But probably output from the command:
grep -rin ".setHeader('" /opt/zenoss/Products/*
will help you with Zenoss hacking :-)

Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.

DevOps stack: Docker / Kubernetes / Mesos / Zabbix / Zenoss / Grafana / Puppet / Ansible / Vagrant / Terraform / Elasticsearch



Subject: I went with the proxy app...
Author: [Not Specified]
Posted: 2015-02-24 12:15

I went with the proxy app...

It's a Java app using the ZenossAPI.java provided here... But now I have another question... When I get a simple device list, the JSON only sends me 50 devices... It even tells me there is more devices but the array always have 50 at maximum...

Object { hash: "172", totalCount: 172, devices: Array[50], success: true }

Is there a hidden restriction somewhere



Subject: add "limit":2000 or whatever
Author: [Not Specified]
Posted: 2015-02-24 12:34

add "limit":2000 or whatever to your API call



Subject: Thanks, that did work...
Author: [Not Specified]
Posted: 2015-02-25 07:59

Thanks, that did work...

I must be somewhat outdated with the API because I do have an older Zenoss installation on a customer that I do the same thing and, as far as I know, I never used that parameter.



< Previous
Where is the zendmd documentation
  Next
Progamatically create local zProperty value?
>