summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/net/geedge/asw/module/runner/util/PcapParserThread.java32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/main/java/net/geedge/asw/module/runner/util/PcapParserThread.java b/src/main/java/net/geedge/asw/module/runner/util/PcapParserThread.java
index 8dcbcba..527443f 100644
--- a/src/main/java/net/geedge/asw/module/runner/util/PcapParserThread.java
+++ b/src/main/java/net/geedge/asw/module/runner/util/PcapParserThread.java
@@ -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())