diff options
| author | unknown <[email protected]> | 2022-06-28 11:14:54 +0800 |
|---|---|---|
| committer | unknown <[email protected]> | 2022-06-28 11:14:54 +0800 |
| commit | ab8f6aba81615b4d744a161b580fcce417b7e209 (patch) | |
| tree | 4537606404438d5f4d036fc54b95cb802e377f9b | |
| parent | 94e8fb807a0ebbdca259cd82d71acbc251e1777e (diff) | |
修复动态获取nacos配置
| -rw-r--r-- | src/main/java/com/zdjizhi/etl/DosDetection.java | 24 | ||||
| -rw-r--r-- | src/main/java/com/zdjizhi/utils/NacosUtils.java | 1 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/main/java/com/zdjizhi/etl/DosDetection.java b/src/main/java/com/zdjizhi/etl/DosDetection.java index af5bafb..d1fdd21 100644 --- a/src/main/java/com/zdjizhi/etl/DosDetection.java +++ b/src/main/java/com/zdjizhi/etl/DosDetection.java @@ -85,9 +85,9 @@ public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> { private DosEventLog getDosEventLogBySensitivityThreshold(DosSketchLog value) { DosEventLog result = null; long sketchSessions = value.getSketch_sessions(); - if (sketchSessions > CommonConfig.STATIC_SENSITIVITY_THRESHOLD) { - long diff = sketchSessions - CommonConfig.STATIC_SENSITIVITY_THRESHOLD; - result = getDosEventLog(value, CommonConfig.STATIC_SENSITIVITY_THRESHOLD, diff, SENSITIVITY_CONDITION_TYPE, SESSIONS_TAG); + if (sketchSessions > NacosUtils.getIntProperty("static.sensitivity.threshold")) { + long diff = sketchSessions - NacosUtils.getIntProperty("static.sensitivity.threshold"); + result = getDosEventLog(value, NacosUtils.getIntProperty("static.sensitivity.threshold"), diff, SENSITIVITY_CONDITION_TYPE, SESSIONS_TAG); result.setSeverity(Severity.MAJOR.severity); } return result; @@ -98,7 +98,7 @@ public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> { String destinationIp = value.getDestination_ip(); String attackType = value.getAttack_type(); long sketchSessions = value.getSketch_sessions(); - if (sketchSessions > CommonConfig.STATIC_SENSITIVITY_THRESHOLD) { + if (sketchSessions > NacosUtils.getIntProperty("static.sensitivity.threshold")) { DosBaselineThreshold dosBaselineThreshold = baselineMap.get(destinationIp).get(attackType); Integer base = getBaseValue(dosBaselineThreshold, value); long diff = sketchSessions - base; @@ -132,7 +132,7 @@ public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> { double percent = getDiffPercent(diff, base); Severity severity = judgeSeverity(percent); if (severity != Severity.NORMAL) { - if (type == BASELINE_CONDITION_TYPE && percent < CommonConfig.BASELINE_SENSITIVITY_THRESHOLD) { + if (type == BASELINE_CONDITION_TYPE && percent < NacosUtils.getDoubleProperty("baseline.sensitivity.threshold")) { logger.debug("当前server IP:{},类型:{},基线值{}百分比{}未超过基线敏感阈值,日志详情\n{}", destinationIp, attackType, base, percent, value); } else { result = getResult(value, base, severity, percent+1, type, tag); @@ -178,8 +178,8 @@ public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> { logger.debug("获取到当前IP: {},类型: {} baseline值为0,替换为P95观测值{}", value.getDestination_ip(), value.getAttack_type(), defaultVaule); base = defaultVaule; } - if (sessionRateBaselineType == OTHER_BASELINE_TYPE && base < CommonConfig.STATIC_SENSITIVITY_THRESHOLD){ - base = CommonConfig.STATIC_SENSITIVITY_THRESHOLD; + if (sessionRateBaselineType == OTHER_BASELINE_TYPE && base < NacosUtils.getIntProperty("static.sensitivity.threshold")){ + base = NacosUtils.getIntProperty("static.sensitivity.threshold"); } } } @@ -261,15 +261,15 @@ public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> { } private Severity judgeSeverity(double diffPercent) { - if (diffPercent >= CommonConfig.BASELINE_SESSIONS_MINOR_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_WARNING_THRESHOLD) { + if (diffPercent >= NacosUtils.getDoubleProperty("baseline.sessions.minor.threshold") && diffPercent < NacosUtils.getDoubleProperty("baseline.sessions.warning.threshold")) { return Severity.MINOR; - } else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_WARNING_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_MAJOR_THRESHOLD) { + } else if (diffPercent >= NacosUtils.getDoubleProperty("baseline.sessions.warning.threshold") && diffPercent < NacosUtils.getDoubleProperty("baseline.sessions.major.threshold")) { return Severity.WARNING; - } else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_MAJOR_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_SEVERE_THRESHOLD) { + } else if (diffPercent >= NacosUtils.getDoubleProperty("baseline.sessions.major.threshold") && diffPercent < NacosUtils.getDoubleProperty("baseline.sessions.severe.threshold")) { return Severity.MAJOR; - } else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_SEVERE_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_CRITICAL_THRESHOLD) { + } else if (diffPercent >= NacosUtils.getDoubleProperty("baseline.sessions.severe.threshold") && diffPercent < NacosUtils.getDoubleProperty("baseline.sessions.critical.threshold")) { return Severity.SEVERE; - } else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_CRITICAL_THRESHOLD) { + } else if (diffPercent >= NacosUtils.getDoubleProperty("baseline.sessions.critical.threshold")) { return Severity.CRITICAL; } else { return Severity.NORMAL; diff --git a/src/main/java/com/zdjizhi/utils/NacosUtils.java b/src/main/java/com/zdjizhi/utils/NacosUtils.java index 5dd753c..cdefd95 100644 --- a/src/main/java/com/zdjizhi/utils/NacosUtils.java +++ b/src/main/java/com/zdjizhi/utils/NacosUtils.java @@ -53,6 +53,7 @@ public class NacosUtils { @Override public void receiveConfigInfo(String configMsg) { try { + commonProperties.clear(); commonProperties.load(new StringReader(configMsg)); } catch (IOException e) { logger.error("监听nacos配置失败", e); |
