Maintenance
maintenance.create: 创造新的维护s
maintenance.delete: 删除维护
maintenance.exists: 检查维护是否存在
maintenance.get: 检索维护
maintenance.update: 更新维护
DummyMaintenance
package cn.com.yeexun.testzabbix.zabbix4j.example.maintenance;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestDummyMethodBase;
import com.zabbix4j.ZabbixApi;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.maintenance.MaintenanceCreateRequest;
import com.zabbix4j.maintenance.MaintenanceCreateResponse;
import com.zabbix4j.maintenance.MaintenanceDeleteRequest;
import com.zabbix4j.maintenance.MaintenanceDeleteResponse;
import com.zabbix4j.maintenance.TimePeriodObject;
/**
* @author Suguru Yajima
*/
public class DummyMaintenance extends ZabbixApiTestDummyMethodBase {
public DummyMaintenance(ZabbixApi zabbixApi) {
super(zabbixApi);
}
public Integer create() throws ZabbixApiException, ParseException {
final Integer groupId = 23;
MaintenanceCreateRequest request = new MaintenanceCreateRequest();
MaintenanceCreateRequest.Params params = request.getParams();
params.setName("test.maintenance.create." + new Date().getTime());
Long since = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2014/01/01 00:00:00").getTime() / 1000;
params.setActive_since(since);
Long till = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2030/01/01 00:00:00").getTime() / 1000;
params.setActive_till(till);
params.addGroupId(groupId);
params.setDescription("test.maintenance.create");
TimePeriodObject obj = new TimePeriodObject();
obj.setTimeperiod_type(TimePeriodObject.TIMEPERIOD_TYPE.WEEKLY.value);
obj.setEvery(TimePeriodObject.WEEK_OF_THE_MONTH.FIRST_WEEK.value);
obj.setDayofweek(64);
obj.setStart_time(64800);
obj.setPeriod(3600);
params.addTimeperiodId(obj);
MaintenanceCreateResponse response = zabbixApi.maintenance().create(request);
Integer actualId = response.getResult().getMaintenanceids().get(0);
return actualId;
}
public void delete(Integer targetId) throws ZabbixApiException {
MaintenanceDeleteRequest request = new MaintenanceDeleteRequest();
request.addMaintenaceId(targetId);
MaintenanceDeleteResponse response = zabbixApi.maintenance().delete(request);
}
}
MaintenanceCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.maintenance;
import static org.junit.Assert.assertNotNull;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.maintenance.MaintenanceCreateRequest;
import com.zabbix4j.maintenance.MaintenanceCreateResponse;
import com.zabbix4j.maintenance.TimePeriodObject;
/**
* @author Suguru Yajima
*/
public class MaintenanceCreateTest extends ZabbixApiTestBase {
public MaintenanceCreateTest() {
super();
}
@Test
public void testCreate() throws Exception {
final Integer groupId = 23;
MaintenanceCreateRequest request = new MaintenanceCreateRequest();
MaintenanceCreateRequest.Params params = request.getParams();
params.setName("test.maintenance.create." + new Date().getTime());
Long since = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2014/01/01 00:00:00").getTime() / 1000;
params.setActive_since(since);
Long till = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2030/01/01 00:00:00").getTime() / 1000;
params.setActive_till(till);
params.addGroupId(23);
params.setDescription("test.maintenance.create");
TimePeriodObject obj = new TimePeriodObject();
obj.setTimeperiod_type(TimePeriodObject.TIMEPERIOD_TYPE.WEEKLY.value);
obj.setEvery(TimePeriodObject.WEEK_OF_THE_MONTH.FIRST_WEEK.value);
obj.setDayofweek(64);
obj.setStart_time(64800);
obj.setPeriod(3600);
params.addTimeperiodId(obj);
MaintenanceCreateResponse response = zabbixApi.maintenance().create(request);
assertNotNull(response);
Integer actualId = response.getResult().getMaintenanceids().get(0);
assertNotNull(actualId);
}
}
MaintenanceDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.maintenance;
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.maintenance.MaintenanceDeleteRequest;
import com.zabbix4j.maintenance.MaintenanceDeleteResponse;
/**
* @author Suguru Yajima
*/
public class MaintenanceDeleteTest extends ZabbixApiTestBase {
public MaintenanceDeleteTest() {
super();
}
@Test
public void testName() throws Exception {
DummyMaintenance dummyMaintenance = new DummyMaintenance(zabbixApi);
Integer targetId = dummyMaintenance.create();
MaintenanceDeleteRequest request = new MaintenanceDeleteRequest();
request.addMaintenaceId(targetId);
MaintenanceDeleteResponse response = zabbixApi.maintenance().delete(request);
assertNotNull(response);
Integer actualId = response.getResult().getMaintenanceids().get(0);
assertThat(targetId, is(actualId));
}
}
MaintenanceGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.maintenance;
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.maintenance.MaintenanceGetRequest;
import com.zabbix4j.maintenance.MaintenanceGetResponse;
/**
* @author Suguru Yajima
*/
public class MaintenanceGetTest extends ZabbixApiTestBase {
public MaintenanceGetTest() {
super();
}
@Test
public void testGet() throws Exception {
DummyMaintenance dummyMaintenance = new DummyMaintenance(zabbixApi);
Integer targetId = dummyMaintenance.create();
try {
MaintenanceGetRequest request = new MaintenanceGetRequest();
MaintenanceGetRequest.Params params = request.getParams();
params.addMaintenanceId(targetId);
params.setSelectHosts(ZabbixApiParamter.QUERY.extend.name());
params.setSelectGroups(ZabbixApiParamter.QUERY.extend.name());
params.setSelectTimeperiods(ZabbixApiParamter.QUERY.extend.name());
MaintenanceGetResponse response = zabbixApi.maintenance().get(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
MaintenanceGetResponse.Result obj = response.getResult().get(0);
assertNotNull(obj.getGroups());
assertNotNull(obj.getTimeperiods());
assertNotNull(obj.getActive_since());
assertNotNull(obj.getActive_till());
assertNotNull(obj.getActiveSinceDate());
assertNotNull(obj.getDescription());
assertNotNull(obj.getMaintenance_type());
} finally {
dummyMaintenance.delete(targetId);
}
}
}
MaintenanceUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.maintenance;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.maintenance.MaintenanceUpdateRequest;
import com.zabbix4j.maintenance.MaintenanceUpdateResponse;
import com.zabbix4j.maintenance.TimePeriodObject;
/**
* @author Suguru Yajima
*/
public class MaintenanceUpdateTest extends ZabbixApiTestBase {
public MaintenanceUpdateTest() {
super();
}
@Test
public void testUpdate() throws Exception {
final Integer groupId = 23;
DummyMaintenance dummyMaintenance = new DummyMaintenance(zabbixApi);
Integer targetId = dummyMaintenance.create();
try {
MaintenanceUpdateRequest request = new MaintenanceUpdateRequest();
MaintenanceUpdateRequest.Params params = request.getParams();
params.setMaintenanceid(targetId);
params.setName("test.maintenance.update." + new Date().getTime());
Long since = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2014/01/01 00:00:00").getTime() / 1000;
params.setActive_since(since);
Long till = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2030/01/01 00:00:00").getTime() / 1000;
params.setActive_till(till);
params.addGroupId(groupId);
params.setDescription("test.maintenance.update");
TimePeriodObject obj = new TimePeriodObject();
obj.setTimeperiod_type(TimePeriodObject.TIMEPERIOD_TYPE.WEEKLY.value);
obj.setEvery(TimePeriodObject.WEEK_OF_THE_MONTH.FIRST_WEEK.value);
obj.setDayofweek(64);
obj.setStart_time(64800);
obj.setPeriod(3600);
params.addTimePeriod(obj);
MaintenanceUpdateResponse response = zabbixApi.maintenance().update(request);
assertNotNull(response);
logger.debug(getGson().toJson(response));
Integer actualId = response.getResult().getMaintenanceids().get(0);
assertThat(actualId, is(targetId));
} finally {
dummyMaintenance.delete(targetId);
}
}
}