Merge remote-tracking branch 'origin/haskafka' into haskafka
This commit is contained in:
@@ -5,6 +5,17 @@ import json
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import socket
|
||||
import struct
|
||||
|
||||
|
||||
def convert_ipv4_to_int(ip_str):
|
||||
binary_ip = socket.inet_aton(ip_str)
|
||||
# 使用 struct.unpack 解包二进制数据到一个大端整数
|
||||
ip_int = struct.unpack('!I', binary_ip)[0]
|
||||
return ip_int
|
||||
|
||||
|
||||
def convert_ipv4_address(ip_int):
|
||||
|
||||
return socket.inet_ntoa(struct.pack('!I', ip_int))
|
||||
@@ -31,6 +42,7 @@ def format_data_to_json(test_data):
|
||||
|
||||
src_ip_v4, dst_ip_v4, src_port_v4, dst_port_v4, protocol_v4 = parse_and_convert_ip(data_parts[1])
|
||||
|
||||
|
||||
formatted_data = {
|
||||
"task_id": 30650,
|
||||
"rule_id": 39,
|
||||
@@ -96,19 +108,26 @@ def kafka_send():
|
||||
if request.method == 'POST' and request.is_json:
|
||||
data = request.get_json()
|
||||
|
||||
base_data = "1702017420-1-175833107,1921297587-310737541-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
base_data = "1702017420-1-175833107,2682412653-760391609-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
base_data2 = "1702017420-1-175833107,760391609-2682412653-53420-6379-6-127-0,140717936336976-140717936336992-0-0-0-131-4481,0,000,440000,1,7,107,1,111,Amazon Data Services UK,0,0,440100,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,,9,10060101189,tcp.banner=$5115"
|
||||
|
||||
for item in data:
|
||||
task_id = item.get('task_id', '')
|
||||
rule_id = item.get('rule_id', '')
|
||||
modified_data = f"{base_data}, {task_id}, {rule_id},{0}"
|
||||
modified_data2 = f"{base_data2}, {task_id}, {rule_id},{0}"
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 65432
|
||||
print(modified_data)
|
||||
send_test_data(HOST, PORT, modified_data)
|
||||
send_test_data(HOST, PORT, modified_data2)
|
||||
|
||||
return jsonify({'message': 'Data processed successfully'}), 200
|
||||
return jsonify({"success": True, "code": 200}), 200
|
||||
|
||||
return jsonify({'error': 'Invalid request'}), 400
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0', port=8081, debug=True)
|
||||
print("convert_ipv4_to_int:", convert_ipv4_to_int("159.226.94.109"))
|
||||
print("convert_ipv4_to_int:", convert_ipv4_to_int("45.82.167.185"))
|
||||
app.run(host='0.0.0.0', port=8088, debug=True)
|
||||
@@ -100,5 +100,5 @@ def start_server(host, port, topic):
|
||||
if __name__ == "__main__":
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 65432
|
||||
TOPIC = 'topic-test'
|
||||
TOPIC = 'topic-alert'
|
||||
start_server(HOST, PORT, TOPIC)
|
||||
|
||||
@@ -60,5 +60,5 @@ public class WhiteListObject {
|
||||
@JsonProperty("audit_status")
|
||||
@ExcelIgnore
|
||||
@Schema(description = "白名单对象审核状态(0为未审核,1为已退回,2为审核通过)", example = "2")
|
||||
private String whiteListAuditStatus;
|
||||
private Integer whiteListAuditStatus;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class WhiteListService {
|
||||
throw new IllegalStateException("无法修改白名单信息,因为其并未处于" + AuditStatusEnum.AUDITED + "状态");
|
||||
}
|
||||
|
||||
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.toString());
|
||||
object.setWhiteListAuditStatus(AuditStatusEnum.PENDING.getNum());
|
||||
|
||||
return whiteListMapper.updateWhiteListObject(id, object);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
<result column="dynamic_rule_create_username" property="dynamicRuleCreateUsername"/>
|
||||
<result column="dynamic_rule_create_depart" property="dynamicRuleCreateDepart"/>
|
||||
<result column="template_id" property="templateId"/>
|
||||
<result column="dynamic_rule_protec_level" property="dynamicRuleProtectLevel"/>
|
||||
<result column="dynamic_rule_protect_level" property="dynamicRuleProtectLevel"/>
|
||||
<result column="dynamic_rule_priority" property="dynamicRulePriority"/>
|
||||
<result column="dynamic_rule_range" property="dynamicRuleRange"/>
|
||||
<result column="dynamic_rule_frequency" property="dynamicRuleFrequency"/>
|
||||
|
||||
@@ -67,7 +67,7 @@ class WhiteListServiceTest extends ProtectionApplicationTests {
|
||||
//object.setWhiteListId(7);
|
||||
object.setWhiteListName("test_update");
|
||||
|
||||
whiteListService.updateWhiteListObject(7, object);
|
||||
whiteListService.updateWhiteListObject(7189, object);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user