1、AlertMessage实体类增加content字段,并同步mapper中新增、查询方法增加content字段
2、DynamicRuleObject实体类新增log_rule_id属性,并同步mapper中新增、查询方法增加log_rule_id字段 3、StaticRule新建增加ip、maskip是否匹配的判断,批量新建和更新还没增加。
This commit is contained in:
@@ -1,38 +1,82 @@
|
||||
package com.realtime.protection.server.alertmessage;
|
||||
|
||||
import com.realtime.protection.configuration.entity.alert.AlertMessage;
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
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.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 org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
public class AlertMessageTest {
|
||||
|
||||
private final AlertMessageService alertMessageService;
|
||||
private final ProtectObjectService protectObjectService;
|
||||
private final TemplateService templateService;
|
||||
private final DynamicRuleService dynamicRuleService;
|
||||
private final TaskService taskService;
|
||||
@Autowired
|
||||
public AlertMessageTest(AlertMessageService alertMessageService) {
|
||||
public AlertMessageTest(AlertMessageService alertMessageService
|
||||
,ProtectObjectService protectObjectService,TemplateService templateService,
|
||||
DynamicRuleService dynamicRuleService,TaskService taskService) {
|
||||
this.alertMessageService = alertMessageService;
|
||||
this.protectObjectService = protectObjectService;
|
||||
this.templateService = templateService;
|
||||
this.dynamicRuleService = dynamicRuleService;
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReceiveAlertMessage() {
|
||||
/*
|
||||
for (int i = 1; i < 4; i++) {
|
||||
AlertMessage alertMessage = new AlertMessage();
|
||||
FiveTupleWithMask fiveTupleWithMask = new FiveTupleWithMask();
|
||||
fiveTupleWithMask.setSourceIP("1.1.1." + i);
|
||||
fiveTupleWithMask.setMaskSourceIP("255.255.255.0");
|
||||
fiveTupleWithMask.setDestinationIP("2.2.3." + i);
|
||||
fiveTupleWithMask.setMaskDestinationIP("255.255.255.255");
|
||||
fiveTupleWithMask.setSourcePort("80");
|
||||
fiveTupleWithMask.setDestinationPort("80");
|
||||
fiveTupleWithMask.setProtocol("TCP");
|
||||
|
||||
alertMessage.setTaskId(1937L);
|
||||
alertMessage.setFiveTupleWithMask(fiveTupleWithMask);
|
||||
alertMessage.setDynamicRuleId(31);
|
||||
alertMessageService.processAlertMessage(alertMessage);
|
||||
}
|
||||
*/
|
||||
List<ProtectObject> protectObject = protectObjectService.queryProtectObjects(null, null, 1, 1);
|
||||
List<Template> templates = templateService.queryTemplates(null, 1, 1);
|
||||
|
||||
DynamicRuleObject object = new DynamicRuleObject();
|
||||
object.setDynamicRuleName("UpdateDynamicRule2");
|
||||
object.setDynamicRuleFrequency(1);
|
||||
object.setDynamicRulePriority(1);
|
||||
object.setDynamicRuleRange("北京");
|
||||
object.setDynamicRuleProtectLevel(2);
|
||||
object.setTemplateId(templates.get(0).getTemplateId());
|
||||
object.setProtectObjectIds(List.of(new Integer[]{protectObject.get(0).getProtectObjectId()}));
|
||||
Integer dynamicRuleId = dynamicRuleService.newDynamicRuleObject(object);
|
||||
|
||||
|
||||
Task task = new Task();
|
||||
task.setTaskName("dong态测试2");
|
||||
LocalDateTime taskStartTime = LocalDateTime.now().plusMinutes(1);
|
||||
LocalDateTime taskEndTime = LocalDateTime.now().plusYears(5);
|
||||
task.setTaskStartTime(taskStartTime);
|
||||
task.setTaskEndTime(taskEndTime);
|
||||
task.setTaskAct("阻断");
|
||||
task.setTaskType(2);
|
||||
task.setTaskCreateUserId(1);
|
||||
task.setTaskCreateUsername("xxx");
|
||||
task.setTaskCreateDepart("xxx");
|
||||
task.setDynamicRuleIds(List.of(new Integer[]{dynamicRuleId}));
|
||||
|
||||
Long taskId = taskService.newTask(task);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user