Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -50,7 +50,7 @@ public class TaskCommandInfo {
|
|||||||
|
|
||||||
@Schema(description = "局点", example = "123456")
|
@Schema(description = "局点", example = "123456")
|
||||||
@JsonProperty("distribute_point")
|
@JsonProperty("distribute_point")
|
||||||
private Integer distributePoint;
|
private String distributePoint;
|
||||||
|
|
||||||
@Schema(description = "事件类型(策略模板名称)", example = "DDOS")
|
@Schema(description = "事件类型(策略模板名称)", example = "DDOS")
|
||||||
@JsonProperty("event_type")
|
@JsonProperty("event_type")
|
||||||
@@ -123,6 +123,7 @@ public class TaskCommandInfo {
|
|||||||
this.taskType = original.taskType;
|
this.taskType = original.taskType;
|
||||||
this.taskAct = original.taskAct;
|
this.taskAct = original.taskAct;
|
||||||
this.distributePoint = original.distributePoint;
|
this.distributePoint = original.distributePoint;
|
||||||
|
this.eventType = original.eventType;
|
||||||
this.frequency = original.frequency;
|
this.frequency = original.frequency;
|
||||||
this.startTime = original.startTime;
|
this.startTime = original.startTime;
|
||||||
this.endTime = original.endTime;
|
this.endTime = original.endTime;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class AlertMessageService {
|
|||||||
public void processAlertMessage(AlertMessage alertMessage) {
|
public void processAlertMessage(AlertMessage alertMessage) {
|
||||||
//根据告警信息——>生成指令
|
//根据告警信息——>生成指令
|
||||||
List<TaskCommandInfo> dynamicTaskCommandInfoList = generateDynamicCommand(alertMessage);
|
List<TaskCommandInfo> dynamicTaskCommandInfoList = generateDynamicCommand(alertMessage);
|
||||||
//获取任务状态,设置指令的isValid字段,且是否生成指令入库(除了RUNING\PAUSED状态,其他都不入库)。
|
//获取任务状态,设置指令的isValid字段,且是否生成指令入库(除了RUNING\PAUSED状态,其他都不入command库)。
|
||||||
Integer taskStatus = dynamicTaskCommandInfoList.get(0).getTaskStatus();
|
Integer taskStatus = dynamicTaskCommandInfoList.get(0).getTaskStatus();
|
||||||
//获取任务类型,设置指令的isJudged字段。
|
//获取任务类型,设置指令的isJudged字段。
|
||||||
Integer taskType = dynamicTaskCommandInfoList.get(0).getTaskType();
|
Integer taskType = dynamicTaskCommandInfoList.get(0).getTaskType();
|
||||||
@@ -89,7 +89,7 @@ public class AlertMessageService {
|
|||||||
alertMessage.getProtectIsSrcOrDst(), templateProtectLevel);
|
alertMessage.getProtectIsSrcOrDst(), templateProtectLevel);
|
||||||
|
|
||||||
//根据fiveTuple生成动态指令信息
|
//根据fiveTuple生成动态指令信息
|
||||||
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<TaskCommandInfo>();
|
List<TaskCommandInfo> dynamicCommandInfoList = new ArrayList<>();
|
||||||
if (fiveTupleWithMaskNew.size() == 2){
|
if (fiveTupleWithMaskNew.size() == 2){
|
||||||
TaskCommandInfo dynamicCommandInfo_bi = new TaskCommandInfo();
|
TaskCommandInfo dynamicCommandInfo_bi = new TaskCommandInfo();
|
||||||
dynamicCommandInfo_bi.copyTaskCommandInfo(dynamicCommandInfo);
|
dynamicCommandInfo_bi.copyTaskCommandInfo(dynamicCommandInfo);
|
||||||
@@ -203,7 +203,7 @@ public class AlertMessageService {
|
|||||||
peer.setPort(null);
|
peer.setPort(null);
|
||||||
peer.setMaskPort(null);
|
peer.setMaskPort(null);
|
||||||
}
|
}
|
||||||
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<FiveTupleWithMask>();
|
List<FiveTupleWithMask> newFiveTupleWithMask = new ArrayList<>();
|
||||||
//生成指令
|
//生成指令
|
||||||
FiveTupleWithMask command1 = new FiveTupleWithMask();
|
FiveTupleWithMask command1 = new FiveTupleWithMask();
|
||||||
command1.setSourceIP(peer.getIP());
|
command1.setSourceIP(peer.getIP());
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -163,7 +165,7 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
|||||||
public ResponseResult updateStaticRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
public ResponseResult updateStaticRuleAuditStatus(@PathVariable Integer id, @PathVariable Integer auditStatus) {
|
||||||
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||||
return new ResponseResult(400, "id or status is invalid")
|
return new ResponseResult(400, "id or status is invalid")
|
||||||
.setData("whiteobj_id", id)
|
.setData("staticRule_id", id)
|
||||||
.setData("success", false);
|
.setData("success", false);
|
||||||
}
|
}
|
||||||
return ResponseResult.ok()
|
return ResponseResult.ok()
|
||||||
@@ -173,4 +175,29 @@ public class StaticRuleController implements StaticRuleControllerApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量修改审核状态
|
||||||
|
*/
|
||||||
|
@PostMapping("/auditbatch")
|
||||||
|
public ResponseResult updateStaticRuleAuditStatusBatch(@RequestBody Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
List<Integer> errorIds = new ArrayList<>();
|
||||||
|
for (Map.Entry<Integer, Integer> entry: idsWithAuditStatusMap.entrySet()) {
|
||||||
|
Integer id = entry.getKey();
|
||||||
|
Integer auditStatus = entry.getValue();
|
||||||
|
if (id <= 0 || auditStatus < 0 || auditStatus > 2) {
|
||||||
|
errorIds.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!errorIds.isEmpty()){
|
||||||
|
return new ResponseResult(400, "id or status is invalid")
|
||||||
|
.setData("staticRule_id", errorIds)
|
||||||
|
.setData("success", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseResult.ok()
|
||||||
|
.setData("success", staticRuleService.updateAuditStatusBatch(idsWithAuditStatusMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface StaticRuleMapper {
|
public interface StaticRuleMapper {
|
||||||
@@ -43,4 +44,6 @@ public interface StaticRuleMapper {
|
|||||||
String static_rule_create_username, String ip);
|
String static_rule_create_username, String ip);
|
||||||
|
|
||||||
List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids);
|
List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids);
|
||||||
|
|
||||||
|
void updateAuditStatusByIdBatch(@Param("idWithAuditStatusBatch")Map<Integer, Integer> idWithAuditStatusBatch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ public class StaticRuleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
|
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
|
||||||
for (StaticRuleObject staticRule : staticRuleList) {
|
for (StaticRuleObject staticRule : list) {
|
||||||
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
|
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
|
||||||
StaticRuleBatch.add(staticRule);
|
StaticRuleBatch.add(staticRule);
|
||||||
if (StaticRuleBatch.size() < 100) {
|
if (StaticRuleBatch.size() < 100) {
|
||||||
@@ -215,4 +215,31 @@ public class StaticRuleService {
|
|||||||
public List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids) {
|
public List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids) {
|
||||||
return staticRuleMapper.queryStaticRuleByIds(ids);
|
return staticRuleMapper.queryStaticRuleByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object updateAuditStatusBatch(Map<Integer, Integer> idsWithAuditStatusMap) {
|
||||||
|
|
||||||
|
Function<StaticRuleMapper, Function<Map<Integer, Integer>, Boolean>> updateStaticRuleAuditStatusFunction =
|
||||||
|
mapper -> map -> {
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Integer> idWithAuditStatusBatch = new HashMap<>();
|
||||||
|
for (Map.Entry<Integer, Integer> item : map.entrySet()) {
|
||||||
|
idWithAuditStatusBatch.put(item.getKey(), item.getValue());
|
||||||
|
if (idWithAuditStatusBatch.size() < 100) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//mapper指的就是外层函数输入的参数,也就是WhiteListMapper
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
idWithAuditStatusBatch.clear();
|
||||||
|
}
|
||||||
|
if (!idWithAuditStatusBatch.isEmpty()) {
|
||||||
|
mapper.updateAuditStatusByIdBatch(idWithAuditStatusBatch);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
//实现事务操作
|
||||||
|
return sqlSessionWrapper.startBatchSession(StaticRuleMapper.class, updateStaticRuleAuditStatusFunction, idsWithAuditStatusMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
<result column="task_end_time" property="endTime"/>
|
<result column="task_end_time" property="endTime"/>
|
||||||
|
|
||||||
<result column="template_id" property="templateId"/>
|
<result column="template_id" property="templateId"/>
|
||||||
|
|
||||||
|
<result column="dynamic_rule_range" property="distributePoint"/>
|
||||||
|
<result column="strategy_template_name" property="eventType"/>
|
||||||
|
|
||||||
<result column="dynamic_rule_protect_level" property="protectLevel"/>
|
<result column="dynamic_rule_protect_level" property="protectLevel"/>
|
||||||
<result column="task_status" property="taskStatus"/>
|
<result column="task_status" property="taskStatus"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@@ -149,12 +153,17 @@
|
|||||||
t_task.task_end_time,
|
t_task.task_end_time,
|
||||||
|
|
||||||
t_dr.template_id,
|
t_dr.template_id,
|
||||||
|
t_dr.dynamic_rule_range,
|
||||||
t_dr.dynamic_rule_protect_level,
|
t_dr.dynamic_rule_protect_level,
|
||||||
t_task.task_status
|
t_task.task_status,
|
||||||
|
|
||||||
|
t_tmplate.strategy_template_name
|
||||||
|
|
||||||
from t_task
|
from t_task
|
||||||
left join realtime_protection.t_dynamic_rule t_dr on
|
left join realtime_protection.t_dynamic_rule t_dr on
|
||||||
(t_task.task_id = t_dr.dynamic_rule_used_task_id and t_dr.dynamic_rule_id = #{dynamicRuleId})
|
(t_task.task_id = t_dr.dynamic_rule_used_task_id and t_dr.dynamic_rule_id = #{dynamicRuleId})
|
||||||
|
left join realtime_protection.t_strategy_template t_tmplate on
|
||||||
|
( t_dr.template_id = t_tmplate.strategy_template_id )
|
||||||
where
|
where
|
||||||
t_task.task_id = #{taskId}
|
t_task.task_id = #{taskId}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME,
|
MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME,
|
||||||
INVALID_TIME, IS_VALID, IS_JUDGED,
|
INVALID_TIME, IS_VALID, IS_JUDGED,
|
||||||
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
|
SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED)
|
||||||
values (#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.taskName}, #{info.eventType}, #{info.department}, #{info.distributePoint},
|
values (#{info.UUID}, #{info.taskId}, #{info.taskAct}, #{info.taskName}, #{info.eventType}, #{info.taskCreateDepart}, #{info.distributePoint},
|
||||||
#{info.frequency},
|
#{info.frequency},
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
#{info.fiveTupleWithMask.sourceIP}, #{info.fiveTupleWithMask.sourcePort},
|
#{info.fiveTupleWithMask.sourceIP}, #{info.fiveTupleWithMask.sourcePort},
|
||||||
|
|||||||
@@ -84,6 +84,20 @@
|
|||||||
set static_rule_audit_status = #{auditStatus}
|
set static_rule_audit_status = #{auditStatus}
|
||||||
where static_rule_id = #{id}
|
where static_rule_id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateAuditStatusByIdBatch">
|
||||||
|
update t_static_rule
|
||||||
|
set static_rule_audit_status = CASE static_rule_id
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" item="auditStatus" separator=" ">
|
||||||
|
WHEN #{id} THEN #{auditStatus}
|
||||||
|
</foreach>
|
||||||
|
ELSE static_rule_audit_status
|
||||||
|
END
|
||||||
|
WHERE static_rule_id IN
|
||||||
|
<foreach collection="idWithAuditStatusBatch" index="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
</update>
|
||||||
<delete id="deleteStaticRules">
|
<delete id="deleteStaticRules">
|
||||||
delete from t_static_rule
|
delete from t_static_rule
|
||||||
where static_rule_id in
|
where static_rule_id in
|
||||||
|
|||||||
@@ -164,7 +164,7 @@
|
|||||||
<result column="static_rule_id" property="ruleId"/>
|
<result column="static_rule_id" property="ruleId"/>
|
||||||
|
|
||||||
<result column="task_act" property="taskAct"/>
|
<result column="task_act" property="taskAct"/>
|
||||||
<result column="task_create_depart" property="department"/>
|
<result column="task_create_depart" property="taskCreateDepart"/>
|
||||||
<result column="static_rule_range" property="distributePoint"/>
|
<result column="static_rule_range" property="distributePoint"/>
|
||||||
<result column="task_type" property="taskType"/>
|
<result column="task_type" property="taskType"/>
|
||||||
<result column="static_rule_frequency" property="frequency"/>
|
<result column="static_rule_frequency" property="frequency"/>
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class AlertMessageTest {
|
|||||||
object.setDynamicRulePriority(1);
|
object.setDynamicRulePriority(1);
|
||||||
object.setDynamicRuleRange("北京");
|
object.setDynamicRuleRange("北京");
|
||||||
object.setDynamicRuleProtectLevel(1);
|
object.setDynamicRuleProtectLevel(1);
|
||||||
|
object.setLogRuleId(1L);
|
||||||
object.setTemplateId(templates.get(0).getTemplateId());
|
object.setTemplateId(templates.get(0).getTemplateId());
|
||||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||||
@@ -81,7 +82,7 @@ public class AlertMessageTest {
|
|||||||
//启动任务
|
//启动任务
|
||||||
stateChangeService.changeState(2, taskId, false);
|
stateChangeService.changeState(2, taskId, false);
|
||||||
|
|
||||||
for (int i = 0 ; i< 10; i++) {
|
for (int i = 0 ; i< 5; i++) {
|
||||||
AlertMessage alert = new AlertMessage();
|
AlertMessage alert = new AlertMessage();
|
||||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||||
fiveTupleWithMask.setSourceIP("111.1.1." + i);
|
fiveTupleWithMask.setSourceIP("111.1.1." + i);
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@@ -101,7 +103,15 @@ public class StaticRuleServiceTest extends ProtectionApplicationTests {
|
|||||||
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(null, null, null, null, 1, 10);
|
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRule(null, null, null, null, 1, 10);
|
||||||
System.out.println(staticRuleObjects);
|
System.out.println(staticRuleObjects);
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
void testUpdateStaticRuleAuditStatusBatch(){
|
||||||
|
Map<Integer, Integer> map = new HashMap<>();
|
||||||
|
map.put(1299, 0);
|
||||||
|
map.put(1300, 1);
|
||||||
|
map.put(1301, 1);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(staticRuleService.updateAuditStatusBatch(map));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user