1、告警信息增加备注接口

2、task下查询所有配置、任务、规则的未审批数量接口
This commit is contained in:
PushM
2024-06-14 17:05:08 +08:00
parent 990167f785
commit 5af3493ba0
8 changed files with 93 additions and 9 deletions

View File

@@ -1,11 +1,17 @@
package com.realtime.protection.server.alertmessage; 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.entity.alert.AlertMessage;
import com.realtime.protection.configuration.response.ResponseResult; import com.realtime.protection.configuration.response.ResponseResult;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jdk.jfr.DataAmount;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("alertmessage") @RequestMapping("alertmessage")
@Slf4j @Slf4j
@@ -30,4 +36,23 @@ public class AlertMessageController
.setData("alarms", alertMessageService.queryAlarmsByCommandId(commandId)); .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<String, String> auditInfo) {
if (auditInfo.get("auditInfo") == null || auditInfo.get("auditInfo").isEmpty()) {
return ResponseResult.ok();
}
return ResponseResult.ok()
.setData("success", alertMessageService.updateAuditInfo(id, auditInfo.get("auditInfo")));
}
} }

View File

@@ -21,4 +21,6 @@ public interface AlertMessageMapper {
void insertAlertMessage(AlertMessage alertMessage); void insertAlertMessage(AlertMessage alertMessage);
@DS("doris") @DS("doris")
List<AlertMessage> queryAlermsByCommandId(String commandId); List<AlertMessage> queryAlermsByCommandId(String commandId);
@DS("doris")
Boolean updateAuditInfo(String id, String auditInfo);
} }

View File

@@ -31,14 +31,18 @@ public class AlertMessageService {
private final Counter counter; private final Counter counter;
private final StateHandler stateHandler; private final StateHandler stateHandler;
public AlertMessageService( public AlertMessageService(CommandService commandService, AlertMessageMapper alertMessageMapper,
CommandService commandService, AlertMessageMapper alertMessageMapper, Counter counter, StateHandler stateHandler) { Counter counter, StateHandler stateHandler) {
this.commandService = commandService; this.commandService = commandService;
this.alertMessageMapper = alertMessageMapper; this.alertMessageMapper = alertMessageMapper;
this.counter = counter; this.counter = counter;
this.stateHandler = stateHandler; this.stateHandler = stateHandler;
} }
public Boolean updateAuditInfo(String id, String auditInfo) {
return alertMessageMapper.updateAuditInfo(id, auditInfo);
}
@DSTransactional @DSTransactional
public void processAlertMessage(AlertMessage alertMessage) { public void processAlertMessage(AlertMessage alertMessage) {
//将告警信息中的c_time转换为LocalDateTime并写入ctime //将告警信息中的c_time转换为LocalDateTime并写入ctime

View File

@@ -23,7 +23,7 @@ public interface CommandMapper {
Boolean startCommandsByTaskId(@Param("task_id") Long taskId); Boolean startCommandsByTaskId(@Param("task_id") Long taskId);
Boolean setCommandJudged(@Param("command_id") String commandId, Boolean setCommandJudged(@Param("command_id") String commandId,
@Param("is_judged") Boolean isJudged); @Param("is_judged") Integer isJudged);
List<TaskCommandInfo> queryCommandInfos(@Param("task_id") Long taskId, List<TaskCommandInfo> queryCommandInfos(@Param("task_id") Long taskId,
@Param("src_ip") String sourceIP, @Param("src_ip") String sourceIP,

View File

@@ -136,13 +136,13 @@ public class CommandService {
return commandMapper.removeCommandsByTaskId(taskId); return commandMapper.removeCommandsByTaskId(taskId);
} }
public Boolean setCommandJudged(String commandId, Boolean isJudged) { public Boolean setCommandJudged(String commandId, Integer isJudged) {
//设置指令是否已经研判 //设置指令是否已经研判
Boolean success = commandMapper.setCommandJudged(commandId, isJudged); Boolean success = commandMapper.setCommandJudged(commandId, isJudged);
try { try {
List<String> commandUUIDs = Collections.singletonList(commandId); List<String> commandUUIDs = Collections.singletonList(commandId);
if (!isJudged) { if (isJudged != 1) {
return success; return success;
} }
//指令首次下发 //指令首次下发

View File

@@ -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.StateEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum; import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.server.command.CommandService; 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.task.status.StateChangeService;
import com.realtime.protection.server.whitelist.WhiteListService;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@@ -28,11 +33,22 @@ import java.util.Map;
public class TaskController implements TaskControllerApi { public class TaskController implements TaskControllerApi {
private final TaskService taskService; 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 CommandService commandService;
private final StateChangeService stateChangeService; 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.taskService = taskService;
this.staticRuleService = staticRuleService;
this.dynamicRuleService = dynamicRuleService;
this.protectObjectService = protectObjectService;
this.whiteListService = whiteListService;
this.templateService = templateService;
this.commandService = commandService; this.commandService = commandService;
this.stateChangeService = stateChangeService; this.stateChangeService = stateChangeService;
} }
@@ -204,7 +220,7 @@ public class TaskController implements TaskControllerApi {
} }
@GetMapping("/{commandId}/valid/{isJudged}") @GetMapping("/{commandId}/valid/{isJudged}")
public ResponseResult setCommandJudged(@PathVariable Boolean isJudged, public ResponseResult setCommandJudged(@PathVariable Integer isJudged,
@PathVariable String commandId) { @PathVariable String commandId) {
return ResponseResult.ok() return ResponseResult.ok()
.setData("success", commandService.setCommandJudged(commandId, isJudged)) .setData("success", commandService.setCommandJudged(commandId, isJudged))
@@ -297,5 +313,20 @@ public class TaskController implements TaskControllerApi {
.setData("history", taskService.queryHistory(id, page, pageSize)); .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()))
;
}
} }

View File

@@ -544,7 +544,7 @@ public interface TaskControllerApi {
) )
) )
@GetMapping("/{commandId}/valid/{isJudged}") @GetMapping("/{commandId}/valid/{isJudged}")
ResponseResult setCommandJudged(@PathVariable Boolean isJudged, ResponseResult setCommandJudged(@PathVariable Integer isJudged,
@PathVariable String commandId); @PathVariable String commandId);
@Operation( @Operation(
@@ -693,4 +693,21 @@ public interface TaskControllerApi {
ResponseResult queryHistory(@PathVariable Long id, ResponseResult queryHistory(@PathVariable Long id,
@RequestParam(value = "page", required = true) Integer page, @RequestParam(value = "page", required = true) Integer page,
@RequestParam(value = "page_size", required = true) Integer pageSize); @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();
} }

View File

@@ -177,8 +177,13 @@
) )
</insert> </insert>
<update id="updateAuditInfo">
UPDATE t_alertmessage
SET audit_info = #{auditInfo}
WHERE ALERT_MESSAGE_ID = #{id}
</update>
<!-- <select id="queryTemplateProtectLevel" resultMap="protectLevelMap">--> <!-- <select id="queryTemplateProtectLevel" resultMap="protectLevelMap">-->
<!-- SELECT--> <!-- SELECT-->
<!-- t_protect_level.protect_level_id,--> <!-- t_protect_level.protect_level_id,-->
<!-- t_protect_level.has_protect_object_ip,--> <!-- t_protect_level.has_protect_object_ip,-->