1、alertmssage入库增加alertmssage的uuid
2、数据库新建语法增加新列 3、StateHandler.java 的handleJudgedTaskStart和handleDynamicTaskStart不执行sendFilters,因为那边还没实现接收。我们这边sendFilters会报错 无法解析url 4、前端转圈问题,更新nginx配置
This commit is contained in:
@@ -11,9 +11,9 @@ import com.realtime.protection.server.command.CommandService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
|
||||
// AlertMessage的UUID在mapper插入数据库时生成了,这里提前生成好像美神恶魔用
|
||||
@Service
|
||||
public class AlertMessageService {
|
||||
private final CommandService commandService;
|
||||
@@ -27,39 +27,41 @@ public class AlertMessageService {
|
||||
}
|
||||
|
||||
@DSTransactional
|
||||
public void processAlertMessage(AlertMessage alertMessage) {
|
||||
public String processAlertMessage(AlertMessage alertMessage) {
|
||||
TaskCommandInfo dynamicTaskCommandInfo = generateDynamicCommand(alertMessage);
|
||||
|
||||
Integer taskStatus = dynamicTaskCommandInfo.getTaskStatus();
|
||||
Integer taskType = dynamicTaskCommandInfo.getTaskType();
|
||||
String alertMessageUUID = null;
|
||||
|
||||
if (taskType == TaskTypeEnum.DYNAMIC.getTaskType())//实时
|
||||
switch (StateEnum.getStateEnumByNum(taskStatus)) {
|
||||
case RUNNING:
|
||||
insertCommandAndAlertMessage(dynamicTaskCommandInfo, true, true, alertMessage);
|
||||
alertMessageUUID = insertCommandAndAlertMessage(dynamicTaskCommandInfo, true, true, alertMessage);
|
||||
break;
|
||||
case PAUSED:
|
||||
insertCommandAndAlertMessage(dynamicTaskCommandInfo, false, true, alertMessage);
|
||||
alertMessageUUID = insertCommandAndAlertMessage(dynamicTaskCommandInfo, false, true, alertMessage);
|
||||
break;
|
||||
default://主要是stop
|
||||
//command不入库
|
||||
//alertmessage入库
|
||||
insertAlertMessageOnly(alertMessage);
|
||||
alertMessageUUID = insertAlertMessageOnly(alertMessage);
|
||||
break;
|
||||
}
|
||||
else if (taskType == TaskTypeEnum.JUDGED.getTaskType())//研判后
|
||||
switch (StateEnum.getStateEnumByNum(taskStatus)) {
|
||||
case RUNNING:
|
||||
insertCommandAndAlertMessage(dynamicTaskCommandInfo, true, false, alertMessage);
|
||||
alertMessageUUID = insertCommandAndAlertMessage(dynamicTaskCommandInfo, true, false, alertMessage);
|
||||
break;
|
||||
case PAUSED:
|
||||
insertCommandAndAlertMessage(dynamicTaskCommandInfo, false, false, alertMessage);
|
||||
alertMessageUUID = insertCommandAndAlertMessage(dynamicTaskCommandInfo, false, false, alertMessage);
|
||||
break;
|
||||
default://主要是stop
|
||||
//command不入库
|
||||
//alertmessage入库
|
||||
insertAlertMessageOnly(alertMessage);
|
||||
alertMessageUUID = insertAlertMessageOnly(alertMessage);
|
||||
}
|
||||
return alertMessageUUID;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +89,7 @@ public class AlertMessageService {
|
||||
}
|
||||
|
||||
@DSTransactional
|
||||
private void insertCommandAndAlertMessage(TaskCommandInfo dynamicTaskCommandInfo,
|
||||
private String insertCommandAndAlertMessage(TaskCommandInfo dynamicTaskCommandInfo,
|
||||
Boolean isValid,
|
||||
Boolean isJudged,
|
||||
AlertMessage alertMessage){
|
||||
@@ -98,12 +100,21 @@ public class AlertMessageService {
|
||||
|
||||
//alertmessage入库
|
||||
alertMessage.setCommandUUID(commandUUID);
|
||||
String alertMessageUUID = UUID.randomUUID().toString();
|
||||
alertMessage.setAlertMessageUUID(alertMessageUUID);
|
||||
alertMessageMapper.insertAlertMessage(alertMessage);
|
||||
|
||||
return alertMessageUUID;
|
||||
}
|
||||
private void insertAlertMessageOnly(AlertMessage alertMessage){
|
||||
private String insertAlertMessageOnly(AlertMessage alertMessage){
|
||||
//alertmessage入库
|
||||
alertMessage.setCommandUUID(null);
|
||||
String alertMessageUUID = UUID.randomUUID().toString();
|
||||
alertMessage.setAlertMessageUUID(alertMessageUUID);
|
||||
alertMessageMapper.insertAlertMessage(alertMessage);
|
||||
|
||||
return alertMessageUUID;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -75,11 +75,14 @@ public class StateHandler {
|
||||
// todo: 如果是实时任务或者研判后处置任务,那么就需要在任务启动之后,立刻向动态规则中指定的系统发送日志筛选请求。
|
||||
// 筛选完成后,系统返回日志,需要由接收端点提取字段,并且合成一条静态规则,再按照任务开始时间、结束时间和任务类型进行指令创建
|
||||
private Boolean handleJudgedTaskStart(TaskService taskService, Long taskId) {
|
||||
return sendFilters(taskService, taskId);
|
||||
// return sendFilters(taskService, taskId);
|
||||
// 还没配置帅选条件发送的url,不配置会出错,所以先注释
|
||||
return true;
|
||||
}
|
||||
|
||||
private Boolean handleDynamicTaskStart(TaskService taskService, Long taskId) {
|
||||
return sendFilters(taskService, taskId);
|
||||
// return sendFilters(taskService, taskId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Boolean handleStaticTaskStart(CommandService commandService, TaskService taskService, Long taskId) {
|
||||
|
||||
@@ -11,7 +11,7 @@ server {
|
||||
location / {
|
||||
root /root/nginx/defense;
|
||||
index index.html;
|
||||
try_files $uri $uri/ @router;
|
||||
#try_files $uri $uri/ @router;
|
||||
}
|
||||
|
||||
location @router {
|
||||
|
||||
@@ -6,10 +6,12 @@ import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.configuration.entity.task.FiveTupleWithMask;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.exception.DorisStartException;
|
||||
import com.realtime.protection.server.defense.object.ProtectObjectService;
|
||||
import com.realtime.protection.server.defense.template.TemplateService;
|
||||
import com.realtime.protection.server.rule.dynamicrule.DynamicRuleService;
|
||||
import com.realtime.protection.server.task.TaskService;
|
||||
import com.realtime.protection.server.task.status.StateChangeService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -25,19 +27,22 @@ public class AlertMessageTest {
|
||||
private final TemplateService templateService;
|
||||
private final DynamicRuleService dynamicRuleService;
|
||||
private final TaskService taskService;
|
||||
private final StateChangeService stateChangeService;
|
||||
@Autowired
|
||||
public AlertMessageTest(AlertMessageService alertMessageService
|
||||
,ProtectObjectService protectObjectService,TemplateService templateService,
|
||||
DynamicRuleService dynamicRuleService,TaskService taskService) {
|
||||
DynamicRuleService dynamicRuleService,TaskService taskService,
|
||||
StateChangeService stateChangeService) {
|
||||
this.alertMessageService = alertMessageService;
|
||||
this.protectObjectService = protectObjectService;
|
||||
this.templateService = templateService;
|
||||
this.dynamicRuleService = dynamicRuleService;
|
||||
this.taskService = taskService;
|
||||
this.stateChangeService = stateChangeService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReceiveAlertMessage() {
|
||||
void testReceiveAlertMessage() throws DorisStartException {
|
||||
|
||||
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(
|
||||
null, null, null, null,
|
||||
@@ -58,7 +63,7 @@ public class AlertMessageTest {
|
||||
|
||||
|
||||
Task task = new Task();
|
||||
task.setTaskName("dong态测试2");
|
||||
task.setTaskName("生产告警信息测试");
|
||||
LocalDateTime taskStartTime = LocalDateTime.now().plusMinutes(1);
|
||||
LocalDateTime taskEndTime = LocalDateTime.now().plusYears(5);
|
||||
task.setTaskStartTime(taskStartTime);
|
||||
@@ -69,18 +74,29 @@ public class AlertMessageTest {
|
||||
task.setTaskCreateUsername("xxx");
|
||||
task.setTaskCreateDepart("xxx");
|
||||
task.setDynamicRuleIds(List.of(new Integer[]{dynamicRuleId}));
|
||||
|
||||
Long taskId = taskService.newTask(task);
|
||||
//审核状态
|
||||
taskService.changeTaskAuditStatus(taskId, 2);
|
||||
//启动任务
|
||||
stateChangeService.changeState(2, taskId, false);
|
||||
|
||||
for (int i = 0 ; i< 10; i++) {
|
||||
AlertMessage alert = new AlertMessage();
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
fiveTupleWithMask.setSourceIP("1.1.1." + i);
|
||||
fiveTupleWithMask.setDestinationIP("2.2.2." + i);
|
||||
fiveTupleWithMask.setSourcePort("80");
|
||||
fiveTupleWithMask.setDestinationPort("80");
|
||||
fiveTupleWithMask.setProtocol("tcp");
|
||||
|
||||
alert.setDynamicRuleId(dynamicRuleId);
|
||||
alert.setTaskId(taskId);
|
||||
alert.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
alert.setContent("testcontent");
|
||||
alertMessageService.processAlertMessage(alert);
|
||||
}
|
||||
|
||||
AlertMessage alert = new AlertMessage();
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
fiveTupleWithMask.setSourceIP("1.1.1.1");
|
||||
|
||||
alert.setDynamicRuleId(dynamicRuleId);
|
||||
alert.setTaskId(taskId);
|
||||
alert.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
alert.setContent("testcontent");
|
||||
alertMessageService.processAlertMessage(alert);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,13 @@ public class DynamicRuleServiceTest extends ProtectionApplicationTests {
|
||||
@Test
|
||||
void testQueryDynamicRuleObject() {
|
||||
List<DynamicRuleObject> objects = dynamicRuleService.queryDynamicRuleObject(
|
||||
null,null,"1", null,1, 10);
|
||||
null,null,null, null,1, 10);
|
||||
System.out.println(objects);
|
||||
}
|
||||
@Test
|
||||
void testQueryDynamicRuleTotalNum(){
|
||||
Integer num = dynamicRuleService.queryDynamicRuleTotalNum(
|
||||
null,null,null,null);
|
||||
System.out.println(num);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user