|
|
package com.monitor.zabbix.comp;
|
|
|
|
|
|
import com.monitor.zabbix.model.LoginRequest;
|
|
|
import com.monitor.zabbix.model.LoginResponse;
|
|
|
import com.monitor.zabbix.model.ZabbixRequest;
|
|
|
import com.monitor.zabbix.model.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang.SystemUtils;
|
|
|
import org.codehaus.jackson.map.ObjectMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -15,8 +14,12 @@ import org.springframework.stereotype.Component; |
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.xml.bind.SchemaOutputResolver;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static org.springframework.http.converter.FormHttpMessageConverter.DEFAULT_CHARSET;
|
|
|
|
...
|
...
|
@@ -74,13 +77,50 @@ public class ZabbixHttpComp { |
|
|
|
|
|
LoginRequest request = LoginRequest.buildRequest("admin", "zabbix");
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
/* HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
headers.setContentType(new MediaType("application", "json-rpc", DEFAULT_CHARSET));
|
|
|
headers.setContentType(new MediaType("application", "json-rpc", DEFAULT_CHARSET));*/
|
|
|
|
|
|
LoginResponse response = template.postForObject("http://192.168.102.76/zabbix/api_jsonrpc.php", request, LoginResponse.class);
|
|
|
|
|
|
System.out.println(response);
|
|
|
|
|
|
|
|
|
List<String> hostIps = new ArrayList<>();
|
|
|
|
|
|
hostIps.add("192.168.102.76");
|
|
|
|
|
|
HostInterfaceRequest request1 = HostInterfaceRequest.buildRequest(hostIps);
|
|
|
|
|
|
request1.setAuth(response.getResult());
|
|
|
|
|
|
HostInterfaceResponse response1 = template.postForObject("http://192.168.102.76/zabbix/api_jsonrpc.php", request1, HostInterfaceResponse.class);
|
|
|
|
|
|
System.out.println(response1);
|
|
|
|
|
|
List<String> items = new ArrayList<>();
|
|
|
|
|
|
items.add("23716");
|
|
|
|
|
|
items.add("23717");
|
|
|
|
|
|
items.add("23718");
|
|
|
|
|
|
long start=System.currentTimeMillis()-120*60*1000;
|
|
|
|
|
|
int start1=(int)(start/1000);
|
|
|
System.out.println(start1);
|
|
|
long end=System.currentTimeMillis()-110*60*1000;
|
|
|
int end1=(int)(end/1000);
|
|
|
System.out.println(end1);
|
|
|
HistoryRequest request2 = HistoryRequest.buildRequest("10105", items, String.valueOf(start1), String.valueOf(end1));
|
|
|
|
|
|
|
|
|
request2.setAuth(response.getResult());
|
|
|
|
|
|
HistoryResponse response2 = template.postForObject("http://192.168.102.76/zabbix/api_jsonrpc.php", request2, HistoryResponse.class);
|
|
|
|
|
|
System.out.println(response2);
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|