/**
* zabbix获取数据
*/
private static String gitItem(String result, String itemid, String value_type, String url) {
String value = null;
try {
String itemBody = "{\n" +
" \"jsonrpc\": \"2.0\",\n" +
" \"method\": \"history.get\",\n" +
" \"params\": {\n" +
" \"output\": \"extend\",\n" +
" \"history\": " + value_type + ",\n" +
" \"itemids\": " + itemid + ",\n" +
" \"sortfield\": \"clock\",\n" +
" \"sortorder\": \"DESC\",\n" +
" \"limit\": 1\n" +
" },\n" +
" \"auth\": " + result + ",\n" +
" \"id\": 1\n" +
"}";
String itemResponse = HttpsUtils.sendByHttp(itemBody, url);
value = com.cctv.foss.utils.Util.getObjectMapper().readTree(itemResponse).get("result").get(0).get("value").asText();
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return value;
}
java连接zabbix获取数据—使用字符串发送请求体
最新推荐文章于 2024-06-27 02:10:25 发布
该代码片段展示了如何使用ZabbixAPI获取特定itemid的历史数据,通过发送HTTP请求,解析JSON响应并提取值,处理可能出现的JsonProcessingException异常。
1509

被折叠的 条评论
为什么被折叠?



