From 914b0f0e2a2cf4a8b887b8aded2b35c6f23bba8d Mon Sep 17 00:00:00 2001 From: Hao Miao <47212914+PushM@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:20:45 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0AlertMessage=20http?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=8E=A5=E6=94=B6=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=94=9F=E6=88=90=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=85=A5=E5=BA=93=202=E3=80=81staticrule=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7=E3=80=81=E9=A2=91=E7=8E=87=E9=99=90=E5=88=B6=E8=8C=83?= =?UTF-8?q?=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/rule/dynamicrule/AlertMessage.java | 15 ++++++++ .../rule/staticrule/StaticRuleObject.java | 7 +++- .../alertmessage/AlertMessageController.java | 28 ++++++++++++++ .../alertmessage/AlertMessageService.java | 38 +++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/AlertMessage.java create mode 100644 src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java create mode 100644 src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java diff --git a/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/AlertMessage.java b/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/AlertMessage.java new file mode 100644 index 0000000..9267d03 --- /dev/null +++ b/src/main/java/com/realtime/protection/configuration/entity/rule/dynamicrule/AlertMessage.java @@ -0,0 +1,15 @@ +package com.realtime.protection.configuration.entity.rule.dynamicrule; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.realtime.protection.configuration.entity.task.FiveTupleWithMask; +import lombok.Data; + +@Data +public class AlertMessage { + + @JsonProperty("task_id") + private Long taskId; + @JsonProperty("five_tuple_with_mask") + private FiveTupleWithMask fiveTupleWithMask; + +} diff --git a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java index 02f22f8..e61b1eb 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java +++ b/src/main/java/com/realtime/protection/configuration/entity/rule/staticrule/StaticRuleObject.java @@ -128,7 +128,9 @@ public class StaticRuleObject { @JsonProperty("static_rule_priority") @ExcelProperty("优先级") - @Schema(description = "优先级", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) + @Max(value = 3) + @Min(value = 1) + @Schema(description = "优先级,1代表高2代表中3代表低", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) private Integer staticRulePriority; @JsonProperty("static_rule_range") @ExcelProperty("范围") @@ -136,7 +138,8 @@ public class StaticRuleObject { private String staticRuleRange; @JsonProperty("static_rule_frequency") @ExcelProperty("频率") - @Schema(description = "频率", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) + @Min(value = 1) + @Schema(description = "频率,最低为1", example = "1", requiredMode = Schema.RequiredMode.REQUIRED) private Integer staticRuleFrequency; } diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java new file mode 100644 index 0000000..44e0661 --- /dev/null +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageController.java @@ -0,0 +1,28 @@ +package com.realtime.protection.server.alertmessage; + +import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage; +import com.realtime.protection.configuration.response.ResponseResult; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("alertmessage") +@Slf4j +public class AlertMessageController +{ + private final AlertMessageService alertMessageService; + public AlertMessageController(final AlertMessageService alertMessageService) { + this.alertMessageService = alertMessageService; + } + + @PostMapping("/new") + public ResponseResult receiveAlertMessage(@RequestBody @Valid AlertMessage alertMessage){ + alertMessageService.receiveAlertMessage(alertMessage); + return ResponseResult.ok(); + } + +} diff --git a/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java new file mode 100644 index 0000000..da8dda1 --- /dev/null +++ b/src/main/java/com/realtime/protection/server/alertmessage/AlertMessageService.java @@ -0,0 +1,38 @@ +package com.realtime.protection.server.alertmessage; + +import com.realtime.protection.configuration.entity.rule.dynamicrule.AlertMessage; +import com.realtime.protection.configuration.entity.task.Task; +import com.realtime.protection.configuration.entity.task.TaskCommandInfo; +import com.realtime.protection.server.task.TaskService; +import org.springframework.stereotype.Service; +import com.realtime.protection.server.command.CommandService; +import com.realtime.protection.configuration.utils.enums.StateEnum; + +@Service +public class AlertMessageService { + private final CommandService commandService; + private final TaskService taskService; + + public AlertMessageService(CommandService commandService,TaskService taskService) { + this.commandService = commandService; + this.taskService = taskService; + } + + public void receiveAlertMessage(AlertMessage alertMessage) { + Long taskId = alertMessage.getTaskId(); + //查task信息 + Task task = taskService.queryTask(taskId); + //检查task status是否为running? +// if (task.getTaskStatus() != StateEnum.RUNNING.getStateNum()) { +// return; +// } + + //task信息和alertMessage中的fiveTuple信息 合并成 TaskCommandInfo + TaskCommandInfo dynamicTaskCommandInfo = new TaskCommandInfo(); + + + //command入库 + //commandService.createCommand(staticTaskCommandInfo); + + } +}