美文网首页
zabbixApi4j-Template screen

zabbixApi4j-Template screen

作者: 差不多先生_tl | 来源:发表于2018-01-11 15:47 被阅读5次

    Template screen

    templatescreen.copy: 复制模板屏幕
    templatescreen.create: 创建模板屏幕
    templatescreen.delete: 删除模板屏幕
    templatescreen.exists: 检查模板屏幕是否存在
    templatescreen.get: 检索模板屏幕
    templatescreen.isreadable: 检查模板屏幕是否是可读的
    templatescreen.iswritable: 检查模板屏幕是否是可写的
    templatescreen.update: 更新模板屏幕

    image.png

    DummyTemplateScreen
    package cn.com.yeexun.testzabbix.zabbix4j.example.templatescreen;
    
    import java.util.Date;
    
    import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
    
    import com.zabbix4j.ZabbixApi;
    import com.zabbix4j.ZabbixApiException;
    import com.zabbix4j.screenitem.ScreenItemObject;
    import com.zabbix4j.templatescreen.TemplateScreenCreateRequest;
    import com.zabbix4j.templatescreen.TemplateScreenCreateResponse;
    import com.zabbix4j.templatescreen.TemplateScreenDeleteRequest;
    import com.zabbix4j.templatescreen.TemplateScreenDeleteResponse;
    
    /**
     * @author Suguru Yajima
     */
    public class DummyTemplateScreen extends ZabbixApiTestDummyMethodBase {
        private final Integer templateId = 10166;
        private final Integer resourceId = 495;
    
        public DummyTemplateScreen(ZabbixApi zabbixApi) {
            super(zabbixApi);
        }
    
        public Integer create() throws ZabbixApiException {
            TemplateScreenCreateRequest request = new TemplateScreenCreateRequest();
            TemplateScreenCreateRequest.Params params = request.getParams();
            params.setName("test.templatescreen.create." + new Date().getTime());
            params.setTemplateid(templateId);
            params.setHsize(3);
            params.setVsize(2);
    
            ScreenItemObject obj = new ScreenItemObject();
            obj.setResourcetype(ScreenItemObject.RESOURCE_TYPE.GRAPH.value);
            obj.setResourceid(resourceId);
            obj.setRowspan(0);
            obj.setColspan(0);
            obj.setX(0);
            obj.setY(0);
            params.addScreenItem(obj);
    
            TemplateScreenCreateResponse response = zabbixApi.templateScreen().create(request);
    
            Integer actualId = response.getResult().getScreenids().get(0);
    
            return actualId;
        }
    
        public void delete(Integer targetId) throws ZabbixApiException {
            TemplateScreenDeleteRequest request = new TemplateScreenDeleteRequest();
            request.addTemplateScreenId(targetId);
    
            TemplateScreenDeleteResponse response = zabbixApi.templateScreen().delete(request);
        }
    }
    
    
    TemplateScreenCreateTest
    package cn.com.yeexun.testzabbix.zabbix4j.example.templatescreen;
    
    import static org.junit.Assert.assertNotNull;
    
    import java.util.Date;
    
    import org.junit.Test;
    
    import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
    
    import com.zabbix4j.screenitem.ScreenItemObject;
    import com.zabbix4j.templatescreen.TemplateScreenCreateRequest;
    import com.zabbix4j.templatescreen.TemplateScreenCreateResponse;
    
    /**
     * @author Suguru Yajima
     */
    public class TemplateScreenCreateTest extends ZabbixApiTestBase {
    
        private final Integer templateId = 10166;
        private final Integer resourceId = 495;
    
        public TemplateScreenCreateTest() {
            super();
        }
    
        @Test
        public void testCreate() throws Exception {
    
            TemplateScreenCreateRequest request = new TemplateScreenCreateRequest();
            TemplateScreenCreateRequest.Params params = request.getParams();
            params.setName("test.templatescreen.create." + new Date().getTime());
            params.setTemplateid(templateId);
            params.setHsize(3);
            params.setVsize(2);
    
            ScreenItemObject obj = new ScreenItemObject();
            obj.setResourcetype(ScreenItemObject.RESOURCE_TYPE.GRAPH.value);
            obj.setResourceid(resourceId);
            obj.setRowspan(0);
            obj.setColspan(0);
            obj.setX(0);
            obj.setY(0);
            params.addScreenItem(obj);
    
            TemplateScreenCreateResponse response = zabbixApi.templateScreen().create(request);
            assertNotNull(response);
    
            logger.debug(getGson().toJson(response));
    
            Integer actualId = response.getResult().getScreenids().get(0);
            assertNotNull(actualId);
        }
    }
    
    
    TemplateScreenDeleteTest
    package cn.com.yeexun.testzabbix.zabbix4j.example.templatescreen;
    
    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.templatescreen.TemplateScreenDeleteRequest;
    import com.zabbix4j.templatescreen.TemplateScreenDeleteResponse;
    
    /**
     * @author Suguru Yajima
     */
    public class TemplateScreenDeleteTest extends ZabbixApiTestBase {
    
        public TemplateScreenDeleteTest() {
            super();
        }
    
        @Test
        public void testDelete() throws Exception {
            DummyTemplateScreen dummyTemplateScreen = new DummyTemplateScreen(zabbixApi);
            Integer targetID = dummyTemplateScreen.create();
    
            TemplateScreenDeleteRequest request = new TemplateScreenDeleteRequest();
            request.addTemplateScreenId(targetID);
    
            TemplateScreenDeleteResponse response = zabbixApi.templateScreen().delete(request);
            assertNotNull(response);
    
            logger.debug(getGson().toJson(response));
    
            Integer actuald = response.getResult().getScreenids().get(0);
    
            assertThat(actuald, Is.is(targetID));
        }
    }
    
    
    TemplateScreenGetTest
    package cn.com.yeexun.testzabbix.zabbix4j.example.templatescreen;
    
    import static org.junit.Assert.assertNotNull;
    
    import org.junit.Test;
    
    import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
    
    import com.zabbix4j.ZabbixApiParamter;
    import com.zabbix4j.templatescreen.TemplateScreenGetRequest;
    import com.zabbix4j.templatescreen.TemplateScreenGetResponse;
    
    /**
     * @author Suguru Yajima
     */
    public class TemplateScreenGetTest extends ZabbixApiTestBase {
        public TemplateScreenGetTest() {
            super();
        }
    
        @Test
        public void testGet() throws Exception {
            TemplateScreenGetRequest request = new TemplateScreenGetRequest();
            TemplateScreenGetRequest.Params params = request.getParams();
            params.setSelectScreenItems(ZabbixApiParamter.QUERY.extend.name());
            params.setNoInheritance(false);
    
            TemplateScreenGetResponse response =zabbixApi.templateScreen().get(request);
            assertNotNull(response);
    
            logger.debug(getGson().toJson(response));
    
            TemplateScreenGetResponse.Result result = response.getResult().get(0);
            assertNotNull(response);
    
    
        }
    }
    
    
    TemplateScreenUpdateTest
    package cn.com.yeexun.testzabbix.zabbix4j.example.templatescreen;
    
    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.templatescreen.TemplateScreenUpdateRequest;
    import com.zabbix4j.templatescreen.TemplateScreenUpdateResponse;
    
    /**
     * @author Suguru Yajima
     */
    public class TemplateScreenUpdateTest extends ZabbixApiTestBase {
        public TemplateScreenUpdateTest() {
            super();
        }
    
        @Test
        public void testUpdate() throws Exception {
            DummyTemplateScreen dummyTemplateScreen = new DummyTemplateScreen(zabbixApi);
            Integer targetId = dummyTemplateScreen.create();
    
            try {
                TemplateScreenUpdateRequest request = new TemplateScreenUpdateRequest();
                TemplateScreenUpdateRequest.Params params = request.getParams();
                params.setScreenid(targetId);
                params.setName("test.tempaltescreen.update");
    
                TemplateScreenUpdateResponse response = zabbixApi.templateScreen().update(request);
                assertNotNull(response);
    
                logger.debug(getGson().toJson(response));
    
                Integer actialId = response.getResult().getScreenids().get(0);
                assertThat(actialId, Is.is(targetId));
    
            } finally {
                dummyTemplateScreen.delete(targetId);
            }
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:zabbixApi4j-Template screen

          本文链接:https://www.haomeiwen.com/subject/vxqtoxtx.html