diff --git a/src/main/java/com/zdjizhi/etl/ParseSketchLog.java b/src/main/java/com/zdjizhi/etl/ParseSketchLog.java index 65d16e5..6731beb 100644 --- a/src/main/java/com/zdjizhi/etl/ParseSketchLog.java +++ b/src/main/java/com/zdjizhi/etl/ParseSketchLog.java @@ -1,11 +1,12 @@ package com.zdjizhi.etl; +import com.alibaba.fastjson2.JSONObject; import com.fasterxml.jackson.databind.JavaType; import com.zdjizhi.common.CommonConfig; import com.zdjizhi.common.DosSketchLog; import com.zdjizhi.source.DosSketchSource; import com.zdjizhi.utils.FlinkEnvironmentUtils; -import com.zdjizhi.utils.JsonMapper; +//import com.zdjizhi.utils.JsonMapper; import com.zdjizhi.utils.StringUtil; import org.apache.flink.api.common.eventtime.WatermarkStrategy; import org.apache.flink.api.common.functions.FlatMapFunction; @@ -23,9 +24,9 @@ import java.util.*; public class ParseSketchLog { private static Logger logger = LoggerFactory.getLogger(ParseSketchLog.class); - private static JsonMapper jsonMapperInstance = JsonMapper.getInstance(); - private static JavaType hashmapJsonType = jsonMapperInstance.createCollectionType(HashMap.class, String.class, Object.class); - private static JavaType listType = jsonMapperInstance.createCollectionType(ArrayList.class, HashMap.class); +// private static JsonMapper jsonMapperInstance = JsonMapper.getInstance(); +// private static JavaType hashmapJsonType = jsonMapperInstance.createCollectionType(HashMap.class, String.class, Object.class); +// private static JavaType listType = jsonMapperInstance.createCollectionType(ArrayList.class, HashMap.class); public static SingleOutputStreamOperator getSketchSource(){ @@ -47,12 +48,15 @@ public class ParseSketchLog { public void flatMap(String s, Collector collector) { try { if (StringUtil.isNotBlank(s)){ - HashMap sketchSource = jsonMapperInstance.fromJson(s, hashmapJsonType); + HashMap sketchSource = JSONObject.parseObject(s, HashMap.class); +// HashMap sketchSource = jsonMapperInstance.fromJson(s, hashmapJsonType); long sketchStartTime = Long.parseLong(sketchSource.get("sketch_start_time").toString()); long sketchDuration = Long.parseLong(sketchSource.get("sketch_duration").toString()); String attackType = sketchSource.get("attack_type").toString(); int vsysId = Integer.parseInt(sketchSource.getOrDefault("common_vsys_id", 1).toString()); - ArrayList> reportIpList = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(sketchSource.get("report_ip_list")), listType); + String report_ip_list = JSONObject.toJSONString(sketchSource.get("report_ip_list")); + ArrayList> reportIpList = JSONObject.parseObject(report_ip_list, ArrayList.class); +// ArrayList> reportIpList = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(sketchSource.get("report_ip_list")), listType); for (HashMap obj : reportIpList) { DosSketchLog dosSketchLog = new DosSketchLog(); dosSketchLog.setSketch_start_time(sketchStartTime); diff --git a/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java b/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java index 8c40ed8..5fd4fa3 100644 --- a/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java +++ b/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java @@ -2,12 +2,14 @@ package com.zdjizhi.etl; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; -import com.fasterxml.jackson.databind.JavaType; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +//import com.fasterxml.jackson.databind.JavaType; import com.zdjizhi.common.CommonConfig; import com.zdjizhi.common.DosDetectionThreshold; import com.zdjizhi.common.DosVsysId; import com.zdjizhi.utils.HttpClientUtils; -import com.zdjizhi.utils.JsonMapper; +//import com.zdjizhi.utils.JsonMapper; import com.zdjizhi.utils.NacosUtils; import inet.ipaddr.IPAddress; import inet.ipaddr.IPAddressString; @@ -19,6 +21,7 @@ import org.apache.http.message.BasicHeader; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -29,10 +32,10 @@ public class ParseStaticThreshold { private static final Log logger = LogFactory.get(); private static String encryptpwd; - private static JsonMapper jsonMapperInstance = JsonMapper.getInstance(); - private static JavaType hashmapJsonType = jsonMapperInstance.createCollectionType(HashMap.class, String.class, Object.class); - private static JavaType thresholdType = jsonMapperInstance.createCollectionType(ArrayList.class, DosDetectionThreshold.class); - private static JavaType vsysIDType = jsonMapperInstance.createCollectionType(ArrayList.class, DosVsysId.class); +// private static JsonMapper jsonMapperInstance = JsonMapper.getInstance(); +// private static JavaType hashmapJsonType = jsonMapperInstance.createCollectionType(HashMap.class, String.class, Object.class); +// private static JavaType thresholdType = jsonMapperInstance.createCollectionType(ArrayList.class, DosDetectionThreshold.class); +// private static JavaType vsysIDType = jsonMapperInstance.createCollectionType(ArrayList.class, DosVsysId.class); static { //加载加密登录密码 @@ -51,11 +54,14 @@ public class ParseStaticThreshold { HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_ENCRYPTPWD_PATH, parms); String resposeJsonStr = HttpClientUtils.httpGet(uriBuilder.build()); if (!HttpClientUtils.ERROR_MESSAGE.equals(resposeJsonStr)) { - HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); + HashMap resposeMap = JSONObject.parseObject(resposeJsonStr, HashMap.class); +// HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); boolean success = (boolean) resposeMap.get("success"); String msg = resposeMap.get("msg").toString(); + if (success) { - HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); + HashMap data = JSONObject.parseObject(JSONObject.toJSONString(resposeMap.get("data")), HashMap.class); +// HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); psw = data.get("encryptpwd").toString(); } else { logger.error(msg); @@ -85,11 +91,13 @@ public class ParseStaticThreshold { HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_LOGIN_PATH, parms); String resposeJsonStr = HttpClientUtils.httpPost(uriBuilder.build(), null); if (!HttpClientUtils.ERROR_MESSAGE.equals(resposeJsonStr)) { - HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); + HashMap resposeMap = JSONObject.parseObject(resposeJsonStr, HashMap.class); +// HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); boolean success = (boolean) resposeMap.get("success"); String msg = resposeMap.get("msg").toString(); if (success) { - HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); + HashMap data = JSONObject.parseObject(JSONObject.toJSONString(resposeMap.get("data")), HashMap.class); +// HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); token = data.get("token").toString(); } else { logger.error(msg); @@ -122,14 +130,21 @@ public class ParseStaticThreshold { BasicHeader authorization1 = new BasicHeader("Content-Type", "application/x-www-form-urlencoded"); String resposeJsonStr = HttpClientUtils.httpGet(uriBuilder.build(), authorization, authorization1); if (!HttpClientUtils.ERROR_MESSAGE.equals(resposeJsonStr)) { - HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); + HashMap resposeMap = JSONObject.parseObject(resposeJsonStr, HashMap.class); +// HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); boolean success = (boolean) resposeMap.get("success"); String msg = resposeMap.get("msg").toString(); if (success) { - HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); + HashMap data = JSONObject.parseObject(JSONObject.toJSONString(resposeMap.get("data")), HashMap.class); +// HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); Object list = data.get("list"); if (list != null) { - vsysIdList = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), vsysIDType); + String s = JSONObject.toJSONString(list); + List dosVsysIds = JSON.parseArray(JSONObject.toJSONString(list), DosVsysId.class); +// vsysIdList= JSONObject.parseObject(JSONObject.toJSONString(list), DosVsysId.class); + vsysIdList= (ArrayList)dosVsysIds; + +// vsysIdList = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), vsysIDType); logger.info("获取到vsysId {}条", vsysIdList.size()); } else { logger.warn("vsysIdList为空"); @@ -171,14 +186,19 @@ public class ParseStaticThreshold { BasicHeader authorization1 = new BasicHeader("Content-Type", "application/x-www-form-urlencoded"); String resposeJsonStr = HttpClientUtils.httpGet(uriBuilder.build(), authorization, authorization1); if (!HttpClientUtils.ERROR_MESSAGE.equals(resposeJsonStr)) { - HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); +// HashMap resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType); + HashMap resposeMap = JSONObject.parseObject(resposeJsonStr,HashMap.class); boolean success = (boolean) resposeMap.get("success"); String msg = resposeMap.get("msg").toString(); if (success) { - HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); +// HashMap data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType); + HashMap data = JSONObject.parseObject(JSONObject.toJSONString(resposeMap.get("data")), HashMap.class); Object list = data.get("list"); if (list != null) { - ArrayList thresholds = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), thresholdType); +// ArrayList thresholds = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), thresholdType); +// ArrayList thresholds = JSONObject.parseObject(JSONObject.toJSONString(list), ArrayList.class); + List dosDetectionThresholds = JSON.parseArray(JSONObject.toJSONString(list), DosDetectionThreshold.class); + ArrayList thresholds = (ArrayList)dosDetectionThresholds; for (DosDetectionThreshold dosDetectionThreshold : thresholds) { dosDetectionThreshold.setSuperiorIds(superiorIds); vsysThresholds.add(dosDetectionThreshold);