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