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.module.runner.entity.PcapEntity;
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
public class PcapParserThread implements Runnable {
@@ -20,8 +21,6 @@ public class PcapParserThread implements Runnable {
private void init() {
pcapService = SpringContextUtils.getBean(IPcapService.class);
// analyzing
this.updatePcapStatus(RunnerConstant.PcapStatus.ANALYZING.getValue());
}
@Override
@@ -31,19 +30,28 @@ public class PcapParserThread implements Runnable {
if (log.isDebugEnabled()) {
log.debug("pcapInfo: {}", T.JSONUtil.toJsonStr(pcapEntity));
}
StopWatch sw = new StopWatch();
sw.start();
try {
log.info("job pcap parser run start");
// init
this.init();
// parsing
this.updateStatus(PcapStatus.PARSING.getValue());
// parser
this.parser();
// indexed
this.updateStatus(PcapStatus.INDEXED.getValue());
log.info("job pcap parser run end");
} catch (Exception e) {
// error
this.updateStatus(PcapStatus.ERROR.getValue());
log.error(e, "job pcap parser error, pcap: {}", pcapEntity.getId());
} finally {
// completed
this.updatePcapStatus(RunnerConstant.PcapStatus.COMPLETED.getValue());
log.info("job pcap parser end");
sw.stop();
log.info("job pcap parser end. Run Time: {}", sw.toString());
}
}
@@ -53,25 +61,15 @@ public class PcapParserThread implements Runnable {
private void parser() {
String id = pcapEntity.getId();
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
}
/**
* update pcap status
*
* @param status
*/
private void updatePcapStatus(String status) {
private void updateStatus(String status) {
pcapService.update(new LambdaUpdateWrapper<PcapEntity>()
.set(PcapEntity::getStatus, status)
.eq(PcapEntity::getId, pcapEntity.getId())