Item prototype
itemprototype.create: 创建新项目原型
itemprototype.delete: 删除项目原型
itemprototype.exists: 检查项目原型是否存在
itemprototype.get: 检索项目原型
itemprototype.isreadable: 检查项目原型是否是可读的
itemprototype.iswritable: 检查项目原型是否是可写的
itemprototype.update: 更新项目原型
DummyItemPrototype
package cn.com.yeexun.testzabbix.zabbix4j.example.itemprototype;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import cn.com.yeexun.testzabbix.zabbix4j.example.host.DummyHost;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.itemprototype.ItemPrototypeCreateRequest;
import com.zabbix4j.itemprototype.ItemPrototypeCreateResponse;
import com.zabbix4j.itemprototype.ItemPrototypeDeleteRequest;
import com.zabbix4j.itemprototype.ItemPrototypeDeleteResponse;
import com.zabbix4j.itemprototype.ItemPrototypeObject;
/**
* @author Suguru Yajima
*/
public class DummyItemPrototype extends ZabbixApiTestDummyMethodBase {
public DummyItemPrototype(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer createItemPrototype() throws ZabbixApiException {
Integer hostId = 10145;
// lld id = 23797
//applicationid = 564
Integer hostInterfaceId = new DummyHost(zabbixApi).getHostInterface(hostId);
ItemPrototypeCreateRequest request = new ItemPrototypeCreateRequest();
ItemPrototypeCreateRequest.Params params = request.getParams();
params.setName("test.dummy.itemprototype." + new Date().getTime());
params.setRuleid(23797);
params.addApplication(564);
params.setDelay(60);
params.setHostid(hostId);
//params.setKey_("vfs.fs.size[{#FSNAME},free]");
params.setKey_("hogehogehoge." + new Date().getTime());
params.setType(ItemPrototypeObject.ITEM_TYPE.SIMPLE_CHECK.value);
params.setValue_type(ItemPrototypeObject.VALUE_TYPE.NUMERIC_UNSIGNED.value);
params.setInterfaceid(hostInterfaceId);
ItemPrototypeCreateResponse response = zabbixApi.itemPrototype().create(request);
return response.getResult().getItemids().get(0);
}
public void delete(Integer id) throws ZabbixApiException {
ItemPrototypeDeleteRequest request = new ItemPrototypeDeleteRequest();
request.addItemPrototypeId(id);
ItemPrototypeDeleteResponse response = zabbixApi.itemPrototype().delete(request);
}
}
ItemPrototypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.itemprototype;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import cn.com.yeexun.testzabbix.zabbix4j.example.host.DummyHost;
import com.zabbix4j.itemprototype.ItemPrototypeCreateRequest;
import com.zabbix4j.itemprototype.ItemPrototypeCreateResponse;
import com.zabbix4j.itemprototype.ItemPrototypeObject;
/**
* @author Suguru Yajima
*/
public class ItemPrototypeCreateTest extends ZabbixApiTestBase {
public ItemPrototypeCreateTest() {
super();
}
@Test
public void testCreate1() throws Exception {
Integer hostId = 10145;
// lld id = 23797
//applicationid = 564
Integer hostInterfaceId = new DummyHost(zabbixApi).getHostInterface(hostId);
ItemPrototypeCreateRequest request = new ItemPrototypeCreateRequest();
ItemPrototypeCreateRequest.Params params = request.getParams();
params.setName("Free disk space on $1");
params.setRuleid(23797);
params.addApplication(564);
params.setDelay(60);
params.setHostid(hostId);
params.setKey_("vfs.fs.size[{#FSNAME},free]");
params.setType(ItemPrototypeObject.ITEM_TYPE.SIMPLE_CHECK.value);
params.setValue_type(ItemPrototypeObject.VALUE_TYPE.NUMERIC_UNSIGNED.value);
params.setInterfaceid(hostInterfaceId);
ItemPrototypeCreateResponse response = zabbixApi.itemPrototype().create(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getItemids().get(0);
assertNotNull(actualId);
}
}
ItemPrototypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.itemprototype;
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.itemprototype.ItemPrototypeDeleteRequest;
import com.zabbix4j.itemprototype.ItemPrototypeDeleteResponse;
/**
* @author Suguru Yajima
*/
public class ItemPrototypeDeleteTest extends ZabbixApiTestBase {
public ItemPrototypeDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
DummyItemPrototype dummyItemPrototype = new DummyItemPrototype(zabbixApi);
Integer targetId = dummyItemPrototype.createItemPrototype();
ItemPrototypeDeleteRequest request = new ItemPrototypeDeleteRequest();
request.addItemPrototypeId(targetId);
ItemPrototypeDeleteResponse response = zabbixApi.itemPrototype().delete(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getPrototypeids().get(0);
assertThat(targetId, is(actualId));
}
}
ItemPrototypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.itemprototype;
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.ZabbixApiParamter;
import com.zabbix4j.itemprototype.ItemPrototypeGetRequest;
import com.zabbix4j.itemprototype.ItemPrototypeGetResponse;
/**
* @author Suguru Yajima
*/
public class ItemPrototypeGetTest extends ZabbixApiTestBase {
public ItemPrototypeGetTest() {
super();
}
@Test
public void testGet1() throws Exception {
DummyItemPrototype dummyItemPrototype = new DummyItemPrototype(zabbixApi);
Integer targetId = dummyItemPrototype.createItemPrototype();
try {
ItemPrototypeGetRequest request = new ItemPrototypeGetRequest();
ItemPrototypeGetRequest.Params params = request.getParams();
params.addItemId(targetId);
params.setSelectDiscoveryRule(ZabbixApiParamter.QUERY.extend.name());
params.setSelectGraphs(ZabbixApiParamter.QUERY.extend.name());
params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
params.setSelectApplications(ZabbixApiParamter.QUERY.extend.name());
params.setSelectTriggers(ZabbixApiParamter.QUERY.extend.name());
ItemPrototypeGetResponse response = zabbixApi.itemPrototype().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().get(0).getItemid();
assertThat(targetId, is(actualId));
} finally {
dummyItemPrototype.delete(targetId);
}
}
}
ItemPrototypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.itemprototype;
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.itemprototype.ItemPrototypeUpdateRequest;
import com.zabbix4j.itemprototype.ItemPrototypeUpdateResponse;
/**
* @author Suguru Yajima
*/
public class ItemPrototypeUpdateTest extends ZabbixApiTestBase {
public ItemPrototypeUpdateTest() {
super();
}
@Test
public void testUpdate1() throws Exception {
DummyItemPrototype dummyItemPrototype = new DummyItemPrototype(zabbixApi);
Integer targetId = dummyItemPrototype.createItemPrototype();
try {
ItemPrototypeUpdateRequest request = new ItemPrototypeUpdateRequest();
ItemPrototypeUpdateRequest.Params params = request.getParams();
params.setItemid(targetId);
params.setName("item update");
params.setDelay(90);
ItemPrototypeUpdateResponse response = zabbixApi.itemPrototype().update(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getItemids().get(0);
assertThat(targetId, is(actualId));
} finally {
dummyItemPrototype.delete(targetId);
}
}
}