User group
usergroup.create: 创建新用户组
usergroup.delete: 删除用户组
usergroup.exists: 检查用户组是否存在
usergroup.get: 检索用户组
usergroup.getobjects: 通过过滤器检索用户组
usergroup.isreadable: 检查用户组是否可读
usergroup.iswritable: 检查用户组是否可写
usergroup.massadd: 向用户组添加权限和用户
usergroup.massupdate: 同时更新多个用户组
usergroup.update: 更新用户组
UserGroupCreateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.usergroup;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.usergroup.UserGroupCreateRequest;
import com.zabbix4j.usergroup.UserGroupCreateResponse;
/**
* Created by Suguru Yajima on 2014/05/14.
*/
public class UserGroupCreateTest extends ZabbixApiTestBase {
public UserGroupCreateTest() {
super();
}
@Test
public void testCreate1() throws Exception {
UserGroupCreateRequest request = new UserGroupCreateRequest();
UserGroupCreateRequest.Params params = request.getParams();
params.setName("usergroup create test");
params.addUserId(1);
UserGroupCreateResponse response = zabbixApi.usergroup().create(request);
assertNotNull(response);
Integer groupId = response.getResult().getUsrgrpids().get(0);
assertNotNull(groupId);
}
}
UserGroupDeleteTest
package cn.com.yeexun.testzabbix.zabbix4j.example.usergroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.usergroup.UserGroupCreateRequest;
import com.zabbix4j.usergroup.UserGroupCreateResponse;
import com.zabbix4j.usergroup.UserGroupDeleteRequest;
import com.zabbix4j.usergroup.UserGroupDeleteResponse;
/**
* Created by Suguru Yajima on 2014/05/15.
*/
public class UserGroupDeleteTest extends ZabbixApiTestBase {
public UserGroupDeleteTest() {
super();
}
@Test
public void testDelete1() throws Exception {
Integer expectedId = createDummyGroup();
UserGroupDeleteRequest request = new UserGroupDeleteRequest();
request.addParams(expectedId);
UserGroupDeleteResponse response = zabbixApi.usergroup().delete(request);
assertNotNull(response);
Integer actualId = response.getResult().getUsrgrpids().get(0);
assertEquals(expectedId, actualId);
}
private Integer createDummyGroup() throws ZabbixApiException {
UserGroupCreateRequest request = new UserGroupCreateRequest();
UserGroupCreateRequest.Params params = request.getParams();
params.setName("usergroup delete test");
params.addUserId(1);
UserGroupCreateResponse response = zabbixApi.usergroup().create(request);
Integer groupId = response.getResult().getUsrgrpids().get(0);
return groupId;
}
}
UserGroupGetTest
package cn.com.yeexun.testzabbix.zabbix4j.example.usergroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.usergroup.UserGroupCreateRequest;
import com.zabbix4j.usergroup.UserGroupCreateResponse;
import com.zabbix4j.usergroup.UserGroupDeleteRequest;
import com.zabbix4j.usergroup.UserGroupDeleteResponse;
import com.zabbix4j.usergroup.UserGroupGetRequest;
import com.zabbix4j.usergroup.UserGroupGetResponse;
/**
* Created by Suguru Yajima on 2014/05/16.
*/
public class UserGroupGetTest extends ZabbixApiTestBase {
public UserGroupGetTest() {
super();
}
@Test
public void testGet1() throws Exception {
Integer expectedId = createDummyGroup();
UserGroupGetRequest request = new UserGroupGetRequest();
UserGroupGetRequest.Params params = request.getParams();
params.addUsrgrpId(expectedId);
UserGroupGetResponse resposne = zabbixApi.usergroup().get(request);
assertNotNull(resposne);
deleteDummmyGroup(expectedId);
logger.debug(getGson().toJson(resposne));
UserGroupGetResponse.Result result = resposne.getResult().get(0);
assertEquals(expectedId, result.getUsrgrpid());
assertEquals("usergroup get test", result.getName());
}
private Integer createDummyGroup() throws ZabbixApiException {
UserGroupCreateRequest request = new UserGroupCreateRequest();
UserGroupCreateRequest.Params params = request.getParams();
params.setName("usergroup get test");
params.addUserId(1);
UserGroupCreateResponse response = zabbixApi.usergroup().create(request);
Integer groupId = response.getResult().getUsrgrpids().get(0);
return groupId;
}
private void deleteDummmyGroup(Integer id) throws ZabbixApiException {
UserGroupDeleteRequest request = new UserGroupDeleteRequest();
request.addParams(id);
UserGroupDeleteResponse response = zabbixApi.usergroup().delete(request);
}
}
UserGroupUpdateTest
package cn.com.yeexun.testzabbix.zabbix4j.example.usergroup;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import cn.com.yeexun.testzabbix.zabbix4j.common.ZabbixApiTestBase;
import com.zabbix4j.ZabbixApiException;
import com.zabbix4j.ZabbixApiParamter;
import com.zabbix4j.usergroup.UserGroupCreateRequest;
import com.zabbix4j.usergroup.UserGroupCreateResponse;
import com.zabbix4j.usergroup.UserGroupDeleteRequest;
import com.zabbix4j.usergroup.UserGroupDeleteResponse;
import com.zabbix4j.usergroup.UserGroupUpdateRequest;
import com.zabbix4j.usergroup.UserGroupUpdateResponse;
/**
* Created by Suguru Yajima on 2014/05/15.
*/
public class UserGroupUpdateTest extends ZabbixApiTestBase {
public UserGroupUpdateTest() {
super();
}
@Test
public void testUpdate1() throws Exception {
Integer id = createDummyGroup();
UserGroupUpdateRequest request = new UserGroupUpdateRequest();
UserGroupUpdateRequest.Params params = request.getParams();
params.setUsrgrpid(id);
params.setName("usergroup update success");
params.setDebug_mode(ZabbixApiParamter.DEBUG_MODE.ENABLE.value);
params.setGui_access(ZabbixApiParamter.GUI_ACCESS.DISABLE_ACCESS_FRONTEND.value);
UserGroupUpdateResponse response = zabbixApi.usergroup().update(request);
assertNotNull(response);
deleteDummmyGroup(id);
Integer actualId = response.getResult().getUsrgrpids().get(0);
assertEquals(id, actualId);
}
private Integer createDummyGroup() throws ZabbixApiException {
UserGroupCreateRequest request = new UserGroupCreateRequest();
UserGroupCreateRequest.Params params = request.getParams();
params.setName("usergroup update test");
params.addUserId(1);
UserGroupCreateResponse response = zabbixApi.usergroup().create(request);
Integer groupId = response.getResult().getUsrgrpids().get(0);
return groupId;
}
private void deleteDummmyGroup(Integer id) throws ZabbixApiException {
UserGroupDeleteRequest request = new UserGroupDeleteRequest();
request.addParams(id);
UserGroupDeleteResponse response = zabbixApi.usergroup().delete(request);
}
}