Screen item:该类用于与屏幕项目一起工作。
screenitem.create: 创建新的屏幕项
screenitem.delete: 删除屏幕项
screenitem.get: 检索屏幕项
screenitem.isreadable: 检查屏幕项是否是可读的
screenitem.iswritable: 检查屏幕项是否是可写的
screenitem.update: 更新屏幕项
screenitem.updatebyposition: 更新特定屏幕单元中的屏幕项目
DummyScreenItem
package cn.com.yeexun.testzabbix.zabbix4j.example.screenitem;
import static org.junit.Assert.assertNotNull;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.screenitem.ScreenItemCreateRequest;
import com.zabbix4j.screenitem.ScreenItemCreateResponse;
import com.zabbix4j.screenitem.ScreenItemDeleteRequest;
import com.zabbix4j.screenitem.ScreenItemDeleteResponse;
import com.zabbix4j.screenitem.ScreenItemObject;
/**
* @author Suguru Yajima
*/
public class DummyScreenItem extends ZabbixApiTestDummyMethodBase {
private final Integer screenId = 24;
private final Integer respurceId = 523;
public DummyScreenItem(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer create() throws ZabbixApiException {
ScreenItemCreateRequest request = new ScreenItemCreateRequest();
ScreenItemObject obj = new ScreenItemObject();
obj.setScreenid(screenId);
obj.setResourcetype(ScreenItemObject.RESOURCE_TYPE.GRAPH.value);
obj.setResourceid(respurceId);
obj.setRowspan(0);
obj.setColspan(0);
obj.setX(0);
obj.setY(1);
request.addScreenItem(obj);
ScreenItemCreateResponse response = zabbixApi.screenItem().create(request);
assertNotNull(response);
Integer actualId = response.getResult().getScreenitemids().get(0);
return actualId;
}
public void delete(Integer targetId) throws ZabbixApiException {
ScreenItemDeleteRequest request = new ScreenItemDeleteRequest();
request.addScreenItemId(targetId);
ScreenItemDeleteResponse response = zabbixApi.screenItem().delete(request);
}
}
ScreenItemCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screenitem;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.screenitem.ScreenItemCreateRequest;
import com.zabbix4j.screenitem.ScreenItemCreateResponse;
import com.zabbix4j.screenitem.ScreenItemObject;
/**
* @author Suguru Yajima
*/
public class ScreenItemCreateTest extends ZabbixApiTestBase {
private final Integer screenId = 24;
private final Integer respurceId= 523;
public ScreenItemCreateTest() {
super();
}
@Test
public void testCreate() throws Exception {
ScreenItemCreateRequest request = new ScreenItemCreateRequest();
ScreenItemObject obj = new ScreenItemObject();
obj.setScreenid(screenId);
obj.setResourcetype(ScreenItemObject.RESOURCE_TYPE.GRAPH.value);
obj.setResourceid(respurceId);
obj.setRowspan(0);
obj.setColspan(0);
obj.setX(0);
obj.setY(0);
request.addScreenItem(obj);
ScreenItemCreateResponse response = zabbixApi.screenItem().create(request);
assertNotNull(response);
Integer actualId = response.getResult().getScreenitemids().get(0);
assertNotNull(actualId);
}
}
ScreenItemDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screenitem;
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.screenitem.ScreenItemDeleteRequest;
import com.zabbix4j.screenitem.ScreenItemDeleteResponse;
/**
* @author Suguru Yajima
*/
public class ScreenItemDeleteTest extends ZabbixApiTestBase {
public ScreenItemDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
DummyScreenItem dummyScreenItem = new DummyScreenItem(zabbixApi);
Integer targetId = dummyScreenItem.create();
ScreenItemDeleteRequest request = new ScreenItemDeleteRequest();
request.addScreenItemId(targetId);
ScreenItemDeleteResponse response = zabbixApi.screenItem().delete(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getScreenitemids().get(0);
assertThat(actualId, is(targetId));
}
}
ScreenItemGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screenitem;
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.screenitem.ScreenItemGetRequest;
import com.zabbix4j.screenitem.ScreenItemGetResponse;
/**
* @author Suguru Yajima
*/
public class ScreenItemGetTest extends ZabbixApiTestBase {
private final Integer scrrenId = 25;
public ScreenItemGetTest() {
super();
}
@Test
public void testGet() throws Exception {
ScreenItemGetRequest request = new ScreenItemGetRequest();
ScreenItemGetRequest.Params params = request.getParams();
params.addScreenId(scrrenId);
ScreenItemGetResponse response = zabbixApi.screenItem().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
int itemCount = response.getResult().size();
assertThat(itemCount, is(3));
}
}
ScreenItemUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.screenitem;
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.screenitem.ScreenItemObject;
import com.zabbix4j.screenitem.ScreenItemUpdateRequest;
import com.zabbix4j.screenitem.ScreenItemUpdateResponse;
/**
* @author Suguru Yajima
*/
public class ScreenItemUpdateTest extends ZabbixApiTestBase {
public ScreenItemUpdateTest() {
super();
}
@Test
public void testUpdate() throws Exception {
DummyScreenItem dummyScreenItem = new DummyScreenItem(zabbixApi);
Integer targetId = dummyScreenItem.create();
try {
ScreenItemUpdateRequest request = new ScreenItemUpdateRequest();
ScreenItemObject obj = new ScreenItemObject();
obj.setScreenitemid(targetId);
obj.setWidth(500);
obj.setHeight(500);
request.addScreenItem(obj);
ScreenItemUpdateResponse response = zabbixApi.screenItem().update(request);
assertNotNull(response);
Integer actualId = response.getResult().getScreenitemids().get(0);
assertThat(actualId, is(targetId));
} finally {
dummyScreenItem.delete(targetId);
}
}
}