REM:
1. 启动设备处置任务接口支持指定处置对象类型参数
2. 启动处置任务接口支持处置IP/URL/域名
This commit is contained in:
HuangXin 2020-10-12 10:47:20 +08:00
parent 393f77e3a5
commit 6ea13baa86
6 changed files with 116 additions and 95 deletions

View File

@ -1,6 +1,7 @@
package com.dispose.ability;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType;
@ -17,6 +18,7 @@ public interface DisposeAbility {
/**
* Init device env.
*
* @param urlPath the url path
* @param username the username
* @param password the password
@ -26,14 +28,15 @@ public interface DisposeAbility {
/**
* Run dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
MulReturnType<ErrorCode, String> runDispose(String ip, DisposeCapacityType capType,
MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration);
@ -41,14 +44,14 @@ public interface DisposeAbility {
/**
* Stop dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
MulReturnType<ErrorCode, Long> stopDispose(String disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId);

View File

@ -3,6 +3,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility;
import com.dispose.common.CommonEnumHandler;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.DpTechAttackType;
import com.dispose.common.DpTechConfigValue;
import com.dispose.common.ErrorCode;
@ -55,6 +56,7 @@ public class DpTechAbilityImpl implements DisposeAbility {
/**
* Init device env.
*
* @param urlPath the url path
* @param username the username
* @param password the password
@ -96,44 +98,45 @@ public class DpTechAbilityImpl implements DisposeAbility {
/**
* Run dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
NetflowDirection nfDirection,
Integer attackType,
Long duration) {
ErrorCode err = ErrorCode.ERR_OK;
try {
log.debug("++++Begging DPTech Start Cleanup Task: {}, {}, {} ", ip, attackType, nfDirection);
log.debug("++++Begging DPTech Start Cleanup Task: {}, {}, {} ", disposeObject, attackType, nfDirection);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error DPTech don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
NtcRequestResultInfo ret = cleanTypePort.startAbnormalTaskForUMC(ip, attackType,
NtcRequestResultInfo ret = cleanTypePort.startAbnormalTaskForUMC(disposeObject, attackType,
nfDirection.getValue());
if (ret.getResultRetVal() != 0) {
err = ErrorCode.ERR_CALLDEVICE;
log.error("----Error DPTech Start Cleanup Task: {}, {}, {}, {}", ip, nfDirection,
log.error("----Error DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
ret.getResultInfo().getValue());
} else {
log.debug("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", ip, nfDirection,
log.debug("----Finish DPTech Start Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
ret.getResultInfo().getValue());
}
} catch (Exception ex) {
err = ErrorCode.ERR_SYSTEMEXCEPTION;
log.error("----Exception DPTech Start Cleanup Task: {}, {}, {}", ip, nfDirection,
log.error("----Exception DPTech Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType));
}
@ -143,15 +146,15 @@ public class DpTechAbilityImpl implements DisposeAbility {
/**
* Stop dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> stopDispose(String ip,
public MulReturnType<ErrorCode, Long> stopDispose(String disposeObject,
DisposeCapacityType capType,
NetflowDirection nfDirection,
Integer attackType,
@ -159,29 +162,29 @@ public class DpTechAbilityImpl implements DisposeAbility {
ErrorCode err = ErrorCode.ERR_OK;
try {
log.info("++++Begging DPTech Stop Cleanup Task: {}, {}, {} ", ip, attackType, nfDirection);
log.info("++++Begging DPTech Stop Cleanup Task: {}, {}, {} ", disposeObject, attackType, nfDirection);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error DPTech don't support dispose capacity type: {}", capType);
return new MulReturnType<>(ErrorCode.ERR_UNSUPPORT, null);
}
NtcRequestResultInfo ret = cleanTypePort.stopAbnormalTaskForUMC(ip, attackType,
NtcRequestResultInfo ret = cleanTypePort.stopAbnormalTaskForUMC(disposeObject, attackType,
nfDirection.getValue());
if (ret.getResultRetVal() != 0) {
err = ErrorCode.ERR_CALLDEVICE;
log.error("----Error DPTech Stop Cleanup Task: {}, {}, {}, {}", ip, nfDirection,
log.error("----Error DPTech Stop Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
ret.getResultInfo().getValue());
} else {
log.info("----Finish DPTech Stop Cleanup Task: {}, {}, {}, {}", ip, nfDirection,
log.info("----Finish DPTech Stop Cleanup Task: {}, {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType),
ret.getResultInfo().getValue());
}
} catch (Exception ex) {
err = ErrorCode.ERR_SYSTEMEXCEPTION;
log.error("----Exception DPTech Stop Cleanup Task: {}, {}, {}", ip, nfDirection,
log.error("----Exception DPTech Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection,
CommonEnumHandler.codeOf(DpTechAttackType.class, attackType));
}

View File

@ -2,6 +2,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType;
@ -53,20 +54,21 @@ public class HaoHanAbilityImpl implements DisposeAbility {
/**
* Run dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
try {
log.info("++++Begging Haohan Start Cleanup Task: {}", ip);
log.info("++++Begging Haohan Start Cleanup Task: {}", disposeObject);
if (capType != DisposeCapacityType.CLEANUP) {
log.error("----Error Haohan don't support dispose capacity type: {}", capType);
@ -78,24 +80,24 @@ public class HaoHanAbilityImpl implements DisposeAbility {
duration = -1L;
}
HaoHanStartCleanResp resp = restfulInterface.startClean(this.urlRootPath, ip,
HaoHanStartCleanResp resp = restfulInterface.startClean(this.urlRootPath, disposeObject,
Math.max(duration.intValue(), 0),
DISPOSE_PLATFORM_NAME);
if (resp == null) {
log.error("----Error Haohan start clean {} server return error", ip);
log.error("----Error Haohan start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
}
if (resp.getState() != ErrorCode.ERR_OK.getCode()) {
log.error("----Error Haohan start clean {} return error: {}, {}", ip, resp.getState(), resp.getMsg());
log.error("----Error Haohan start clean {} return error: {}, {}", disposeObject, resp.getState(), resp.getMsg());
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
}
log.debug("----Finish Haohan Start Cleanup Task: {}", ip);
log.debug("----Finish Haohan Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, String.valueOf(resp.getCleanTaskId()));
} catch (Exception ex) {
log.error("----Exception Haohan Start Cleanup Task: {}, {}, {}", ip, nfDirection, duration);
log.error("----Exception Haohan Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
@ -103,15 +105,15 @@ public class HaoHanAbilityImpl implements DisposeAbility {
/**
* Stop dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, Long> stopDispose(String disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId) {
@ -139,7 +141,7 @@ public class HaoHanAbilityImpl implements DisposeAbility {
log.debug("----Finish Haohan Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception Haohan Stop Cleanup Task: {}, {}, {}", ip, nfDirection, taskId);
log.error("----Exception Haohan Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}

View File

@ -36,11 +36,11 @@ import java.util.List;
public class PengXinAbilityImpl implements DisposeAbility {
/**
* The Protect ipv4.
* The Protect ip v 4.
*/
private final List<String> protectIpV4 = new ArrayList<>();
/**
* The Protect ipv6.
* The Protect ip v 6.
*/
private final List<String> protectIpV6 = new ArrayList<>();
@ -132,15 +132,16 @@ public class PengXinAbilityImpl implements DisposeAbility {
/**
* Run dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
@ -153,7 +154,7 @@ public class PengXinAbilityImpl implements DisposeAbility {
}
try {
log.info("++++Begging PengXin Start Cleanup Task: {}", ip);
log.info("++++Begging PengXin Start Cleanup Task: {}", disposeObject);
if (capType != DisposeCapacityType.BLACKHOOL) {
log.error("----Error PengXin don't support dispose capacity type: {}", capType);
@ -167,8 +168,8 @@ public class PengXinAbilityImpl implements DisposeAbility {
reqItems.add(PengXinStartTaskItem.builder()
.type(getPengXinTaskType(capType))
.disposeObject(ip)
.objectType(getPengXinObjectType(DisposeObjectType.IP))
.disposeObject(disposeObject)
.objectType(getPengXinObjectType(objectType))
.disposeTime(duration)
.taskReqId(String.valueOf(taskReqId++))
.build());
@ -183,14 +184,14 @@ public class PengXinAbilityImpl implements DisposeAbility {
}
if (rspInfo == null || rspInfo.getCode() != ErrorCode.ERR_OK.getHttpCode()) {
log.error("----Error PengXin start clean {} server return error", ip);
log.error("----Error PengXin start clean {} server return error", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null);
}
log.debug("----Finish PengXin Start Cleanup Task: {}", ip);
log.debug("----Finish PengXin Start Cleanup Task: {}", disposeObject);
return new MulReturnType<>(ErrorCode.ERR_OK, rspInfo.getMsgContent().getItems().get(0).getTaskId());
} catch (Exception ex) {
log.error("----Exception PengXin Start Cleanup Task: {}, {}, {}", ip, nfDirection, duration);
log.error("----Exception PengXin Start Cleanup Task: {}, {}, {}", disposeObject, nfDirection, duration);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}
@ -198,15 +199,15 @@ public class PengXinAbilityImpl implements DisposeAbility {
/**
* Stop dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, Long> stopDispose(String disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId) {
@ -246,7 +247,7 @@ public class PengXinAbilityImpl implements DisposeAbility {
log.debug("----Finish PengXin Stop Cleanup Task: {}", taskId);
return new MulReturnType<>(ErrorCode.ERR_OK, null);
} catch (Exception ex) {
log.error("----Exception PengXin Stop Cleanup Task: {}, {}, {}", ip, nfDirection, taskId);
log.error("----Exception PengXin Stop Cleanup Task: {}, {}, {}", disposeObject, nfDirection, taskId);
return new MulReturnType<>(ErrorCode.ERR_SYSTEMEXCEPTION, null);
}
}

View File

@ -2,6 +2,7 @@ package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType;
@ -22,6 +23,7 @@ public class VirtualAbilityImpl implements DisposeAbility {
/**
* Init device env.
*
* @param urlPath the url path
* @param username the username
* @param password the password
@ -38,15 +40,16 @@ public class VirtualAbilityImpl implements DisposeAbility {
/**
* Run dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType, @Nullable Long duration) {
return new MulReturnType<>(ErrorCode.ERR_OK, null);
@ -55,15 +58,15 @@ public class VirtualAbilityImpl implements DisposeAbility {
/**
* Stop dispose mul return type.
*
* @param ip the ip
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> stopDispose(String ip, DisposeCapacityType capType,
public MulReturnType<ErrorCode, Long> stopDispose(String disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType, @Nullable String taskId) {
return new MulReturnType<>(ErrorCode.ERR_OK, null);

View File

@ -71,7 +71,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTask.getTaskAttackType());
// 调用设备执行处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null, null);
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(),
null, null, null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果
@ -136,8 +139,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
(long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果
@ -223,8 +228,9 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_OUT,
t.getValue());
// 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_OUT, t.getValue(), null);
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_OUT,
t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功
@ -260,8 +266,9 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), NetflowDirection.DIRECTION_IN,
t.getValue());
// 调用迪普设备启动处置任务
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(),
NetflowDirection.DIRECTION_IN, t.getValue(), null);
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), NetflowDirection.DIRECTION_IN,
t.getValue(), null);
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 标志启动成功
@ -437,8 +444,10 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
deviceTaskManager.setExecAttackType(deviceTask.getId(), NetflowDirection.DIRECTION_BI,
deviceTask.getTaskAttackType());
ret = ai.getDb().runDispose(disposeTask.getDisposeObject(), disposeTask.getDisposeCapacity(), null, null,
(long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
ret = ai.getDb()
.runDispose(disposeTask.getDisposeObject(), disposeTask.getObjectType(),
disposeTask.getDisposeCapacity(), null,
null, (long) -(Helper.getTimestampDiffNow(disposeTask.getPlanEndTime()) / 60));
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
// 设置攻击类型任务启动结果