zabbixApi4j-Graph prototype

Graph prototype: 这个类设计用于处理图形原型。

graphprototype.create: 创建新的图形原型
graphprototype.delete: 删除图形原型
graphprototype.exists: 查看图形原型是否存在
graphprototype.get: 检索图形原型
graphprototype.getobjects: 利用过滤器检索图形对象
graphprototype.update: 更新图形原型

image.png


GraphPrototypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;

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

import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;

/**
 * Created by Suguru Yajima on 2014/06/02.
 */
public class GraphPrototypeCreateTest extends ZabbixApiTestBase {

    public GraphPrototypeCreateTest() {
        super();
    }

    @Test
    public void testCreate1() throws Exception {
        GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
        GraphPrototypeCreateRequest.Params params = request.getParams();
        params.setName("Graphprototype create test");
        GraphItem gitem = new GraphItem();
        gitem.setColor("00AA00");
        gitem.setItemid(23730);
        params.addGraphItem(gitem);
        params.setHeight(140);
        params.setWidth(800);

        GraphPrototypeCreateResponse response = zabbixApi.graphPrototype().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getGraphids().get(0);
        assertNotNull(id);
    }

    private void deleteResult(Integer id) throws ZabbixApiException {

        GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
        request.addParam(id);

        GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
    }


}


GraphPrototypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;

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.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;

/**
 * Created by Suguru Yajima on 2014/06/02.
 */
public class GraphPrototypeDeleteTest extends ZabbixApiTestBase {

    public GraphPrototypeDeleteTest() {
        super();
    }

    @Test
    public void testDelete1() throws Exception {

        Integer targetId = createDummy();

        GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
        request.addParam(targetId);

        GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
        assertNotNull(response);

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

    private Integer createDummy() throws ZabbixApiException {

        GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
        GraphPrototypeCreateRequest.Params params = request.getParams();
        params.setName("Graphprototype delete test");
        GraphItem gitem  = new GraphItem();
        gitem.setColor("00AA00");
        gitem.setItemid(23730);
        params.addGraphItem(gitem);
        params.setHeight(140);
        params.setWidth(800);

        GraphPrototypeCreateResponse response  =zabbixApi.graphPrototype().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getGraphids().get(0);

        return id;
    }
}


GraphPrototypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.hamcrest.core.Is;
import org.junit.Test;

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

import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.ZabbixApiParamter;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
import com.zabbix4j.graphprototype.GraphPrototypeGetRequest;
import com.zabbix4j.graphprototype.GraphPrototypeGetResponse;
import com.zabbix4j.item.ItemObject;

/**
 * Created by Suguru Yajima on 2014/06/03.
 */
public class GraphPrototypeGetTest extends ZabbixApiTestBase {

    public GraphPrototypeGetTest() {
        super();
    }

    @Test
    public void testGet1() throws Exception {

        Integer tagetId = createDummy();

        GraphPrototypeGetRequest request = new GraphPrototypeGetRequest();
        GraphPrototypeGetRequest.Params params = request.getParams();
        params.addGraphId(tagetId);
        params.setSelectItems(ZabbixApiParamter.QUERY.extend.name());
        params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
        params.setSelectGroups(ZabbixApiParamter.QUERY.extend.name());
        params.setSelectDiscoveryRule(ZabbixApiParamter.QUERY.extend.name());
        params.setSelectGraphItems(ZabbixApiParamter.QUERY.extend.name());
        params.setSelectTemplates(ZabbixApiParamter.QUERY.extend.name());

        GraphPrototypeGetResponse response = zabbixApi.graphPrototype().get(request);
        assertNotNull(response);

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

        GraphPrototypeGetResponse.Result result = response.getResult().get(0);
        assertThat(tagetId, Is.is(result.getGraphid()));
        assertThat("Graphprototype get test", Is.is(result.getName()));
        List<ItemObject> items = result.getItems();
        assertNotNull(items);
        assertNotNull(result.getGitems());
        assertNotNull(result.getGroups());
        assertNotNull(result.getHosts());
    }

    private Integer createDummy() throws ZabbixApiException {

        GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
        GraphPrototypeCreateRequest.Params params = request.getParams();
        params.setName("Graphprototype get test");
        GraphItem gitem  = new GraphItem();
        gitem.setColor("00AA00");
        gitem.setItemid(23730);
        params.addGraphItem(gitem);
        params.setHeight(140);
        params.setWidth(800);

        GraphPrototypeCreateResponse response  =zabbixApi.graphPrototype().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getGraphids().get(0);

        return id;
    }

    private void deleteResult(Integer id) throws ZabbixApiException {

        GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
        request.addParam(id);

        GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
    }
}


GraphPrototypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graphprototype;

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.ZabbixApiException;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graphprototype.GraphPrototypeCreateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeCreateResponse;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteRequest;
import com.zabbix4j.graphprototype.GraphPrototypeDeleteResponse;
import com.zabbix4j.graphprototype.GraphPrototypeUpdateRequest;
import com.zabbix4j.graphprototype.GraphPrototypeUpdateResponse;

/**
 * Created by Suguru Yajima on 2014/06/02.
 */
public class GraphPrototypeUpdateTest  extends ZabbixApiTestBase {

    public GraphPrototypeUpdateTest() {
        super();
    }

    @Test
    public void testUpdate1() throws Exception {

        Integer expectedId = createDummy();

        GraphPrototypeUpdateRequest request = new GraphPrototypeUpdateRequest();
        GraphPrototypeUpdateRequest.Params params = request.getParams();
        params.setGraphid(expectedId);
        params.setName("Grpahprototype update success");
        params.setWidth(100);
        params.setHeight(800);

        GraphPrototypeUpdateResponse response = zabbixApi.graphPrototype().update(request);
        assertNotNull(response);

        deleteResult(expectedId);

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

        Integer actualId = response.getResult().getGraphids().get(0);
        assertThat(expectedId, is(expectedId));
    }

    private Integer createDummy() throws ZabbixApiException {

        GraphPrototypeCreateRequest request = new GraphPrototypeCreateRequest();
        GraphPrototypeCreateRequest.Params params = request.getParams();
        params.setName("Graphprototype update test");
        GraphItem gitem  = new GraphItem();
        gitem.setColor("00AA00");
        gitem.setItemid(23730);
        params.addGraphItem(gitem);
        params.setHeight(140);
        params.setWidth(800);

        GraphPrototypeCreateResponse response  =zabbixApi.graphPrototype().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getGraphids().get(0);

        return id;
    }

    private void deleteResult(Integer id) throws ZabbixApiException {

        GraphPrototypeDeleteRequest request = new GraphPrototypeDeleteRequest();
        request.addParam(id);

        GraphPrototypeDeleteResponse response = zabbixApi.graphPrototype().delete(request);
    }
}

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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,473评论 19 139
  • spring mvc 工作机制(原理): DispatcherServlet主要用作职责调度工作,本身主要用于控制...
    java大湿兄阅读 5,876评论 5 24
  • 有关“试卷检查存在的问题”的说明 对于《大学语文》试卷检查中提出的“存在的问题”,本人复查之后,对所存在问题及补正...
    步仁章阅读 3,764评论 0 2
  • 手机里安装简书 不是一天两天了 在这里读过的文章 不是一篇两篇了 也许生活就是需要一些尖锐的刺激 你才真的可以打开...
    吕燕阅读 5,822评论 45 29
  • 离开你的第一次旅行,实现了沙漠之旅,徒步12公里,装备齐全,善始善终。 遇到了有缘又有趣的伙伴。 超级热心的阳光小...
    渺小的我有大大的梦阅读 2,224评论 0 3