java连接zabbix获取数据—使用字符串发送请求体

/**
     * 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;
    }

你可能感兴趣的:(zabbix,java,zabbix)