zabbixApi4j-Icon map

Icon map

iconmap.create: 创建新的图标映射
iconmap.delete: 删除图标映射
iconmap.get: 检索图标映射
iconmap.isreadable: 检查图标映射是否是可读的
iconmap.iswritable: 检查图标映射是否是可写的
iconmap.update: 更新图标映射

zabbixApi4j-Icon map_第1张图片
image.png


IconMapDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.iconmap;

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.iconmap.IconMapDeleteRequest;
import com.zabbix4j.iconmap.IconMapDeleteResponse;

/**
 * @author Suguru Yajima
 */
public class IconMapDeleteTest extends ZabbixApiTestBase {
    public IconMapDeleteTest() {
        super();
    }

    @Test
    public void testDelete1() throws Exception {

        ZabbixApiTestDummyIconMap dummy = new ZabbixApiTestDummyIconMap(zabbixApi);
        Integer targetId = dummy.create();
        IconMapDeleteRequest request = new IconMapDeleteRequest();
        request.addIconMapId(targetId);

        IconMapDeleteResponse response = zabbixApi.iconMap().delete(request);
        assertNotNull(response);

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

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


IconMapDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.iconmap;

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.iconmap.IconMapDeleteRequest;
import com.zabbix4j.iconmap.IconMapDeleteResponse;

/**
 * @author Suguru Yajima
 */
public class IconMapDeleteTest extends ZabbixApiTestBase {
    public IconMapDeleteTest() {
        super();
    }

    @Test
    public void testDelete1() throws Exception {

        ZabbixApiTestDummyIconMap dummy = new ZabbixApiTestDummyIconMap(zabbixApi);
        Integer targetId = dummy.create();
        IconMapDeleteRequest request = new IconMapDeleteRequest();
        request.addIconMapId(targetId);

        IconMapDeleteResponse response = zabbixApi.iconMap().delete(request);
        assertNotNull(response);

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

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


IconMapGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.iconmap;

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.iconmap.IconMapGetRequest;
import com.zabbix4j.iconmap.IconMapGetResponse;

/**
 * @author Suguru Yajima
 */
public class IconMapGetTest extends ZabbixApiTestBase {
    public IconMapGetTest() {
        super();
    }

    @Test
    public void testGet1() throws Exception {
        IconMapGetRequest request = new IconMapGetRequest();
        IconMapGetRequest.Params params = request.getParams();
        params.addIconMapId(1);

        params.setSelectMappings(ZabbixApiParamter.QUERY.extend.name());

        IconMapGetResponse response = zabbixApi.iconMap().get(request);
        assertNotNull(response);

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


ZabbixApiTestDummyIconMap
package cn.com.yeexun.testzabbix.zabbix4j.example.iconmap;

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

import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.iconmap.IconMapCreateRequest;
import com.zabbix4j.iconmap.IconMapCreateResponse;
import com.zabbix4j.iconmap.IconMappingObject;

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

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

    public Integer create() throws ZabbixApiException {
        IconMapCreateRequest request = new IconMapCreateRequest();
        IconMapCreateRequest.Params params = request.getParams();
        params.setName("Icon map Test");
        params.setDefault_iconid(2);

        IconMappingObject obj = new IconMappingObject();
        obj.setInventory_link(1);
        obj.setExpression("server");
        obj.setIconid(3);

        params.addMapping(obj);

        IconMapCreateResponse response = zabbixApi.iconMap().create(request);

        return response.getResult().getIconmapids().get(0);
    }
}

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