zabbixApi4j-Item prototype

Item prototype

itemprototype.create: 创建新项目原型
itemprototype.delete: 删除项目原型
itemprototype.exists: 检查项目原型是否存在
itemprototype.get: 检索项目原型
itemprototype.isreadable: 检查项目原型是否是可读的
itemprototype.iswritable: 检查项目原型是否是可写的
itemprototype.update: 更新项目原型

image.png


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);
        }
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,242评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,351评论 25 709
  • 记得之前看过一段非常喜欢的情话: 我想和你去看世间所有的美景 看长城 看铁塔 江河湖海 看日月星辰 我和你站在镜子...
    补钉阅读 254评论 0 0
  • 陈乔恩又双叒叕要当伴娘?!“七朵花”赵小侨9月办婚礼邀请陈乔恩当伴娘。继183club合体之后,七朵花也即将合体啦...
    潮流一起说阅读 534评论 0 0
  • 马上就到春节了,就说说我们家乡的过年习俗吧! 春节在我们这叫“过年”,貌似应该是俗称吧!全国各地都这么叫吧,...
    梁木纯阅读 201评论 2 1