zabbixApi4j-Trigger|zabbixApi4j-Trigger prototype
Trigger prototype
triggerprototype.create: 创建新触发器原型
triggerprototype.delete: 删除触发器原型
triggerprototype.get: 检索触发器原型
triggerprototype.update: 更新触发器原型
文章图片
image.png 【zabbixApi4j-Trigger|zabbixApi4j-Trigger prototype】
DummyTriggerPrototype
package cn.com.yeexun.testzabbix.zabbix4j.example.triggerprototype;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.triggerprototype.TriggerPrototypeCreateRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeCreateResponse;
import com.zabbix4j.triggerprototype.TriggerPrototypeDeleteRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeDeleteResponse;
import com.zabbix4j.triggerprototype.TriggerPrototypeObject;
/**
* @author Suguru Yajima
*/
public class DummyTriggerPrototype extends ZabbixApiTestDummyMethodBase {
public DummyTriggerPrototype(ZabbixApi zabbixApi) {
super(zabbixApi);
}public Integer create() throws ZabbixApiException {
TriggerPrototypeCreateRequest request = new TriggerPrototypeCreateRequest();
TriggerPrototypeObject obj = new TriggerPrototypeObject();
obj.setDescription("test Free disk space is less than 20% on volume {#FSNAME} " + new Date().getTime());
obj.setExpression("{Zabbix server:vfs.fs.size[{#FSNAME},pfree].last(0)}<20");
request.addTriggerPrototypeObject(obj);
TriggerPrototypeCreateResponse response = zabbixApi.triggerPrototype().create(request);
Integer actualId = response.getResult().getTriggerids().get(0);
return actualId;
}public void delete(Integer targetId) throws ZabbixApiException {TriggerPrototypeDeleteRequest request = new TriggerPrototypeDeleteRequest();
request.addTirggerPrototypeId(targetId);
TriggerPrototypeDeleteResponse response = zabbixApi.triggerPrototype().delete(request);
}
}
TriggerProrotypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.triggerprototype;
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.triggerprototype.TriggerPrototypeDeleteRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeDeleteResponse;
/**
* @author Suguru Yajima
*/
public class TriggerProrotypeDeleteTest extends ZabbixApiTestBase {
public TriggerProrotypeDeleteTest() {
super();
}@Test
public void testDelete() throws Exception {
DummyTriggerPrototype dummyTriggerPrototype = new DummyTriggerPrototype(zabbixApi);
Integer targetId = dummyTriggerPrototype.create();
TriggerPrototypeDeleteRequest request = new TriggerPrototypeDeleteRequest();
request.addTirggerPrototypeId(targetId);
TriggerPrototypeDeleteResponse response = zabbixApi.triggerPrototype().delete(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getTriggerids().get(0);
assertThat(actualId, Is.is(targetId));
}
}
TriggerPrototypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.triggerprototype;
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.triggerprototype.TriggerPrototypeCreateRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeCreateResponse;
import com.zabbix4j.triggerprototype.TriggerPrototypeObject;
/**
* @author Suguru Yajima
*/
public class TriggerPrototypeCreateTest extends ZabbixApiTestBase {
public TriggerPrototypeCreateTest() {
super();
}@Test
public void testCreate() throws Exception {
TriggerPrototypeCreateRequest request = new TriggerPrototypeCreateRequest();
TriggerPrototypeObject obj = new TriggerPrototypeObject();
obj.setDescription("Free disk space is less than 20% on volume {#FSNAME} " + new Date().getTime());
obj.setExpression("{Zabbix server:vfs.fs.size[{#FSNAME},pfree].last(0)}<20");
request.addTriggerPrototypeObject(obj);
TriggerPrototypeCreateResponse response = zabbixApi.triggerPrototype().create(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getTriggerids().get(0);
assertNotNull(actualId);
}
}
TriggerPrototypeGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.triggerprototype;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiParamter;
import com.zabbix4j.triggerprototype.TriggerPrototypeGetRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeGetResponse;
/**
* @author Suguru Yajima
*/
public class TriggerPrototypeGetTest extends ZabbixApiTestBase {
public TriggerPrototypeGetTest() {
super();
}@Test
public void testGet() throws Exception {
final Integer targetId = 13545;
TriggerPrototypeGetRequest request = new TriggerPrototypeGetRequest();
TriggerPrototypeGetRequest.Params params = request.getParams();
params.addTriggerId(targetId);
params.setSelectGroups(ZabbixApiParamter.QUERY.extend.name());
params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
params.setSelectDiscoveryRule(ZabbixApiParamter.QUERY.extend.name());
params.setSelectFunctions(ZabbixApiParamter.QUERY.extend.name());
params.setSelectItems(ZabbixApiParamter.QUERY.extend.name());
TriggerPrototypeGetResponse response = zabbixApi.triggerPrototype().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
}
}
TriggerPrototypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.triggerprototype;
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.triggerprototype.TriggerPrototypeObject;
import com.zabbix4j.triggerprototype.TriggerPrototypeUpdateRequest;
import com.zabbix4j.triggerprototype.TriggerPrototypeUpdateResponse;
/**
* @author Suguru Yajima
*/
public class TriggerPrototypeUpdateTest extends ZabbixApiTestBase {
public TriggerPrototypeUpdateTest() {
super();
}@Test
public void testUpdate() throws Exception {
DummyTriggerPrototype dummyTriggerPrototype = new DummyTriggerPrototype(zabbixApi);
Integer targetId = dummyTriggerPrototype.create();
try {
TriggerPrototypeUpdateRequest request = new TriggerPrototypeUpdateRequest();
TriggerPrototypeObject obj = new TriggerPrototypeObject();
obj.setTriggerid(targetId);
obj.setStatus(TriggerPrototypeObject.STATUS.DISABLED.value);
obj.setDescription("hogehogehoge");
request.addTriggerPrototypeObject(obj);
TriggerPrototypeUpdateResponse response = zabbixApi.triggerPrototype().update(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getTriggerids().get(0);
assertThat(actualId, Is.is(targetId));
} finally {
dummyTriggerPrototype.delete(targetId);
}
}
}
推荐阅读
- 关于|关于 SAP UI5 Context.prototype.delete 方法的输入参数 Group ID 的细节
- .Net设计模式之原型模式(Prototype)
- 一文彻底搞懂JavaScript中的prototype