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:
EnderByEndera
2024-04-25 12:09:23 +08:00
parent fa7c89eb5a
commit 1b38276701
5 changed files with 49 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
package com.realtime.protection.configuration.entity.task;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.time.LocalDateTime;
@@ -10,23 +11,44 @@ public class DynamicTaskInfo {
@Data
private static class SimpleProtectObject {
@JsonProperty("ip")
private String IP;
@JsonProperty("port")
private Integer port;
@JsonProperty("url")
private String URL;
@JsonProperty("protocol")
private String protocol;
}
// 从任务中获取
@JsonProperty("task_id")
private Long taskId;
@JsonProperty("start_time")
private LocalDateTime startTime;
@JsonProperty("end_time")
private LocalDateTime endTime;
// 从规则中获取
@JsonProperty("rule_id")
private Integer ruleId;
@JsonProperty("source_system")
private String sourceSystem;
@JsonProperty("event_type")
private String eventType;
@JsonProperty("log_rule_id")
private Long logRuleId;
// 从防护对象列表中获取
@JsonProperty("protect_objects")
private List<SimpleProtectObject> protectObjects;
}

View File

@@ -92,7 +92,12 @@ public class TaskService {
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()) {
throw new IllegalArgumentException("静态规则列表中的ID不存在请检查静态规则是否真实存在");
}
@@ -147,7 +152,12 @@ public class TaskService {
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()) {
throw new IllegalArgumentException("静态规则列表中的ID不存在请检查静态规则是否真实存在");
}

View File

@@ -13,13 +13,14 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
public class StateHandler {
private final WebClient client = WebClient.builder()
.baseUrl("") // todo: unfinished
.baseUrl("http://192.168.107.89:9081")
.build();
protected Boolean handleStart(TaskService taskService, CommandService commandService, Long taskId) {
@@ -110,12 +111,12 @@ public class StateHandler {
throw new IllegalArgumentException("动态规则列表为空,请至少选择一个动态规则以启动动态/研判后类型任务");
}
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.AUDITED);
taskService.updateDynamicRuleAuditStatusInTask(task.getTaskId(), AuditStatusEnum.USING);
AtomicReference<Boolean> success = new AtomicReference<>(false);
Mono<SimpleResponse> mono = client.post()
.uri("http://192.168.107.89:9081/api/v1/kafkasend") // todo: untested
.uri("/api/v1/kafkasend")
.bodyValue(dynamicTaskInfos)
.exchangeToMono(res -> {
if (res.statusCode().equals(HttpStatus.OK)) {
@@ -126,9 +127,10 @@ public class StateHandler {
})
.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;
}