Zabbix 서버에 연결하려고합니다. 웹 브라우저를 통해 포트 10051에서 실행되는 Zabbix 서버에 액세스 할 수 있지만 Java API를 사용하여 동일한 서버에 연결할 수 없습니다. 내가Java API를 사용하여 zabbix 서버에 연결하는 방법
import io.github.cgi.zabbix.api.DefaultZabbixApi;
import io.github.cgi.zabbix.api.ZabbixApi;
public class TestClass {
ZabbixApi zabbixApi;
public static void main(String[] args) {
TestClass tc = new TestClass();
tc.before();
tc.testLogin();
// tc.testVersion();
}
public void before() {
String url = "http://xxx.xxx.xxx.xxx:10051/zabbix/api_jsonrpc.php";
zabbixApi = new DefaultZabbixApi(url);
zabbixApi.init();
}
public void testLogin() {
String user = "admin";
String password = "zabbix";
boolean login = zabbixApi.login(user, password);
System.out.println("login result:" + login);
}
public void testVersion() {
String version = zabbixApi.apiVersion();
System.err.println(version);
System.out.println("version := " + version);
}
}
클래스 경로를 연결하기 위해 사용하고있는 코드는 다음과 같은 것이있다 :
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/zabbix-api-0.0.2.jar"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/httpclient-4.5.3.jar"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/jackson-all-1.9.9.jar/jackson-all-1.9.9.jar"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/httpcore-4.4.8.jar"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/commons-logging-1.2/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="D:/Software_Development/Jars/slf4j-api-1.7.25.jar"/>
<classpathentry kind="output" path="bin"/>
오류이 코드를 실행하는 동안 :
Exception in thread "main" java.lang.RuntimeException: DefaultZabbixApi call exception!
at io.github.cgi.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:142)
at io.github.cgi.zabbix.api.DefaultZabbixApi.login(DefaultZabbixApi.java:72)
at TestClass.testLogin(TestClass.java:25)
at TestClass.main(TestClass.java:12)
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:839)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at io.github.cgi.zabbix.api.DefaultZabbixApi.call(DefaultZabbixApi.java:138)
... 3 more
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:149)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:286)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:207)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
... 7 more
는 연결에 도움이 필요하십니까 Java API를 사용하는 Zabbix 서버.
또는 https를 사용하는 경우 443 –