解决修改序列化方式之后产生的null值问题

This commit is contained in:
wangkuan
2024-08-09 18:23:27 +08:00
parent 2d0dcf89e3
commit c08b94fec2
6 changed files with 25 additions and 19 deletions

View File

@@ -244,7 +244,7 @@ public class DosSketchLog implements Serializable {
}
public int getRule_id() {
public int getRule_id() {
return rule_id;
}

View File

@@ -58,7 +58,10 @@ public class DosMetricsRichFunction extends RichFlatMapFunction<DosSketchLog, St
}
private int getPartitionNumByIp(String destinationIp) {
return Math.abs(destinationIp.hashCode()) % configuration.get(DESTINATION_IP_PARTITION_NUM);
if(destinationIp!=null){
return Math.abs(destinationIp.hashCode()) % configuration.get(DESTINATION_IP_PARTITION_NUM);
}
return 0;
}
}

View File

@@ -24,13 +24,20 @@ public class FlatSketchFunction implements FlatMapFunction<String, DosSketchLog>
DosSketchLog dosSketchLog = JSONObject.parseObject(value, DosSketchLog.class);
dosSketchLog.setRecv_time(System.currentTimeMillis()/1000);
dosSketchLog.setStart_timestamp_ms(dosSketchLog.getTimestamp_ms());
if(dosSketchLog.getDuration()<=0){
dosSketchLog.setDuration(60000);
}
dosSketchLog.setEnd_timestamp_ms(dosSketchLog.getTimestamp_ms() + dosSketchLog.getDuration());
HashSet<String> client_ips = new HashSet<>();
HashSet<String> client_countrys = new HashSet<>();
dosSketchLog.setClient_ips(client_ips);
dosSketchLog.setClient_countrys(client_countrys);
if("top_client_and_server_ip".equals(dosSketchLog.getName())){
client_ips.add(dosSketchLog.getClient_ip());
dosSketchLog.setDecoded_as("");
if(dosSketchLog.getClient_ip()!=null) {
client_ips.add(dosSketchLog.getClient_ip());
}
if(dosSketchLog.getClient_country()!=null && !dosSketchLog.getClient_country().isEmpty()) {
client_countrys.add(dosSketchLog.getClient_country());
}
@@ -39,7 +46,9 @@ public class FlatSketchFunction implements FlatMapFunction<String, DosSketchLog>
dosSketchLog.setPkts(0);
dosSketchLog.setBytes(0);
dosSketchLog.setSessions(0);
client_ips.add(dosSketchLog.getClient_ip());
if(dosSketchLog.getClient_ip()!=null) {
client_ips.add(dosSketchLog.getClient_ip());
}
if(dosSketchLog.getClient_country()!=null && !dosSketchLog.getClient_country().isEmpty()) {
client_countrys.add(dosSketchLog.getClient_country());
}

View File

@@ -45,7 +45,7 @@ public class MetricsCalculate extends ProcessWindowFunction<
dosSketchLog.setSession_rate(dosSketchLog.getSessions()/ (duration/1000) );
dosSketchLog.setPacket_rate(dosSketchLog.getPkts()/(duration/1000));
dosSketchLog.setBit_rate(dosSketchLog.getBytes()*8/(duration/1000));
dosSketchLog.setAttack_type(attackTypeMapping.getOrDefault(dosSketchLog.getDecoded_as(),""));
dosSketchLog.setAttack_type(attackTypeMapping.get(dosSketchLog.getDecoded_as()));
}catch (RuntimeException e){
logger.error(e.toString());
}