1. DynamicRuleMapper中添加audit_status result映射
2. 给DynamicTaskInfo实体类中添加所有字段对应的Json字段 3. 修改sendFilter函数中的WebClient初始化URL和URI,修改mono.block的超时设置,添加对response字段中success的判断 4. 将TaskMapper中的getDynamicTaskInfos select语句的INNER JOIN修改为LEFT JOIN 5. updateStaticRUleAuditStatusInTask和updateDynamicRuleAuditStatusInTask添加对staticRuleIds列表的判断,确保SQL语句不会出现问题
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.realtime.protection.configuration.entity.task;
|
package com.realtime.protection.configuration.entity.task;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -10,23 +11,44 @@ public class DynamicTaskInfo {
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class SimpleProtectObject {
|
private static class SimpleProtectObject {
|
||||||
|
|
||||||
|
@JsonProperty("ip")
|
||||||
private String IP;
|
private String IP;
|
||||||
|
|
||||||
|
@JsonProperty("port")
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
|
||||||
|
@JsonProperty("url")
|
||||||
private String URL;
|
private String URL;
|
||||||
|
|
||||||
|
@JsonProperty("protocol")
|
||||||
private String protocol;
|
private String protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从任务中获取
|
// 从任务中获取
|
||||||
|
@JsonProperty("task_id")
|
||||||
private Long taskId;
|
private Long taskId;
|
||||||
|
|
||||||
|
@JsonProperty("start_time")
|
||||||
private LocalDateTime startTime;
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
@JsonProperty("end_time")
|
||||||
private LocalDateTime endTime;
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
// 从规则中获取
|
// 从规则中获取
|
||||||
|
@JsonProperty("rule_id")
|
||||||
private Integer ruleId;
|
private Integer ruleId;
|
||||||
|
|
||||||
|
@JsonProperty("source_system")
|
||||||
private String sourceSystem;
|
private String sourceSystem;
|
||||||
|
|
||||||
|
@JsonProperty("event_type")
|
||||||
private String eventType;
|
private String eventType;
|
||||||
|
|
||||||
|
@JsonProperty("log_rule_id")
|
||||||
private Long logRuleId;
|
private Long logRuleId;
|
||||||
|
|
||||||
// 从防护对象列表中获取
|
// 从防护对象列表中获取
|
||||||
|
@JsonProperty("protect_objects")
|
||||||
private List<SimpleProtectObject> protectObjects;
|
private List<SimpleProtectObject> protectObjects;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,12 @@ public class TaskService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StaticRuleObject> staticRuleObjects = staticRuleMapper.queryStaticRuleByIds(taskMapper.queryDynamicRuleIdsFromTaskId(taskId));
|
List<Integer> staticRuleIds = taskMapper.queryStaticRuleIdsFromTaskId(taskId);
|
||||||
|
if (staticRuleIds == null || staticRuleIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<StaticRuleObject> staticRuleObjects = staticRuleMapper.queryStaticRuleByIds(staticRuleIds);
|
||||||
if (staticRuleObjects == null || staticRuleObjects.isEmpty()) {
|
if (staticRuleObjects == null || staticRuleObjects.isEmpty()) {
|
||||||
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
||||||
}
|
}
|
||||||
@@ -147,7 +152,12 @@ public class TaskService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DynamicRuleObject> dynamicRuleObjects = dynamicRuleMapper.queryDynamicRuleByIds(taskMapper.queryDynamicRuleIdsFromTaskId(taskId));
|
List<Integer> dynamicRuleIds = taskMapper.queryDynamicRuleIdsFromTaskId(taskId);
|
||||||
|
if (dynamicRuleIds == null || dynamicRuleIds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DynamicRuleObject> dynamicRuleObjects = dynamicRuleMapper.queryDynamicRuleByIds(dynamicRuleIds);
|
||||||
if (dynamicRuleObjects == null || dynamicRuleObjects.isEmpty()) {
|
if (dynamicRuleObjects == null || dynamicRuleObjects.isEmpty()) {
|
||||||
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
throw new IllegalArgumentException("静态规则列表中的ID不存在,请检查静态规则是否真实存在");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,14 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||||||
import org.springframework.web.reactive.function.client.WebClientResponseException;
|
import org.springframework.web.reactive.function.client.WebClientResponseException;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class StateHandler {
|
public class StateHandler {
|
||||||
|
|
||||||
private final WebClient client = WebClient.builder()
|
private final WebClient client = WebClient.builder()
|
||||||
.baseUrl("") // todo: unfinished
|
.baseUrl("http://192.168.107.89:9081")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
protected Boolean handleStart(TaskService taskService, CommandService commandService, Long taskId) {
|
protected Boolean handleStart(TaskService taskService, CommandService commandService, Long taskId) {
|
||||||
@@ -110,12 +111,12 @@ public class StateHandler {
|
|||||||
throw new IllegalArgumentException("动态规则列表为空,请至少选择一个动态规则以启动动态/研判后类型任务");
|
throw new IllegalArgumentException("动态规则列表为空,请至少选择一个动态规则以启动动态/研判后类型任务");
|
||||||
}
|
}
|
||||||
|
|
||||||
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.AUDITED);
|
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.USING);
|
||||||
|
|
||||||
AtomicReference<Boolean> success = new AtomicReference<>(false);
|
AtomicReference<Boolean> success = new AtomicReference<>(false);
|
||||||
|
|
||||||
Mono<SimpleResponse> mono = client.post()
|
Mono<SimpleResponse> mono = client.post()
|
||||||
.uri("http://192.168.107.89:9081/api/v1/kafkasend") // todo: untested
|
.uri("/api/v1/kafkasend")
|
||||||
.bodyValue(dynamicTaskInfos)
|
.bodyValue(dynamicTaskInfos)
|
||||||
.exchangeToMono(res -> {
|
.exchangeToMono(res -> {
|
||||||
if (res.statusCode().equals(HttpStatus.OK)) {
|
if (res.statusCode().equals(HttpStatus.OK)) {
|
||||||
@@ -126,9 +127,10 @@ public class StateHandler {
|
|||||||
})
|
})
|
||||||
.doOnError(WebClientResponseException.class, res -> success.set(false));
|
.doOnError(WebClientResponseException.class, res -> success.set(false));
|
||||||
|
|
||||||
SimpleResponse response = mono.block();
|
|
||||||
|
|
||||||
if (response == null) {
|
SimpleResponse response = mono.block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
|
if (response == null || response.getSuccess() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,7 @@
|
|||||||
<result column="dynamic_rule_priority" property="dynamicRulePriority"/>
|
<result column="dynamic_rule_priority" property="dynamicRulePriority"/>
|
||||||
<result column="dynamic_rule_range" property="dynamicRuleRange"/>
|
<result column="dynamic_rule_range" property="dynamicRuleRange"/>
|
||||||
<result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/>
|
<result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/>
|
||||||
|
<result column="audit_status" property="auditStatus"/>
|
||||||
<!-- <result column="protect_object_id" property="protectObjectIds"/>-->
|
<!-- <result column="protect_object_id" property="protectObjectIds"/>-->
|
||||||
<result column="strategy_template_name" property="dynamicRuleEventType"/>
|
<result column="strategy_template_name" property="dynamicRuleEventType"/>
|
||||||
<result column="strategy_template_source_system" property="dynamicRuleSourceSystem"/>
|
<result column="strategy_template_source_system" property="dynamicRuleSourceSystem"/>
|
||||||
|
|||||||
@@ -257,7 +257,8 @@
|
|||||||
<result column="log_rule_id" property="logRuleId"/>
|
<result column="log_rule_id" property="logRuleId"/>
|
||||||
<result column="source_system" property="sourceSystem"/>
|
<result column="source_system" property="sourceSystem"/>
|
||||||
<result column="event_type" property="eventType"/>
|
<result column="event_type" property="eventType"/>
|
||||||
<collection property="protectObjects" ofType="com.realtime.protection.configuration.entity.task.DynamicTaskInfo$SimpleProtectObject">
|
<collection property="protectObjects"
|
||||||
|
ofType="com.realtime.protection.configuration.entity.task.DynamicTaskInfo$SimpleProtectObject">
|
||||||
<result column="protect_object_ip" property="IP"/>
|
<result column="protect_object_ip" property="IP"/>
|
||||||
<result column="protect_object_port" property="port"/>
|
<result column="protect_object_port" property="port"/>
|
||||||
<result column="protect_object_url" property="URL"/>
|
<result column="protect_object_url" property="URL"/>
|
||||||
@@ -274,16 +275,16 @@
|
|||||||
strategy_template_source_system as source_system,
|
strategy_template_source_system as source_system,
|
||||||
strategy_template_name as event_type,
|
strategy_template_name as event_type,
|
||||||
tdr.log_rule_id,
|
tdr.log_rule_id,
|
||||||
INET_NTOA(protect_object_ip) as protect_object_ip,
|
INET_NTOA(protect_object_ip) as protect_object_ip,
|
||||||
protect_object_port,
|
protect_object_port,
|
||||||
protect_object_url,
|
protect_object_url,
|
||||||
protect_object_protocol
|
protect_object_protocol
|
||||||
FROM t_task AS tt
|
FROM t_task AS tt
|
||||||
INNER JOIN realtime_protection.t_dynamic_rule tdr on tt.task_id = tdr.dynamic_rule_used_task_id
|
LEFT JOIN realtime_protection.t_dynamic_rule tdr on tt.task_id = tdr.dynamic_rule_used_task_id
|
||||||
INNER JOIN realtime_protection.t_protect_object_dynamic_rule_conn tpodrc
|
LEFT JOIN realtime_protection.t_protect_object_dynamic_rule_conn tpodrc
|
||||||
on tdr.dynamic_rule_id = tpodrc.dynamic_rule_id
|
on tdr.dynamic_rule_id = tpodrc.dynamic_rule_id
|
||||||
INNER JOIN realtime_protection.t_protect_object tpo on tpo.protect_object_id = tpodrc.protect_object_id
|
LEFT JOIN realtime_protection.t_protect_object tpo on tpo.protect_object_id = tpodrc.protect_object_id
|
||||||
INNER JOIN realtime_protection.t_strategy_template tst on tdr.template_id = tst.strategy_template_id
|
LEFT JOIN realtime_protection.t_strategy_template tst on tdr.template_id = tst.strategy_template_id
|
||||||
WHERE task_id = #{task_id}
|
WHERE task_id = #{task_id}
|
||||||
</select>
|
</select>
|
||||||
<select id="queryTaskTotalNum" resultType="java.lang.Integer">
|
<select id="queryTaskTotalNum" resultType="java.lang.Integer">
|
||||||
|
|||||||
Reference in New Issue
Block a user