zabbixApi4j-Map

Map

map.create: 创建新地图
map.delete: 删除地图
map.exists: 检查地图是否存在
map.get: 检索地图
map.getobjects: 通过过滤器检索地图
map.isreadable: 检查地图是否是可读的
map.iswritable: 检查地图是否是可写的
map.update: 更新地图

zabbixApi4j-Map_第1张图片
image.png


DummyMap
package cn.com.yeexun.testzabbix.zabbix4j.example.map;

import java.util.Date;

import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;

import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.map.MapCreateRequest;
import com.zabbix4j.map.MapCreateResponse;
import com.zabbix4j.map.MapDeleteRequest;
import com.zabbix4j.map.MapDeleteResponse;
import com.zabbix4j.map.MapElementObject;

/**
 * @author Suguru Yajima
 */
public class DummyMap extends ZabbixApiTestDummyMethodBase {

    public DummyMap(ZabbixApi zabbixApi) {
        super(zabbixApi);
    }

    public Integer create() throws ZabbixApiException {

        MapCreateRequest request = new MapCreateRequest();
        MapCreateRequest.Params params = request.getParams();

        params.setName("test.map.create." + new Date().getTime());
        params.setWidth(600);
        params.setHeight(600);

        MapElementObject obj = new MapElementObject();
        obj.setElementid(10146);
        obj.setSelementid(1);
        obj.setElementtype(MapElementObject.ELEMENT_TYPE.HOST.value);
        obj.setIconid_off(2);
        params.addMapElement(obj);

        MapCreateResponse response = zabbixApi.map().create(request);

        Integer actualId = response.getResult().getSysmapids().get(0);

        return actualId;
    }

    public void delete(Integer targetId) throws ZabbixApiException {

        MapDeleteRequest request = new MapDeleteRequest();
        request.addMapId(targetId);

        MapDeleteResponse response = zabbixApi.map().delete(request);

    }
}


MapCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.map;

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.map.MapCreateRequest;
import com.zabbix4j.map.MapCreateResponse;
import com.zabbix4j.map.MapElementObject;

/**
 * @author Suguru Yajima
 */
public class MapCreateTest extends ZabbixApiTestBase {

    public MapCreateTest() {
        super();
    }

    @Test
    public void testCreateSimpleMap() throws Exception {
        MapCreateRequest request = new MapCreateRequest();
        MapCreateRequest.Params params = request.getParams();

        params.setName("test.map.create." + new Date().getTime());
        params.setWidth(600);
        params.setHeight(600);

        MapCreateResponse response = zabbixApi.map().create(request);
        assertNotNull(response);

        logger.debug(getGson().toJson(response));

        Integer actualId = response.getResult().getSysmapids().get(0);
        assertNotNull(actualId);
    }

    @Test
    public void testCreateHostMap() throws Exception {

        MapCreateRequest request = new MapCreateRequest();
        MapCreateRequest.Params params = request.getParams();

        params.setName("test.map.create." + new Date().getTime());
        params.setWidth(600);
        params.setHeight(600);

        MapElementObject obj = new MapElementObject();
        obj.setElementid(10146);
        obj.setSelementid(1);
        obj.setElementtype(MapElementObject.ELEMENT_TYPE.HOST.value);
        obj.setIconid_off(2);
        params.addMapElement(obj);

        MapCreateResponse response = zabbixApi.map().create(request);
        assertNotNull(response);

        logger.debug(getGson().toJson(response));

        Integer actualId = response.getResult().getSysmapids().get(0);
        assertNotNull(actualId);
    }
}


MapDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.map;

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.map.MapDeleteRequest;
import com.zabbix4j.map.MapDeleteResponse;

/**
 * @author Suguru Yajima
 */
public class MapDeleteTest extends ZabbixApiTestBase {

    public MapDeleteTest() {
        super();
    }

    @Test
    public void testDelete() throws Exception {
        DummyMap dummyMap = new DummyMap(zabbixApi);
        Integer targetId = dummyMap.create();

        MapDeleteRequest request = new MapDeleteRequest();
        request.addMapId(targetId);

        MapDeleteResponse response = zabbixApi.map().delete(request);
        assertNotNull(response);

        logger.debug(getGson().toJson(response));

        Integer actualId = response.getResult().getSysmapids().get(0);
        assertThat(actualId, is(targetId));
    }
}


MapGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.map;

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.map.MapGetRequest;
import com.zabbix4j.map.MapGetResponse;

/**
 * @author Suguru Yajima
 */
public class MapGetTest extends ZabbixApiTestBase {

    public MapGetTest() {
        super();
    }

    @Test
    public void testGet() throws Exception {
        DummyMap dummyMap = new DummyMap(zabbixApi);
        Integer targetId = dummyMap.create();

        try {
            MapGetRequest request = new MapGetRequest();
            MapGetRequest.Params params = request.getParams();
            params.addSysMapId(targetId);
            params.setSelectIconMap(ZabbixApiParamter.QUERY.extend.name());
            params.setSelectLinks(ZabbixApiParamter.QUERY.extend.name());
            params.setSelectSelements(ZabbixApiParamter.QUERY.extend.name());
            params.setSelectUrls(ZabbixApiParamter.QUERY.extend.name());

            MapGetResponse response = zabbixApi.map().get(request);
            assertNotNull(response);

            logger.debug(getGson().toJson(response));

            MapGetResponse.Result result = response.getResult().get(0);
            assertThat(result.getSysmapid(), is(targetId));
        } finally {
            dummyMap.delete(targetId);
        }
    }
}


MapUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.map;

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.map.MapUpdateRequest;
import com.zabbix4j.map.MapUpdateResponse;

/**
 * @author Suguru Yajima
 */
public class MapUpdateTest extends ZabbixApiTestBase {

    public MapUpdateTest() {
        super();
    }

    @Test
    public void testUpdate() throws Exception {
        DummyMap dummyMap = new DummyMap(zabbixApi);
        Integer targetId = dummyMap.create();


        try {
            MapUpdateRequest request = new MapUpdateRequest();
            MapUpdateRequest.Params params = request.getParams();
            params.setSysmapid(targetId);
            params.setWidth(800);
            params.setHeight(800);

            MapUpdateResponse response = zabbixApi.map().update(request);
            assertNotNull(response);

            logger.debug(getGson().toJson(response));

            Integer actualId = response.getResult().getSysmapids().get(0);
            assertThat(actualId, is(targetId));

        } finally {
            dummyMap.delete(targetId);
        }
    }
}

你可能感兴趣的:(zabbixApi4j-Map)