Hey all,
working on creating a script that can automatically synchronize my Zabbix servers by exporting the template data on one server, then importing that data to another Zabbix server.
I'm getting an error that i can't figure out when I try to run some Javascript, no matter what method I try:
Here is my Javascript:
The weird part is, when I run this curl command:
I get the correct results back:
Any idea as to how I can adjust my Javascript to fix this error??
working on creating a script that can automatically synchronize my Zabbix servers by exporting the template data on one server, then importing that data to another Zabbix server.
I'm getting an error that i can't figure out when I try to run some Javascript, no matter what method I try:
JSON-rpc version is not specified.
Code:
function auth() {
var auth;
var url = 'http://<ip>/zabbix/api_jsonrpc.php';
var req = {
"jsonrpc":"2.0",
"method":"user.login",
"params": {
"user":"<username>",
"passowrd":"<password>"
},
"auth":null,
"id":1
};
console.log(req);
$.ajax({
type: 'POST',
data: req,
contentType: 'application/json-rpc',
url: url,
success: function(data) {
console.log(data);
if(!data.error) {
$(" #results ").text(data);
}
else {
$(" #results ").text(data.error.data);
}
},
error: function(data) {
$(" #results ").text(data.error.data);
}
});
}
auth();
The weird part is, when I run this curl command:
Code:
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"<username>","password":"<password>"},"id":1,"auth":null}' http://<ip>/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Tue, 29 Mar 2016 20:57:06 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Content-Type: application/json
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
{"jsonrpc":"2.0","result":"afcfbf67da00669c91b355e b84834372","id":1}
Date: Tue, 29 Mar 2016 20:57:06 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Content-Type: application/json
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
{"jsonrpc":"2.0","result":"afcfbf67da00669c91b355e b84834372","id":1}
Any idea as to how I can adjust my Javascript to fix this error??
Comment