Web scenario
httptest.create: 創(chuàng)建新的Web場(chǎng)景
httptest.delete: 刪除web場(chǎng)景
httptest.get: 檢索web場(chǎng)景
httptest.isreadable: 檢查web場(chǎng)景是否可讀
httptest.iswritable: 檢查web場(chǎng)景是否可寫
httptest.update: 更新web場(chǎng)景
DummyWebScenario
package cn.com.yeexun.testzabbix.zabbix4j.example.webscenario;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.webscenario.HttpTestCreateRequest;
import com.zabbix4j.webscenario.HttpTestCreateResponse;
import com.zabbix4j.webscenario.HttpTestDeleteRequest;
import com.zabbix4j.webscenario.HttpTestDeleteResponse;
import com.zabbix4j.webscenario.ScenarioStepObject;
/**
* @author Suguru Yajima
*/
public class DummyWebScenario extends ZabbixApiTestDummyMethodBase {
public DummyWebScenario(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer create() throws ZabbixApiException {
final Integer hostId = 10084;
HttpTestCreateRequest request = new HttpTestCreateRequest();
HttpTestCreateRequest.Params params = request.getParams();
params.setName("httptest.create." + new Date().getTime());
params.setHostid(hostId);
ScenarioStepObject obj = new ScenarioStepObject();
obj.setName("Homepage");
obj.setUrl("http://mycompany.com");
obj.setStatus_codes("200");
obj.setNo(1);
params.addScenarioStepObject(obj);
HttpTestCreateResponse response = zabbixApi.webscenario().create(request);
Integer actualId = response.getResult().getHttptestids().get(0);
return actualId;
}
public void delete(Integer targetId) throws ZabbixApiException {
HttpTestDeleteRequest request = new HttpTestDeleteRequest();
request.addHttpTestId(targetId);
HttpTestDeleteResponse response = zabbixApi.webscenario().delete(request);
}
}
HttpTestUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.webscenario;
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.webscenario.HttpTestUpdateRequest;
import com.zabbix4j.webscenario.HttpTestUpdateRespose;
import com.zabbix4j.webscenario.WebScenarioObject;
/**
* @author Suguru Yajima
*/
public class HttpTestUpdateTest extends ZabbixApiTestBase {
public HttpTestUpdateTest() {
super();
}
@Test
public void testUpdate() throws Exception {
DummyWebScenario dummyWebScenario = new DummyWebScenario(zabbixApi);
Integer targetId = dummyWebScenario.create();
try {
HttpTestUpdateRequest request = new HttpTestUpdateRequest();
HttpTestUpdateRequest.Params params = request.getParams();
params.setHttptestid(targetId);
params.setStatus(WebScenarioObject.STATUS.DISABLED.value);
HttpTestUpdateRespose respose = zabbixApi.webscenario().update(request);
assertNotNull(respose);
Integer actualId = respose.getResult().getHttptestids().get(0);
assertThat(actualId, Is.is(targetId));
} finally {
dummyWebScenario.delete(targetId);
}
}
}
HttpTestCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.webscenario;
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.webscenario.HttpTestCreateRequest;
import com.zabbix4j.webscenario.HttpTestCreateResponse;
import com.zabbix4j.webscenario.ScenarioStepObject;
/**
* @author Suguru Yajima
*/
public class HttpTestCreateTest extends ZabbixApiTestBase{
public HttpTestCreateTest() {
super();
}
@Test
public void testCreate() throws Exception {
final Integer hostId = 10084;
HttpTestCreateRequest request = new HttpTestCreateRequest();
HttpTestCreateRequest.Params params = request.getParams();
params.setName("httptest.create." + new Date().getTime());
params.setHostid(hostId);
ScenarioStepObject obj = new ScenarioStepObject();
obj.setName("Homepage");
obj.setUrl("http://mycompany.com");
obj.setStatus_codes("200");
obj.setNo(1);
params.addScenarioStepObject(obj);
HttpTestCreateResponse response = zabbixApi.webscenario().create(request);
assertNotNull(response);
Integer actualId = response.getResult().getHttptestids().get(0);
assertNotNull(actualId);
}
}
HttpTestDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.webscenario;
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.webscenario.HttpTestDeleteRequest;
import com.zabbix4j.webscenario.HttpTestDeleteResponse;
/**
* @author Suguru Yajima
*/
public class HttpTestDeleteTest extends ZabbixApiTestBase {
public HttpTestDeleteTest() {
super();
}
@Test
public void testDelete() throws Exception {
DummyWebScenario dummyWebScenario = new DummyWebScenario(zabbixApi);
Integer targetId = dummyWebScenario.create();
HttpTestDeleteRequest request = new HttpTestDeleteRequest();
request.addHttpTestId(targetId);
HttpTestDeleteResponse response = zabbixApi.webscenario().delete(request);
assertNotNull(response);
Integer actualId = response.getResult().getHttptestids().get(0);
assertThat(actualId, Is.is(targetId));
}
}
HttpTestGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.webscenario;
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.webscenario.HttpTestGetRequest;
import com.zabbix4j.webscenario.HttpTestGetResponse;
/**
* @author Suguru Yajima
*/
public class HttpTestGetTest extends ZabbixApiTestBase {
public HttpTestGetTest() {
super();
}
@Test
public void testGet() throws Exception {
DummyWebScenario dummyWebScenario = new DummyWebScenario(zabbixApi);
Integer targetId = dummyWebScenario.create();
try {
HttpTestGetRequest request = new HttpTestGetRequest();
HttpTestGetRequest.Params params = request.getParams();
params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
params.setSelectSteps(ZabbixApiParamter.QUERY.extend.name());
params.setExpandName(true);
params.setExpandStepName(true);
HttpTestGetResponse response = zabbixApi.webscenario().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
} finally {
dummyWebScenario.delete(targetId);
}
}
}