Hey Guys!
Beend working with Zabbix Api lately,managed to succesfully connect to it and auth. token(Using David Webb Java plugin).
The problem is,i need to get host latitude ang longitude,but i'm strugling to write JSON request to get this data.
Used this to connect to Zabbix(Succesfully)
Trying to use this,but no luck lately,getting only host ID's.
Any ideas how i can retrive host inventory?
Thanks)
Beend working with Zabbix Api lately,managed to succesfully connect to it and auth. token(Using David Webb Java plugin).
The problem is,i need to get host latitude ang longitude,but i'm strugling to write JSON request to get this data.
Used this to connect to Zabbix(Succesfully)
Code:
import org.json.JSONObject;
import org.json.JSONException;
import com.goebl.david.Webb;
public class Zabbix_auth {
public static void main(String[] args) throws JSONException {
try {
JSONObject mainJObj = new JSONObject();
JSONObject paramJObj = new JSONObject();
mainJObj.put("jsonrpc", "2.0");
mainJObj.put("method", "user.login");
paramJObj.put("user", "username");
paramJObj.put("password", "password");
mainJObj.put("params", paramJObj);
mainJObj.put("id", "1");
Webb webb = Webb.create();
System.out.println("Data to send: " + mainJObj.toString());
JSONObject result = webb.post("http://localhost/api_jsonrpc.php")
.header("Content-Type", "application/json")
.useCaches(false)
.body(mainJObj)
.ensureSuccess()
.asJsonObject()
.getBody();
System.out.println("Authentication token: " + result.getString("result"));
} catch (JSONException je) {
System.out.println("Error creating JSON request to Zabbix API..." + je.getMessage());
}
}
}
Code:
import org.json.JSONObject;
import org.json.JSONException;
import com.goebl.david.Webb;
public class Host_info_get {
public static void main(String[] args) throws JSONException {
try {
JSONObject mainJObj = new JSONObject();
JSONObject paramJObj = new JSONObject();
mainJObj.put("jsonrpc", "2.0");
mainJObj.put("method", "host.get");
paramJObj.put("output", "location_lat");
mainJObj.put("params", paramJObj);
mainJObj.put("id", "2");
mainJObj.put("auth", "TOKEN");
Webb webb = Webb.create();
System.out.println("Data to send: " + mainJObj.toString());
JSONObject result = webb.post("http://localhost/api_jsonrpc.php")
.header("Content-Type", "application/json")
.useCaches(false)
.body(mainJObj)
.ensureSuccess()
.asJsonObject()
.getBody();
System.out.print("Host info: " + result.getString("result"));
} catch (JSONException je) {
System.out.println("Unable to get to host" + je.getMessage());
}
}
}
Thanks)
Comment