Graph prototype: 这个类设计用于处理图形原型。
graphprototype.create: 创建新的图形原型
graphprototype.delete: 删除图形原型
graphprototype.exists: 查看图形原型是否存在
graphprototype.get: 检索图形原型
graphprototype.getobjects: 利用过滤器检索图形对象
graphprototype.update: 更新图形原型
GraphPrototypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
/**
* Created by Suguru Yajima on 2014/06/02.
*/
public class GraphPrototypeCreateTest extends ZabbixApiTestBase {
public GraphPrototypeCreateTest() {
super();
}
@Test
public void testCreate1() throws Exception {
GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
GraphPrototypeCreateRequest.Params params = request.getParams();
params.setName("Graphprototype create test");
GraphItem gitem = new GraphItem();
gitem.setColor("00AA00");
gitem.setItemid(23730);
params.addGraphItem(gitem);
params.setHeight(140);
params.setWidth(800);
GraphPrototypeCreateResponse response = zabbixApi.graphPrototype().create(request);
assertNotNull(response);
Integer id = response.getResult().getGraphids().get(0);
assertNotNull(id);
}
private void deleteResult(Integer id) throws ZabbixApiException {
GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
request.addParam(id);
GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
}
}
GraphPrototypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import org.hamcrest.core.Is;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
/**
* Created by Suguru Yajima on 2014/06/02.
*/
public class GraphPrototypeDeleteTest extends ZabbixApiTestBase {
public GraphPrototypeDeleteTest() {
super();
}
@Test
public void testDelete1() throws Exception {
Integer targetId = createDummy();
GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
request.addParam(targetId);
GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
assertNotNull(response);
Integer actualId = response.getResult().getGraphids().get(0);
assertThat(targetId, Is.is(actualId));
}
private Integer createDummy() throws ZabbixApiException {
GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
GraphPrototypeCreateRequest.Params params = request.getParams();
params.setName("Graphprototype delete test");
GraphItem gitem = new GraphItem();
gitem.setColor("00AA00");
gitem.setItemid(23730);
params.addGraphItem(gitem);
params.setHeight(140);
params.setWidth(800);
GraphPrototypeCreateResponse response =zabbixApi.graphPrototype().create(request);
assertNotNull(response);
Integer id = response.getResult().getGraphids().get(0);
return id;
}
}
GraphPrototypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.hamcrest.core.Is;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.ZabbixApiParamter;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
import com.zabbix4j.graphprototype.GraphPrototypeGetRequest;
import com.zabbix4j.graphprototype.GraphPrototypeGetResponse;
import com.zabbix4j.item.ItemObject;
/**
* Created by Suguru Yajima on 2014/06/03.
*/
public class GraphPrototypeGetTest extends ZabbixApiTestBase {
public GraphPrototypeGetTest() {
super();
}
@Test
public void testGet1() throws Exception {
Integer tagetId = createDummy();
GraphPrototypeGetRequest request = new GraphPrototypeGetRequest();
GraphPrototypeGetRequest.Params params = request.getParams();
params.addGraphId(tagetId);
params.setSelectItems(ZabbixApiParamter.QUERY.extend.name());
params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
params.setSelectGroups(ZabbixApiParamter.QUERY.extend.name());
params.setSelectDiscoveryRule(ZabbixApiParamter.QUERY.extend.name());
params.setSelectGraphItems(ZabbixApiParamter.QUERY.extend.name());
params.setSelectTemplates(ZabbixApiParamter.QUERY.extend.name());
GraphPrototypeGetResponse response = zabbixApi.graphPrototype().get(request);
assertNotNull(response);
deleteResult(tagetId);
logger.debug(getGson().toJson(response));
GraphPrototypeGetResponse.Result result = response.getResult().get(0);
assertThat(tagetId, Is.is(result.getGraphid()));
assertThat("Graphprototype get test", Is.is(result.getName()));
List items = result.getItems();
assertNotNull(items);
assertNotNull(result.getGitems());
assertNotNull(result.getGroups());
assertNotNull(result.getHosts());
}
private Integer createDummy() throws ZabbixApiException {
GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
GraphPrototypeCreateRequest.Params params = request.getParams();
params.setName("Graphprototype get test");
GraphItem gitem = new GraphItem();
gitem.setColor("00AA00");
gitem.setItemid(23730);
params.addGraphItem(gitem);
params.setHeight(140);
params.setWidth(800);
GraphPrototypeCreateResponse response =zabbixApi.graphPrototype().create(request);
assertNotNull(response);
Integer id = response.getResult().getGraphids().get(0);
return id;
}
private void deleteResult(Integer id) throws ZabbixApiException {
GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
request.addParam(id);
GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
}
}
GraphPrototypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
import com.zabbix4j.graphprototype.GraphPrototypeUpdateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeUpdateResponse;
/**
* Created by Suguru Yajima on 2014/06/02.
*/
public class GraphPrototypeUpdateTest extends ZabbixApiTestBase {
public GraphPrototypeUpdateTest() {
super();
}
@Test
public void testUpdate1() throws Exception {
Integer expectedId = createDummy();
GraphPrototypeUpdateRequest request = new GraphPrototypeUpdateRequest();
GraphPrototypeUpdateRequest.Params params = request.getParams();
params.setGraphid(expectedId);
params.setName("Grpahprototype update success");
params.setWidth(100);
params.setHeight(800);
GraphPrototypeUpdateResponse response = zabbixApi.graphPrototype().update(request);
assertNotNull(response);
deleteResult(expectedId);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getGraphids().get(0);
assertThat(expectedId, is(expectedId));
}
private Integer createDummy() throws ZabbixApiException {
GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
GraphPrototypeCreateRequest.Params params = request.getParams();
params.setName("Graphprototype update test");
GraphItem gitem = new GraphItem();
gitem.setColor("00AA00");
gitem.setItemid(23730);
params.addGraphItem(gitem);
params.setHeight(140);
params.setWidth(800);
GraphPrototypeCreateResponse response =zabbixApi.graphPrototype().create(request);
assertNotNull(response);
Integer id = response.getResult().getGraphids().get(0);
return id;
}
private void deleteResult(Integer id) throws ZabbixApiException {
GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
request.addParam(id);
GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
}
}