zabbixApi4j-Media type

Media type: 这个类被设计为与媒体类型一起工作。

mediatype.create: 创建新媒体类型
mediatype.delete: 删除媒体类型
mediatype.get: 检索媒体类型
mediatype.update: 更新媒体类型

image.png


DummyMediaType
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;

import java.util.Date;

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

import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.mediatype.MediaTypeCreateRequest;
import com.zabbix4j.mediatype.MediaTypeCreateResponse;
import com.zabbix4j.mediatype.MediaTypeDeleteRequest;
import com.zabbix4j.mediatype.MediaTypeDeleteResponse;
import com.zabbix4j.mediatype.MediaTypeObject;

/**
 * @author Suguru Yajima
 */
public class DummyMediaType extends ZabbixApiTestDummyMethodBase {

    public DummyMediaType(ZabbixApi zabbixApi) {
        super(zabbixApi);
    }

    public Integer create() throws ZabbixApiException {

        MediaTypeCreateRequest request = new MediaTypeCreateRequest();

        MediaTypeObject obj = new MediaTypeObject();
        obj.setDescription("test.mediatype." + new Date());
        obj.setType(MediaTypeObject.MEDIA_TYPE.EMAIL.value);
        obj.setSmtp_server("rootmail@company.com");
        obj.setSmtp_helo("company.com");
        obj.setSmtp_email("zabbix@company.com");
        request.addMediaType(obj);

        MediaTypeCreateResponse response = zabbixApi.mediaType().create(request);

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

        return actualId;
    }

    public void delete(Integer targetId) throws ZabbixApiException {

        MediaTypeDeleteRequest request = new MediaTypeDeleteRequest();
        request.addMediaTypeId(targetId);

        MediaTypeDeleteResponse response = zabbixApi.mediaType().delete(request);
    }
}


MediaTypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;

import static org.junit.Assert.assertNotNull;

import java.util.Date;

import org.junit.Test;

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

import com.zabbix4j.mediatype.MediaTypeCreateRequest;
import com.zabbix4j.mediatype.MediaTypeCreateResponse;
import com.zabbix4j.mediatype.MediaTypeObject;

/**
 * @author Suguru Yajima
 */
public class MediaTypeCreateTest extends ZabbixApiTestBase {

    public MediaTypeCreateTest() {
        super();
    }

    @Test
    public void testCreate() throws Exception {
        MediaTypeCreateRequest request = new MediaTypeCreateRequest();

        MediaTypeObject obj = new MediaTypeObject();
        obj.setDescription("test.mediatype." + new Date());
        obj.setType(MediaTypeObject.MEDIA_TYPE.EMAIL.value);
        obj.setSmtp_server("rootmail@company.com");
        obj.setSmtp_helo("company.com");
        obj.setSmtp_email("zabbix@company.com");
        request.addMediaType(obj);

        MediaTypeCreateResponse response = zabbixApi.mediaType().create(request);
        assertNotNull(response);

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

        Integer actualId = response.getResult().getMediatypeids().get(0);
        assertNotNull(actualId);
    }
}


MediaTypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;

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.mediatype.MediaTypeDeleteRequest;
import com.zabbix4j.mediatype.MediaTypeDeleteResponse;

/**
 * @author Suguru Yajima
 */
public class MediaTypeDeleteTest extends ZabbixApiTestBase {

    public MediaTypeDeleteTest() {
        super();
    }

    @Test
    public void testDelete() throws Exception {
        DummyMediaType dummyMediaType = new DummyMediaType(zabbixApi);
        Integer targetId = dummyMediaType.create();

        MediaTypeDeleteRequest request = new MediaTypeDeleteRequest();
        request.addMediaTypeId(targetId);

        MediaTypeDeleteResponse response = zabbixApi.mediaType().delete(request);
        assertNotNull(response);

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

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


MediaTypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;

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.mediatype.MediaTypeGetRequest;
import com.zabbix4j.mediatype.MediaTypeGetResponse;

/**
 * @author Suguru Yajima
 */
public class MediaTypeGetTest extends ZabbixApiTestBase {
    public MediaTypeGetTest() {
        super();
    }

    @Test
    public void testGet() throws Exception {
        MediaTypeGetRequest request = new MediaTypeGetRequest();
        MediaTypeGetRequest.Params params = request.getParams();
        params.addMediaTypeId(1);
        params.addMediaTypeId(2);
        params.addMediaTypeId(3);
        params.setSelectUsers(ZabbixApiParamter.QUERY.extend.name());

        MediaTypeGetResponse response = zabbixApi.mediaType().get(request);
        assertNotNull(response);

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

        int actualCount = response.getResult().size();
        assertThat(actualCount, is(3));
    }
}


MediaTypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.mediatype;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

import java.util.Date;

import org.junit.Test;

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

import com.zabbix4j.mediatype.MediaTypeObject;
import com.zabbix4j.mediatype.MediaTypeUpdateRequest;
import com.zabbix4j.mediatype.MediaTypeUpdateResponse;

/**
 * @author Suguru Yajima
 */
public class MediaTypeUpdateTest extends ZabbixApiTestBase {
    public MediaTypeUpdateTest() {
        super();
    }

    @Test
    public void testUpdate() throws Exception {
        DummyMediaType dummyMediaType = new DummyMediaType(zabbixApi);
        Integer targetId = dummyMediaType.create();

        try {
            MediaTypeUpdateRequest request = new MediaTypeUpdateRequest();
            MediaTypeObject obj = new MediaTypeObject();
            obj.setMediatypeid(targetId);
            obj.setDescription("update" + new Date());
            obj.setSmtp_email("hoge@hoge.com");
            request.addMediaTypeObject(obj);

            MediaTypeUpdateResponse response = zabbixApi.mediaType().update(request);
            assertNotNull(response);

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

            Integer actualId = response.getResult().getMediatypeids().get(0);
            assertThat(actualId, is(targetId));

        } finally {
            dummyMediaType.delete(targetId);
        }
    }
}

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

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,084评论 19 139
  • 1、开启公众号开发者模式 公众平台的技术文档目的为了简明扼要的交代接口的使用,语句难免苦涩难懂,甚至对于不同的读者...
    good7758阅读 5,473评论 0 1
  • API定义规范 本规范设计基于如下使用场景: 请求频率不是非常高:如果产品的使用周期内请求频率非常高,建议使用双通...
    有涯逐无涯阅读 7,784评论 0 6
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,111评论 25 709
  • 有事做 我喜欢做自己喜欢的事情,艺术就是首选了,画画,手工,音乐,烹饪,语言,文学,心理学。 有钱花 作为一...
    一个会画画的文字控阅读 3,437评论 0 0

友情链接更多精彩内容