DoS 检测支持vsys id
This commit is contained in:
@@ -113,6 +113,7 @@ public class ParseStaticThreshold {
|
||||
HashMap<String, Object> parms = new HashMap<>();
|
||||
parms.put("pageSize", -1);
|
||||
parms.put("orderBy", "vsysId desc");
|
||||
parms.put("type", 1);
|
||||
HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_POLICY_VSYSID_PATH, parms);
|
||||
String token = NacosUtils.getStringProperty("bifang.server.token");
|
||||
if (!HttpClientUtils.ERROR_MESSAGE.equals(token)) {
|
||||
@@ -128,7 +129,7 @@ public class ParseStaticThreshold {
|
||||
Object list = data.get("list");
|
||||
if (list != null) {
|
||||
vsysIdList = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), vsysIDType);
|
||||
logger.info("获取到vsysId{}条", vsysIdList.size());
|
||||
logger.info("获取到vsysId {}条", vsysIdList.size());
|
||||
} else {
|
||||
logger.warn("vsysIdList为空");
|
||||
}
|
||||
@@ -149,49 +150,54 @@ public class ParseStaticThreshold {
|
||||
* @return thresholds
|
||||
*/
|
||||
private static ArrayList<DosDetectionThreshold> getDosDetectionThreshold() {
|
||||
ArrayList<DosDetectionThreshold> thresholds = null;
|
||||
// ArrayList<DosVsysId> vsysId = getVsysId();
|
||||
ArrayList<DosDetectionThreshold> vsysThresholds = new ArrayList<>();
|
||||
ArrayList<DosVsysId> vsysIds = getVsysId();
|
||||
try {
|
||||
// if (vsysId != null){
|
||||
// for (DosVsysId dosVsysId : vsysId) {
|
||||
URIBuilder uriBuilder = new URIBuilder(CommonConfig.BIFANG_SERVER_URI);
|
||||
HashMap<String, Object> parms = new HashMap<>();
|
||||
parms.put("pageSize", -1);
|
||||
parms.put("orderBy", "profileId asc");
|
||||
parms.put("isValid", 1);
|
||||
// parms.put("vsysId", dosVsysId.getVsysId());
|
||||
parms.put("vsysId", 1);
|
||||
HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_POLICY_THRESHOLD_PATH, parms);
|
||||
String token = NacosUtils.getStringProperty("bifang.server.token");
|
||||
if (!HttpClientUtils.ERROR_MESSAGE.equals(token)) {
|
||||
BasicHeader authorization = new BasicHeader("Authorization", token);
|
||||
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<String, Object> resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType);
|
||||
boolean success = (boolean) resposeMap.get("success");
|
||||
String msg = resposeMap.get("msg").toString();
|
||||
if (success) {
|
||||
HashMap<String, Object> data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType);
|
||||
Object list = data.get("list");
|
||||
if (list != null) {
|
||||
thresholds = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), thresholdType);
|
||||
logger.info("获取到静态阈值配置{}条", thresholds.size());
|
||||
} else {
|
||||
logger.warn("静态阈值配置为空");
|
||||
if (vsysIds != null) {
|
||||
for (DosVsysId dosVsysId : vsysIds) {
|
||||
Integer vsysId = dosVsysId.getId();
|
||||
Integer[] superiorIds = dosVsysId.getSuperiorIds();
|
||||
URIBuilder uriBuilder = new URIBuilder(CommonConfig.BIFANG_SERVER_URI);
|
||||
HashMap<String, Object> parms = new HashMap<>();
|
||||
parms.put("pageSize", -1);
|
||||
parms.put("orderBy", "profileId asc");
|
||||
parms.put("isValid", 1);
|
||||
parms.put("vsysId", vsysId);
|
||||
HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_POLICY_THRESHOLD_PATH, parms);
|
||||
String token = NacosUtils.getStringProperty("bifang.server.token");
|
||||
if (!HttpClientUtils.ERROR_MESSAGE.equals(token)) {
|
||||
BasicHeader authorization = new BasicHeader("Authorization", token);
|
||||
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<String, Object> resposeMap = jsonMapperInstance.fromJson(resposeJsonStr, hashmapJsonType);
|
||||
boolean success = (boolean) resposeMap.get("success");
|
||||
String msg = resposeMap.get("msg").toString();
|
||||
if (success) {
|
||||
HashMap<String, Object> data = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(resposeMap.get("data")), hashmapJsonType);
|
||||
Object list = data.get("list");
|
||||
if (list != null) {
|
||||
ArrayList<DosDetectionThreshold> thresholds = jsonMapperInstance.fromJson(jsonMapperInstance.toJson(list), thresholdType);
|
||||
for (DosDetectionThreshold dosDetectionThreshold:thresholds){
|
||||
dosDetectionThreshold.setSuperiorIds(superiorIds);
|
||||
vsysThresholds.add(dosDetectionThreshold);
|
||||
}
|
||||
logger.info("获取到vsys id是{}静态阈值配置{}条",vsysId, thresholds.size());
|
||||
} else {
|
||||
logger.warn("静态阈值配置为空");
|
||||
}
|
||||
} else {
|
||||
logger.error(msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.error(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
logger.error("获取静态阈值配置失败,请检查bifang服务或登录配置信息 ", e);
|
||||
}
|
||||
|
||||
return thresholds;
|
||||
return vsysThresholds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,14 +205,17 @@ public class ParseStaticThreshold {
|
||||
*
|
||||
* @return threshold RangeMap
|
||||
*/
|
||||
static HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> createStaticThreshold() {
|
||||
HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> thresholdRangeMap = new HashMap<>(4);
|
||||
static HashMap<Integer,HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>>> createStaticThreshold() {
|
||||
HashMap<Integer,HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>>> thresholdRangeMap = new HashMap<>(4);
|
||||
try {
|
||||
ArrayList<DosDetectionThreshold> dosDetectionThreshold = getDosDetectionThreshold();
|
||||
if (dosDetectionThreshold != null && !dosDetectionThreshold.isEmpty()) {
|
||||
for (DosDetectionThreshold threshold : dosDetectionThreshold) {
|
||||
String attackType = threshold.getAttackType();
|
||||
TreeRangeMap<IPAddress, DosDetectionThreshold> treeRangeMap = thresholdRangeMap.getOrDefault(attackType, TreeRangeMap.create());
|
||||
int vsysId = threshold.getVsysId();
|
||||
HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> rangeMap = thresholdRangeMap.getOrDefault(vsysId, new HashMap<>());
|
||||
|
||||
TreeRangeMap<IPAddress, DosDetectionThreshold> treeRangeMap = rangeMap.getOrDefault(attackType, TreeRangeMap.create());
|
||||
ArrayList<String> serverIpList = threshold.getServerIpList();
|
||||
for (String sip : serverIpList) {
|
||||
IPAddressString ipAddressString = new IPAddressString(sip);
|
||||
@@ -239,7 +248,8 @@ public class ParseStaticThreshold {
|
||||
}
|
||||
}
|
||||
}
|
||||
thresholdRangeMap.put(attackType, treeRangeMap);
|
||||
rangeMap.put(attackType, treeRangeMap);
|
||||
thresholdRangeMap.put(vsysId,rangeMap);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -249,22 +259,27 @@ public class ParseStaticThreshold {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
ArrayList<DosDetectionThreshold> dosDetectionThreshold = getDosDetectionThreshold();
|
||||
dosDetectionThreshold.forEach(System.out::println);
|
||||
|
||||
|
||||
// dosDetectionThreshold.forEach(System.out::println);
|
||||
getVsysId().forEach(System.out::println);
|
||||
System.out.println("------------------------");
|
||||
HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> staticThreshold = createStaticThreshold();
|
||||
*/
|
||||
HashMap<Integer,HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>>> staticThreshold = createStaticThreshold();
|
||||
|
||||
System.out.println("------------------------");
|
||||
|
||||
for (String type : staticThreshold.keySet()) {
|
||||
Map<Range<IPAddress>, DosDetectionThreshold> asMapOfRanges = staticThreshold.get(type).asMapOfRanges();
|
||||
for (Range<IPAddress> range : asMapOfRanges.keySet()) {
|
||||
DosDetectionThreshold threshold = asMapOfRanges.get(range);
|
||||
System.out.println(type + "---" + range + "---" + threshold);
|
||||
for (Integer integer : staticThreshold.keySet()){
|
||||
HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> stringTreeRangeMapHashMap = staticThreshold.get(integer);
|
||||
for (String type : stringTreeRangeMapHashMap.keySet()) {
|
||||
Map<Range<IPAddress>, DosDetectionThreshold> asMapOfRanges = stringTreeRangeMapHashMap.get(type).asMapOfRanges();
|
||||
for (Range<IPAddress> range : asMapOfRanges.keySet()) {
|
||||
DosDetectionThreshold threshold = asMapOfRanges.get(range);
|
||||
System.out.println(integer+"---"+type + "---" + range + "---" + threshold);
|
||||
}
|
||||
System.out.println("------------------------");
|
||||
}
|
||||
System.out.println("------------------------");
|
||||
|
||||
}
|
||||
// String s = loginBifangServer();
|
||||
// System.out.println(s);
|
||||
|
||||
Reference in New Issue
Block a user