fix: 补充提交

This commit is contained in:
shizhendong
2024-07-30 14:00:25 +08:00
parent 4a2d7f9adf
commit b5af3de27d

View File

@@ -7,8 +7,9 @@ import net.geedge.asw.common.config.SpringContextUtils;
import net.geedge.asw.common.util.T; import net.geedge.asw.common.util.T;
import net.geedge.asw.module.runner.entity.PcapEntity; import net.geedge.asw.module.runner.entity.PcapEntity;
import net.geedge.asw.module.runner.service.IPcapService; import net.geedge.asw.module.runner.service.IPcapService;
import org.apache.commons.lang3.time.StopWatch;
import java.io.File; import static net.geedge.asw.module.runner.util.RunnerConstant.PcapStatus;
@Data @Data
public class PcapParserThread implements Runnable { public class PcapParserThread implements Runnable {
@@ -20,8 +21,6 @@ public class PcapParserThread implements Runnable {
private void init() { private void init() {
pcapService = SpringContextUtils.getBean(IPcapService.class); pcapService = SpringContextUtils.getBean(IPcapService.class);
// analyzing
this.updatePcapStatus(RunnerConstant.PcapStatus.ANALYZING.getValue());
} }
@Override @Override
@@ -31,19 +30,28 @@ public class PcapParserThread implements Runnable {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("pcapInfo: {}", T.JSONUtil.toJsonStr(pcapEntity)); log.debug("pcapInfo: {}", T.JSONUtil.toJsonStr(pcapEntity));
} }
StopWatch sw = new StopWatch();
sw.start();
try { try {
log.info("job pcap parser run start"); log.info("job pcap parser run start");
// init // init
this.init(); this.init();
// parsing
this.updateStatus(PcapStatus.PARSING.getValue());
// parser // parser
this.parser(); this.parser();
// indexed
this.updateStatus(PcapStatus.INDEXED.getValue());
log.info("job pcap parser run end"); log.info("job pcap parser run end");
} catch (Exception e) { } catch (Exception e) {
// error
this.updateStatus(PcapStatus.ERROR.getValue());
log.error(e, "job pcap parser error, pcap: {}", pcapEntity.getId()); log.error(e, "job pcap parser error, pcap: {}", pcapEntity.getId());
} finally { } finally {
// completed sw.stop();
this.updatePcapStatus(RunnerConstant.PcapStatus.COMPLETED.getValue()); log.info("job pcap parser end. Run Time: {}", sw.toString());
log.info("job pcap parser end");
} }
} }
@@ -53,25 +61,15 @@ public class PcapParserThread implements Runnable {
private void parser() { private void parser() {
String id = pcapEntity.getId(); String id = pcapEntity.getId();
String path = pcapEntity.getPath(); String path = pcapEntity.getPath();
SignatureExtract signatureExtract = new SignatureExtract(id, path);
// signature
String signature = signatureExtract.signature();
// 保存结果,和 pcap 文件同目录文件名pcap_id_signature.json
String parentPath = T.FileUtil.getParent(path, 1);
File signatureFile = T.FileUtil.file(parentPath, id + "_signature.json");
T.FileUtil.del(signatureFile);
T.FileUtil.writeUtf8String(signature, signatureFile);
// TODO // TODO
} }
/** /**
* update pcap status * update pcap status
* *
* @param status * @param status
*/ */
private void updatePcapStatus(String status) { private void updateStatus(String status) {
pcapService.update(new LambdaUpdateWrapper<PcapEntity>() pcapService.update(new LambdaUpdateWrapper<PcapEntity>()
.set(PcapEntity::getStatus, status) .set(PcapEntity::getStatus, status)
.eq(PcapEntity::getId, pcapEntity.getId()) .eq(PcapEntity::getId, pcapEntity.getId())