zabbix-api java_How to connect to zabbix server using java API

2017-11-01 10:15:40

0

I am trying to connect to a Zabbix server. I am able to access the Zabbix server running on port 10051 via the web browser, however, I am unable to connect to the same server using Java API. Following is the code that I am using to connect

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);

}

}

Classpath is:

Error while running this code is :

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

Need help in connecting to Zabbix server using Java API.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值