zabbix-api

zabbix-api for java

License

License

GroupId

GroupId

io.github.hengyunabc
ArtifactId

ArtifactId

zabbix-api
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

zabbix-api
zabbix-api for java
Project URL

Project URL

https://github.com/hengyunabc/zabbix-api
Source Code Management

Source Code Management

https://github.com/hengyunabc/zabbix-api

Download zabbix-api

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.hengyunabc/zabbix-api/ -->
<dependency>
    <groupId>io.github.hengyunabc</groupId>
    <artifactId>zabbix-api</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.hengyunabc/zabbix-api/
implementation 'io.github.hengyunabc:zabbix-api:0.0.2'
// https://jarcasting.com/artifacts/io.github.hengyunabc/zabbix-api/
implementation ("io.github.hengyunabc:zabbix-api:0.0.2")
'io.github.hengyunabc:zabbix-api:jar:0.0.2'
<dependency org="io.github.hengyunabc" name="zabbix-api" rev="0.0.2">
  <artifact name="zabbix-api" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.hengyunabc', module='zabbix-api', version='0.0.2')
)
libraryDependencies += "io.github.hengyunabc" % "zabbix-api" % "0.0.2"
[io.github.hengyunabc/zabbix-api "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.alibaba : fastjson jar 1.1.39
org.apache.httpcomponents : httpclient jar 4.3.6
org.slf4j : slf4j-api jar 1.7.5

test (5)

Group / Artifact Type Version
org.slf4j : jcl-over-slf4j jar 1.7.5
org.slf4j : log4j-over-slf4j jar 1.7.5
ch.qos.logback : logback-core jar 1.0.13
ch.qos.logback : logback-classic jar 1.0.13
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

zabbix-api

zabbix-api for java

https://www.zabbix.com/wiki/doc/api

https://www.zabbix.com/documentation/2.4/manual/api/reference/user/login

Based on zabbix api version 2.4.

Zabbix api version 2.2 will throw a exception.

##Info API is simple, beacuse java can not process json like dynamic language.

You can build you own Request Object.

public interface ZabbixApi {

	public void init();

	public void destory();

	public String apiVersion();

	public JSONObject call(Request request);

	public boolean login(String user, String password);
}

##Example

		String url = "http://192.168.90.102/zabbix/api_jsonrpc.php";
		zabbixApi = new DefaultZabbixApi(url);
		zabbixApi.init();

		boolean login = zabbixApi.login("zabbix.dev", "goK0Loqua4Eipoe");
		System.err.println("login:" + login);

		String host = "192.168.66.29";
		JSONObject filter = new JSONObject();

		filter.put("host", new String[] { host });
		Request getRequest = RequestBuilder.newBuilder()
				.method("host.get").paramEntry("filter", filter)
				.build();
		JSONObject getResponse = zabbixApi.call(getRequest);
		System.err.println(getResponse);
		String hostid = getResponse.getJSONArray("result")
				.getJSONObject(0).getString("hostid");
		System.err.println(hostid);

You can set your own HttpClient.

		RequestConfig requestConfig = RequestConfig.custom()
				.setConnectTimeout(5 * 1000).setConnectionRequestTimeout(5 * 1000)
				.setSocketTimeout(5 * 1000).build();
		PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();

		CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager)
				.setDefaultRequestConfig(requestConfig).build();

		ZabbixApi zabbixApi = new DefaultZabbixApi(
				"http://localhost:10051/zabbix/api_jsonrpc.php", httpclient);
		zabbixApi.init();

		String apiVersion = zabbixApi.apiVersion();

		System.out.println("api version:" + apiVersion);

		zabbixApi.destory();

##Maven dependency

<dependency>
    <groupId>io.github.hengyunabc</groupId>
    <artifactId>zabbix-api</artifactId>
    <version>0.0.2</version>
</dependency>

##Links

https://github.com/hengyunabc/zabbix-sender

##Licence Apache License V2

Versions

Version
0.0.2
0.0.1