zabbixApi4j-Application

Application:

此类设计用于处理应用程序。

application.create: 创建新应用程序
application.delete: 删除应用程序
application.exists: 检查应用程序是否存在
application.get: 检索应用
application.massadd: 更新中的应用
application.update: 将项目添加到应用程序

image.png
zabbix4j-0.1.8只有如下方法
image.png
ApplicationCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;

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.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;

/**
 * Created by Suguru Yajima on 2014/05/22.
 */
public class ApplicationCreateTest extends ZabbixApiTestBase {

    public ApplicationCreateTest() {
        super();
    }

    @Test
    public void testCreate1() throws Exception {

        ApplicationCreateRequest request = new ApplicationCreateRequest();
        ApplicationCreateRequest.Params params = request.getParams();
        params.setName("Application crated");
        params.setHostid(10084);

        ApplicationCreateResponse response = zabbixApi.application().create(request);
        assertNotNull(response);

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

        delete(id);
    }

    private void delete(Integer id) throws ZabbixApiException {

        ApplicationDeleteRequest request = new ApplicationDeleteRequest();
        request.addParams(id);

        ApplicationDeleteResponse response = zabbixApi.application().delete(request);
    }
}


ApplicationDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;

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.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;

/**
 * Created by Suguru Yajima on 2014/05/23.
 */
public class ApplicationDeleteTest extends ZabbixApiTestBase {

    public ApplicationDeleteTest() {
        super();
    }

    @Test
    public void testDelete() throws Exception {

        Integer expect = createDummy();

        ApplicationDeleteRequest request = new ApplicationDeleteRequest();
        request.addParams(expect);

        ApplicationDeleteResponse response = zabbixApi.application().delete(request);
        assertNotNull(response);

        Integer actual = response.getResult().getApplicationids().get(0);
        assertEquals(expect, actual);
    }

    private Integer createDummy() throws ZabbixApiException {
        ApplicationCreateRequest request = new ApplicationCreateRequest();
        ApplicationCreateRequest.Params params = request.getParams();
        params.setName("Application before delete");
        params.setHostid(10084);

        ApplicationCreateResponse response = zabbixApi.application().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getApplicationids().get(0);
        return id;
    }
}


ApplicationGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;

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

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

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

import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
import com.zabbix4j.application.ApplicationGetRequest;
import com.zabbix4j.application.ApplicationGetResponse;

/**
 * Created by Suguru Yajima on 2014/05/24.
 */
public class ApplicationGetTest extends ZabbixApiTestBase {

    public ApplicationGetTest() {
        super();
    }

    @Test
    public void testGet() throws Exception {

        ArrayList<Integer> ids = new ArrayList<Integer>();
        ids.add(createDummy());
        ids.add(createDummy2());

        Integer hostId = 10084;
        ApplicationGetRequest request = new ApplicationGetRequest();
        ApplicationGetRequest.Params params = request.getParams();
        params.addHostId(hostId);

        ApplicationGetResponse response = zabbixApi.application().get(request);
        assertNotNull(response);

        deleteDummy(ids.get(0));
        deleteDummy(ids.get(1));

        List<ApplicationGetResponse.Result> resultList = response.getResult();
        for (int i = 0; i < resultList.size(); i++) {
            ApplicationGetResponse.Result result = resultList.get(i);

            assertNotNull(result);
            assertEquals(hostId, result.getHostid());
        }
    }

    private Integer createDummy() throws ZabbixApiException {
        ApplicationCreateRequest request = new ApplicationCreateRequest();
        ApplicationCreateRequest.Params params = request.getParams();
        params.setName("Application get test");
        params.setHostid(10084);

        ApplicationCreateResponse response = zabbixApi.application().create(request);

        Integer id = response.getResult().getApplicationids().get(0);
        return id;
    }

    private Integer createDummy2() throws ZabbixApiException {
        ApplicationCreateRequest request = new ApplicationCreateRequest();
        ApplicationCreateRequest.Params params = request.getParams();
        params.setName("Application get test2");
        params.setHostid(10084);

        ApplicationCreateResponse response = zabbixApi.application().create(request);

        Integer id = response.getResult().getApplicationids().get(0);
        return id;
    }

    private void deleteDummy(Integer id) throws ZabbixApiException {
        ApplicationDeleteRequest request = new ApplicationDeleteRequest();
        request.addParams(id);

        ApplicationDeleteResponse response = zabbixApi.application().delete(request);
    }
}


ApplicationUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.application;

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.application.ApplicationCreateRequest;
import com.zabbix4j.application.ApplicationCreateResponse;
import com.zabbix4j.application.ApplicationDeleteRequest;
import com.zabbix4j.application.ApplicationDeleteResponse;
import com.zabbix4j.application.ApplicationUpdateRequest;
import com.zabbix4j.application.ApplicationUpdateResponse;

/**
 * Created by Suguru Yajima on 2014/05/23.
 */
public class ApplicationUpdateTest extends ZabbixApiTestBase {

    public ApplicationUpdateTest() {
        super();
    }

    @Test
    public void testUpdte() throws Exception {

        Integer expected = createDummy();

        ApplicationUpdateRequest request = new ApplicationUpdateRequest();
        ApplicationUpdateRequest.Params params = request.getParams();
        params.setApplicationid(expected);
        params.setName("Applicaton updated");

        ApplicationUpdateResponse response = zabbixApi.application().update(request);
        assertNotNull(response);

        Integer actual = response.getResult().getApplicationids().get(0);

        delete(actual);

        assertEquals(expected, actual);
    }

    private Integer createDummy() throws ZabbixApiException {
        ApplicationCreateRequest request = new ApplicationCreateRequest();
        ApplicationCreateRequest.Params params = request.getParams();
        params.setName("Application before update");
        params.setHostid(10113);

        ApplicationCreateResponse response = zabbixApi.application().create(request);
        assertNotNull(response);

        Integer id = response.getResult().getApplicationids().get(0);
        return id;
    }

    private void delete(Integer id) throws ZabbixApiException {

        ApplicationDeleteRequest request = new ApplicationDeleteRequest();
        request.addParams(id);

        ApplicationDeleteResponse response = zabbixApi.application().delete(request);
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,920评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 35,084评论 18 399
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 179,890评论 25 708
  • 秦家的少爷秦临风,年及弱冠,人如其名,玉树临风。长身玉立,宽肩窄腰,谦逊的样子像极了初春时绽出绿芽儿的柳条。他一副...
    陌上南蔷阅读 1,271评论 0 1
  • 今年13岁,应该是简书里年纪最小的作者。 7样材料(基本家里都有) 1.手帐 2.剪刀 3.尺子 4.包书胶 5....
    橘子杂货店阅读 946评论 3 16

友情链接更多精彩内容