zabbixApi4j-Item prototype

Item prototype

itemprototype.create: 創(chuàng)建新項(xiàng)目原型
itemprototype.delete: 刪除項(xiàng)目原型
itemprototype.exists: 檢查項(xiàng)目原型是否存在
itemprototype.get: 檢索項(xiàng)目原型
itemprototype.isreadable: 檢查項(xiàng)目原型是否是可讀的
itemprototype.iswritable: 檢查項(xiàng)目原型是否是可寫的
itemprototype.update: 更新項(xiàng)目原型

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末鬼吵,一起剝皮案震驚了整個濱河市励幼,隨后出現(xiàn)的幾起案子熙卡,更是在濱河造成了極大的恐慌,老刑警劉巖竹勉,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異娄琉,居然都是意外死亡次乓,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進(jìn)店門孽水,熙熙樓的掌柜王于貴愁眉苦臉地迎上來票腰,“玉大人,你說我怎么就攤上這事女气⌒游浚” “怎么了?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵炼鞠,是天一觀的道長鼓蜒。 經(jīng)常有香客問我腿准,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任盗尸,我火速辦了婚禮,結(jié)果婚禮上凯傲,老公的妹妹穿的比我還像新娘搪泳。我一直安慰自己,他們只是感情好姿现,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布肠仪。 她就那樣靜靜地躺著,像睡著了一般备典。 火紅的嫁衣襯著肌膚如雪异旧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天提佣,我揣著相機(jī)與錄音吮蛹,去河邊找鬼荤崇。 笑死,一個胖子當(dāng)著我的面吹牛潮针,可吹牛的內(nèi)容都是我干的术荤。 我是一名探鬼主播,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼每篷,長吁一口氣:“原來是場噩夢啊……” “哼瓣戚!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起焦读,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤子库,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后矗晃,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體仑嗅,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年喧兄,在試婚紗的時候發(fā)現(xiàn)自己被綠了无畔。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡吠冤,死狀恐怖浑彰,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情拯辙,我是刑警寧澤郭变,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站涯保,受9級特大地震影響诉濒,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜夕春,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一未荒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧及志,春花似錦片排、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至倚搬,卻和暖如春冶共,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工捅僵, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留家卖,地道東北人。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓庙楚,卻偏偏與公主長得像篡九,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子醋奠,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn)伊佃,斷路器窜司,智...
    卡卡羅2017閱讀 134,656評論 18 139
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,116評論 25 707
  • 記得之前看過一段非常喜歡的情話: 我想和你去看世間所有的美景 看長城 看鐵塔 江河湖海 看日月星辰 我和你站在鏡子...
    補(bǔ)釘閱讀 161評論 0 0
  • 陳喬恩又雙叒叕要當(dāng)伴娘?航揉!“七朵花”趙小僑9月辦婚禮邀請陳喬恩當(dāng)伴娘塞祈。繼183club合體之后,七朵花也即將合體啦...
    潮流一起說閱讀 505評論 0 0
  • 馬上就到春節(jié)了帅涂,就說說我們家鄉(xiāng)的過年習(xí)俗吧议薪! 春節(jié)在我們這叫“過年”,貌似應(yīng)該是俗稱吧媳友!全國各地都這么叫吧斯议,...
    梁木純閱讀 181評論 2 1