Host prototype
hostprototype.create: 创建新主机原型
hostprototype.delete: 删除主机原型
hostprototype.get: 检索主机原型
hostprototype.isreadable: 检查主机原型是否是可读的
hostprototype.iswritable: 检查主机原型是否是可写的
hostprototype.update: 更新主机原型
HostPrototypeCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.hostprototype;
import org.junit.Test;
import com.zabbix4j.hostprototype.GroupLinkObject;
import com.zabbix4j.hostprototype.GroupPrototypeObject;
import com.zabbix4j.hostprototype.HostPrototypeCreateRequest;
import com.zabbix4j.hostprototype.HostPrototypeCreateResponse;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import static org.junit.Assert.assertNotNull;
/**
* Created by Suguru Yajima on 2014/06/05.
*/
public class HostPrototypeCreateTest extends ZabbixApiTestBase {
private final int TEST_GROUP_ID = 20;
public HostPrototypeCreateTest() {
super();
}
@Test
public void testCreate1() throws Exception {
ZabbixApiTestDummyLLDRule dummyLLD = new ZabbixApiTestDummyLLDRule(zabbixApi);
Integer lldRuleID = dummyLLD.createLLDRule();
try {
HostPrototypeCreateRequest request = new HostPrototypeCreateRequest();
HostPrototypeCreateRequest.Params params = request.getParams();
params.setRuleid(lldRuleID);
GroupLinkObject linkObj = new GroupLinkObject();
linkObj.setGroupid(TEST_GROUP_ID);
params.addGroupLink(linkObj);
GroupPrototypeObject typeObj = new GroupPrototypeObject();
typeObj.setName("{#HV.NAME}");
params.addGroupPrototype(typeObj);
params.setHost("{#HV.NAME}");
HostPrototypeCreateResponse response = zabbixApi.hostPrototype().create(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getHostids().get(0);
assertNotNull(actualId);
} finally {
dummyLLD.deleteLLDRule(lldRuleID);
}
}
}
HostPrototypeDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.hostprototype;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.hostprototype.HostPrototypeDeleteRequest;
import com.zabbix4j.hostprototype.HostPrototypeDeleteResponse;
/**
* @author Suguru Yajima
*/
public class HostPrototypeDeleteTest extends ZabbixApiTestBase {
public HostPrototypeDeleteTest() {
super();
}
@Test
public void testDelete1() throws Exception {
ZabbixApiTestDummyHostPrototype dummy = new ZabbixApiTestDummyHostPrototype(zabbixApi);
try {
Integer targetId = dummy.createHost();
HostPrototypeDeleteRequest request = new HostPrototypeDeleteRequest();
request.addHostId(targetId);
HostPrototypeDeleteResponse response = zabbixApi.hostPrototype().delete(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
} finally {
}
}
}
HostPrototypeUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.hostprototype;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.hamcrest.core.Is;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.hostprototype.GroupPrototypeObject;
import com.zabbix4j.hostprototype.HostPrototypeUpdateRequest;
import com.zabbix4j.hostprototype.HostPrototypeUpdateResponse;
/**
* @author Suguru Yajima
*/
public class HostPrototypeUpdateTest extends ZabbixApiTestBase{
public HostPrototypeUpdateTest() {
super();
}
@Test
public void testTest1() throws Exception {
Integer targetId = null;
ZabbixApiTestDummyHostPrototype dummy = new ZabbixApiTestDummyHostPrototype(zabbixApi);
try {
targetId = dummy.createHost();
HostPrototypeUpdateRequest request = new HostPrototypeUpdateRequest();
HostPrototypeUpdateRequest.Params params = request.getParams();
params.setHostid(targetId);
params.setHost("host.prototype.update");
params.setName("host prototype update");
GroupPrototypeObject typeObj = new GroupPrototypeObject();
typeObj.setName("host prototype update");
params.addGroupPrototype(typeObj);
params.setHost("192.168.0.1");
HostPrototypeUpdateResponse response = zabbixApi.hostPrototype().update(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getHostids().get(0);
assertThat(targetId, Is.is(actualId));
} catch (Exception e) {
e.printStackTrace();
} finally {
dummy.deleteHostPrototype(targetId);
fail();
}
}
}
ZabbixApiTestDummyHostPrototype
package cn.com.yeexun.testzabbix.zabbix4j.example.hostprototype;
import java.util.Random;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.hostprototype.GroupLinkObject;
import com.zabbix4j.hostprototype.GroupPrototypeObject;
import com.zabbix4j.hostprototype.HostPrototypeCreateRequest;
import com.zabbix4j.hostprototype.HostPrototypeCreateResponse;
import com.zabbix4j.hostprototype.HostPrototypeDeleteRequest;
import com.zabbix4j.hostprototype.HostPrototypeDeleteResponse;
/**
* @author Suguru Yajima
*/
public class ZabbixApiTestDummyHostPrototype extends ZabbixApiTestDummyMethodBase {
private final int TEST_GROUP_ID = 20;
private ZabbixApiTestBase dummyLLD;
private Integer lldRuleID = 23796;
public ZabbixApiTestDummyHostPrototype(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer createHost() throws ZabbixApiException {
try {
HostPrototypeCreateRequest request = new HostPrototypeCreateRequest();
HostPrototypeCreateRequest.Params params = request.getParams();
params.setRuleid(lldRuleID);
GroupLinkObject linkObj = new GroupLinkObject();
linkObj.setGroupid(TEST_GROUP_ID);
params.addGroupLink(linkObj);
GroupPrototypeObject typeObj = new GroupPrototypeObject();
typeObj.setName("host prototype name" + new Random().nextInt());
params.addGroupPrototype(typeObj);
params.setHost("{#HV.NAME}");
HostPrototypeCreateResponse response = zabbixApi.hostPrototype().create(request);
Integer actualId = response.getResult().getHostids().get(0);
return actualId;
} finally {
}
}
public void deleteHostPrototype(Integer id) throws ZabbixApiException {
if (id == null) {
return;
}
HostPrototypeDeleteRequest request = new HostPrototypeDeleteRequest();
request.addHostId(id);
HostPrototypeDeleteResponse response = zabbixApi.hostPrototype().delete(request);
}
}
网友评论