zabbixApi4j-Graph

Graph: 该类旨在与项目一起工作。

graph.create: 创建新的图形
graph.delete: 删除图
graph.exists: 检查图是否存在
graph.get: 检索图
graph.getobjects: 用滤波器检索图
graph.update: 更新图

zabbixApi4j-Graph_第1张图片
image.png
GraphCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graph;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;

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

import com.zabbix4j.graph.GraphCreateRequest;
import com.zabbix4j.graph.GraphCreateResponse;
import com.zabbix4j.graph.GraphItem;

/**
 * Created by Suguru Yajima on 2014/05/29.
 */
public class GraphCreateTest extends ZabbixApiTestBase {

    public GraphCreateTest() {
        super();
    }

    @Test
    public void testCreate1() throws Exception {
        GraphCreateRequest request = new GraphCreateRequest();
        GraphCreateRequest.Params params = request.getParams();
        params.setName("Graph Create Test");

        GraphItem gitem = new GraphItem();
        gitem.setItemid(23661);
        gitem.setColor("00AA00");
        params.addGraphItem(gitem);

        params.setHeight(800);
        params.setWidth(140);

        GraphCreateResponse response = zabbixApi.graph().create(request);
        assertNotNull(response);

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


GraphDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graph;

import static org.junit.Assert.assertEquals;
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.GraphCreateRequest;
import com.zabbix4j.graph.GraphCreateResponse;
import com.zabbix4j.graph.GraphDeleteRequest;
import com.zabbix4j.graph.GraphDeleteResponse;
import com.zabbix4j.graph.GraphItem;

/**
 * Created by Suguru Yajima on 2014/05/31.
 */
public class GraphDeleteTest extends ZabbixApiTestBase {

    public GraphDeleteTest() {
        super();
    }

    @Test
    public void testDelete1() throws Exception {

        Integer targetId = createDummyGraph();

        GraphDeleteRequest request = new GraphDeleteRequest();
        request.getParams().add(targetId);

        GraphDeleteResponse response = zabbixApi.graph().delete(request);
        assertNotNull(response);

        assertEquals(targetId, response.getResult().getGraphids().get(0));
    }

    private Integer createDummyGraph() throws ZabbixApiException {

        GraphCreateRequest request = new GraphCreateRequest();
        GraphCreateRequest.Params params = request.getParams();
        params.setName("Graph Update Test");

        GraphItem gitem = new GraphItem();
        gitem.setItemid(23661);
        gitem.setColor("00AA00");
        params.addGraphItem(gitem);

        params.setHeight(800);
        params.setWidth(140);

        GraphCreateResponse response = zabbixApi.graph().create(request);

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


GraphGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graph;

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.ZabbixApiParamter;
import com.zabbix4j.graph.GraphCreateRequest;
import com.zabbix4j.graph.GraphCreateResponse;
import com.zabbix4j.graph.GraphDeleteRequest;
import com.zabbix4j.graph.GraphDeleteResponse;
import com.zabbix4j.graph.GraphGetRequest;
import com.zabbix4j.graph.GraphGetResponse;
import com.zabbix4j.graph.GraphItem;

/**
 * Created by Suguru Yajima on 2014/05/31.
 */
public class GraphGetTest extends ZabbixApiTestBase {

    public GraphGetTest() {
        super();
    }

    @Test
    public void testGet1() throws Exception {

        Integer targetId = createDummyGraph();

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

        GraphGetResponse response = zabbixApi.graph().get(request);
        assertNotNull(response);

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

        deleteDummy(targetId);
    }

    private Integer createDummyGraph() throws ZabbixApiException {

        GraphCreateRequest request = new GraphCreateRequest();
        GraphCreateRequest.Params params = request.getParams();
        params.setName("Graph Delete Test");

        GraphItem gitem = new GraphItem();
        gitem.setItemid(23661);
        gitem.setColor("00AA00");
        params.addGraphItem(gitem);

        params.setHeight(800);
        params.setWidth(140);

        GraphCreateResponse response = zabbixApi.graph().create(request);

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

    private void deleteDummy(Integer id) throws ZabbixApiException {

        GraphDeleteRequest request = new GraphDeleteRequest();
        request.getParams().add(id);

        GraphDeleteResponse response = zabbixApi.graph().delete(request);
    }
}


GraphUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.graph;

import static org.junit.Assert.assertEquals;
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.GraphCreateRequest;
import com.zabbix4j.graph.GraphCreateResponse;
import com.zabbix4j.graph.GraphItem;
import com.zabbix4j.graph.GraphUpdateRequest;
import com.zabbix4j.graph.GraphUpdateResponse;

/**
 * Created by Suguru Yajima on 2014/05/31.
 */
public class GraphUpdateTest extends ZabbixApiTestBase {

    public GraphUpdateTest() {
        super();
    }

    @Test
    public void testUpdate1() throws Exception {

        Integer targetId = createDummyGraph();

        GraphUpdateRequest request = new GraphUpdateRequest();
        GraphUpdateRequest.Params params = request.getParams();
        params.setName("Graph Updated Test Success");
        params.setGraphid(targetId);

        GraphUpdateResponse response = zabbixApi.graph().update(request);
        assertNotNull(request);

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

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

        assertEquals(targetId, actualId);
    }

    private Integer createDummyGraph() throws ZabbixApiException {

        GraphCreateRequest request = new GraphCreateRequest();
        GraphCreateRequest.Params params = request.getParams();
        params.setName("Graph Update Test");

        GraphItem gitem = new GraphItem();
        gitem.setItemid(23661);
        gitem.setColor("00AA00");
        params.addGraphItem(gitem);

        params.setHeight(800);
        params.setWidth(140);

        GraphCreateResponse response = zabbixApi.graph().create(request);

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

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