diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java index 0e78a9e..736d779 100644 --- a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java @@ -1,11 +1,17 @@ package com.realtime.protection.server.alertmessage; +import com.fasterxml.jackson.annotation.JsonProperty; import com.realtime.protection.configuration.entity.alert.AlertMessage; import com.realtime.protection.configuration.response.ResponseResult; import jakarta.validation.Valid; +import jdk.jfr.DataAmount; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.Map; + @RestController @RequestMapping("alertmessage") @Slf4j @@ -30,4 +36,23 @@ public class AlertMessageController .setData("alarms", alertMessageService.queryAlarmsByCommandId(commandId)); } + @Data + class AlertMessageAuditInfo { + @JsonProperty("id") + private Integer id; + @JsonProperty("audit_info") + private String auditInfo; + } + //告警信息审计接口 + @PostMapping("/auditInfo/{id}") + public ResponseResult updateAuditInfo(@PathVariable String id, + @RequestBody Map auditInfo) { + if (auditInfo.get("auditInfo") == null || auditInfo.get("auditInfo").isEmpty()) { + return ResponseResult.ok(); + } + return ResponseResult.ok() + .setData("success", alertMessageService.updateAuditInfo(id, auditInfo.get("auditInfo"))); + } + + } diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageMapper.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageMapper.java index 8cf153d..223f4bf 100644 --- a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageMapper.java +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageMapper.java @@ -21,4 +21,6 @@ public interface AlertMessageMapper { void insertAlertMessage(AlertMessage alertMessage); @DS("doris") List queryAlermsByCommandId(String commandId); + @DS("doris") + Boolean updateAuditInfo(String id, String auditInfo); } diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java index 9921f80..fd49573 100644 --- a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java @@ -31,14 +31,18 @@ public class AlertMessageService { private final Counter counter; private final StateHandler stateHandler; - public AlertMessageService( - CommandService commandService, AlertMessageMapper alertMessageMapper, Counter counter, StateHandler stateHandler) { + public AlertMessageService(CommandService commandService, AlertMessageMapper alertMessageMapper, + Counter counter, StateHandler stateHandler) { this.commandService = commandService; this.alertMessageMapper = alertMessageMapper; this.counter = counter; this.stateHandler = stateHandler; } + public Boolean updateAuditInfo(String id, String auditInfo) { + return alertMessageMapper.updateAuditInfo(id, auditInfo); + } + @DSTransactional public void processAlertMessage(AlertMessage alertMessage) { //将告警信息中的c_time转换为LocalDateTime,并写入ctime diff --git a/src/main/java/com/realtime/protection/server/command/CommandMapper.java b/src/main/java/com/realtime/protection/server/command/CommandMapper.java index 0ba5dce..a7c8693 100644 --- a/src/main/java/com/realtime/protection/server/command/CommandMapper.java +++ b/src/main/java/com/realtime/protection/server/command/CommandMapper.java @@ -23,7 +23,7 @@ public interface CommandMapper { Boolean startCommandsByTaskId(@Param("task_id") Long taskId); Boolean setCommandJudged(@Param("command_id") String commandId, - @Param("is_judged") Boolean isJudged); + @Param("is_judged") Integer isJudged); List queryCommandInfos(@Param("task_id") Long taskId, @Param("src_ip") String sourceIP, diff --git a/src/main/java/com/realtime/protection/server/command/CommandService.java b/src/main/java/com/realtime/protection/server/command/CommandService.java index 0d73a91..a2691e3 100644 --- a/src/main/java/com/realtime/protection/server/command/CommandService.java +++ b/src/main/java/com/realtime/protection/server/command/CommandService.java @@ -136,13 +136,13 @@ public class CommandService { return commandMapper.removeCommandsByTaskId(taskId); } - public Boolean setCommandJudged(String commandId, Boolean isJudged) { + public Boolean setCommandJudged(String commandId, Integer isJudged) { //设置指令是否已经研判 Boolean success = commandMapper.setCommandJudged(commandId, isJudged); try { List commandUUIDs = Collections.singletonList(commandId); - if (!isJudged) { + if (isJudged != 1) { return success; } //指令首次下发 diff --git a/src/main/java/com/realtime/protection/server/task/TaskController.java b/src/main/java/com/realtime/protection/server/task/TaskController.java index 69d63d2..472abd1 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskController.java +++ b/src/main/java/com/realtime/protection/server/task/TaskController.java @@ -8,7 +8,12 @@ import com.realtime.protection.configuration.response.ResponseResult; import com.realtime.protection.configuration.utils.enums.StateEnum; import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import com.realtime.protection.server.command.CommandService; +import com.realtime.protection.server.defense.object.ProtectObjectService; +import com.realtime.protection.server.defense.templatenew.TemplateService; +import com.realtime.protection.server.rule.dynamicrule.DynamicRuleService; +import com.realtime.protection.server.rule.staticrule.StaticRuleService; import com.realtime.protection.server.task.status.StateChangeService; +import com.realtime.protection.server.whitelist.WhiteListService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; @@ -28,11 +33,22 @@ import java.util.Map; public class TaskController implements TaskControllerApi { private final TaskService taskService; + private final StaticRuleService staticRuleService; + private final DynamicRuleService dynamicRuleService; + private final ProtectObjectService protectObjectService; + private final WhiteListService whiteListService; + private final TemplateService templateService; + private final CommandService commandService; private final StateChangeService stateChangeService; - public TaskController(TaskService taskService, CommandService commandService, StateChangeService stateChangeService) { + public TaskController(TaskService taskService, StaticRuleService staticRuleService, DynamicRuleService dynamicRuleService, ProtectObjectService protectObjectService, WhiteListService whiteListService, TemplateService templateService, CommandService commandService, StateChangeService stateChangeService) { this.taskService = taskService; + this.staticRuleService = staticRuleService; + this.dynamicRuleService = dynamicRuleService; + this.protectObjectService = protectObjectService; + this.whiteListService = whiteListService; + this.templateService = templateService; this.commandService = commandService; this.stateChangeService = stateChangeService; } @@ -204,7 +220,7 @@ public class TaskController implements TaskControllerApi { } @GetMapping("/{commandId}/valid/{isJudged}") - public ResponseResult setCommandJudged(@PathVariable Boolean isJudged, + public ResponseResult setCommandJudged(@PathVariable Integer isJudged, @PathVariable String commandId) { return ResponseResult.ok() .setData("success", commandService.setCommandJudged(commandId, isJudged)) @@ -297,5 +313,20 @@ public class TaskController implements TaskControllerApi { .setData("history", taskService.queryHistory(id, page, pageSize)); } + @Override + @GetMapping("/unaudit/statistics") + public ResponseResult queryUnauditStatistics() { + return ResponseResult.ok() + .setData("task", taskService.queryAuditTaskTotalNum(AuditStatusEnum.PENDING.getNum())) + .setData("static_rule", staticRuleService.queryAuditStaticRuleTotalNum(AuditStatusEnum.PENDING.getNum())) + .setData("dynamic_rule", dynamicRuleService.queryAuditDynamicRuleTotalNum(AuditStatusEnum.PENDING.getNum())) + .setData("proobj_undit_num", protectObjectService.queryProtectObjectsTotalNum(null, null, null, null, + null, null, null, null, null, + AuditStatusEnum.getNumByState(AuditStatusEnum.PENDING.getState()))) + .setData("white_list", whiteListService.queryAuditWhiteListTotalNum(AuditStatusEnum.PENDING.getNum())) + .setData("strategy_template", templateService.queryAuditTemplateTotalNum(AuditStatusEnum.PENDING.getNum())) + ; + } + } \ No newline at end of file diff --git a/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java b/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java index c05f28b..4412296 100644 --- a/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java +++ b/src/main/java/com/realtime/protection/server/task/TaskControllerApi.java @@ -544,7 +544,7 @@ public interface TaskControllerApi { ) ) @GetMapping("/{commandId}/valid/{isJudged}") - ResponseResult setCommandJudged(@PathVariable Boolean isJudged, + ResponseResult setCommandJudged(@PathVariable Integer isJudged, @PathVariable String commandId); @Operation( @@ -693,4 +693,21 @@ public interface TaskControllerApi { ResponseResult queryHistory(@PathVariable Long id, @RequestParam(value = "page", required = true) Integer page, @RequestParam(value = "page_size", required = true) Integer pageSize); + @Operation( + summary = "查询规则、任务、配置的未审核数量", + description = "查询规则、任务、配置的未审核数量", + responses = { + @io.swagger.v3.oas.annotations.responses.ApiResponse( + description = "返回是否成功", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ResponseResult.class) + ) + ) + }, + parameters = { + } + ) + @GetMapping("/unaudit/statistics") + ResponseResult queryUnauditStatistics(); } diff --git a/src/main/resources/mappers/AlertMessageMapper.xml b/src/main/resources/mappers/AlertMessageMapper.xml index eb1d5ac..4814c9b 100644 --- a/src/main/resources/mappers/AlertMessageMapper.xml +++ b/src/main/resources/mappers/AlertMessageMapper.xml @@ -177,8 +177,13 @@ ) + + UPDATE t_alertmessage + SET audit_info = #{auditInfo} + WHERE ALERT_MESSAGE_ID = #{id} + - +