2021-07-29 10:02:31 +08:00
|
|
|
|
package com.zdjizhi.etl;
|
|
|
|
|
|
|
2021-10-21 18:27:48 +08:00
|
|
|
|
import com.zdjizhi.common.*;
|
2021-10-19 18:39:13 +08:00
|
|
|
|
import com.zdjizhi.utils.*;
|
2021-08-20 18:34:40 +08:00
|
|
|
|
import inet.ipaddr.IPAddress;
|
|
|
|
|
|
import inet.ipaddr.IPAddressString;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
2021-10-19 18:39:13 +08:00
|
|
|
|
import org.apache.commons.lang.text.StrBuilder;
|
2021-08-24 16:35:31 +08:00
|
|
|
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
2021-08-05 18:42:34 +08:00
|
|
|
|
import org.apache.flink.api.common.functions.RichMapFunction;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
import org.apache.flink.configuration.Configuration;
|
2021-08-20 18:34:40 +08:00
|
|
|
|
import org.apache.flink.shaded.guava18.com.google.common.collect.TreeRangeMap;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
2021-08-26 18:42:28 +08:00
|
|
|
|
import java.math.BigDecimal;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
import java.text.NumberFormat;
|
2021-08-05 18:42:34 +08:00
|
|
|
|
import java.util.*;
|
2021-08-24 16:35:31 +08:00
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
|
2021-08-16 18:24:13 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @author wlh
|
|
|
|
|
|
*/
|
2021-08-05 18:42:34 +08:00
|
|
|
|
public class DosDetection extends RichMapFunction<DosSketchLog, DosEventLog> {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DosDetection.class);
|
2021-10-21 18:27:48 +08:00
|
|
|
|
private static Map<String, Map<String, DosBaselineThreshold>> baselineMap = new HashMap<>();
|
2021-07-30 10:55:01 +08:00
|
|
|
|
private final static NumberFormat PERCENT_INSTANCE = NumberFormat.getPercentInstance();
|
2021-10-20 18:23:12 +08:00
|
|
|
|
private HashMap<String, TreeRangeMap<IPAddress, DosDetectionThreshold>> thresholdRangeMap;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
|
2021-10-21 18:27:48 +08:00
|
|
|
|
private final static int BASELINE_SIZE = 144;
|
|
|
|
|
|
private final static int STATIC_CONDITION_TYPE = 1;
|
|
|
|
|
|
private final static int BASELINE_CONDITION_TYPE = 2;
|
|
|
|
|
|
private final static int SENSITIVITY_CONDITION_TYPE = 3;
|
|
|
|
|
|
|
2021-07-29 10:02:31 +08:00
|
|
|
|
@Override
|
2021-08-18 19:15:49 +08:00
|
|
|
|
public void open(Configuration parameters) {
|
2021-08-24 16:35:31 +08:00
|
|
|
|
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(2,
|
|
|
|
|
|
new BasicThreadFactory.Builder().namingPattern("Dos-Detection-%d").daemon(true).build());
|
|
|
|
|
|
try {
|
2021-09-23 18:36:27 +08:00
|
|
|
|
executorService.scheduleAtFixedRate(() -> thresholdRangeMap = ParseStaticThreshold.createStaticThreshold(), 0,
|
|
|
|
|
|
CommonConfig.STATIC_THRESHOLD_SCHEDULE_MINUTES, TimeUnit.MINUTES);
|
2021-08-24 16:35:31 +08:00
|
|
|
|
|
2021-10-21 18:27:48 +08:00
|
|
|
|
executorService.scheduleAtFixedRate(() -> baselineMap = ParseBaselineThreshold.readFromHbase(), 0,
|
2021-09-23 18:36:27 +08:00
|
|
|
|
CommonConfig.BASELINE_THRESHOLD_SCHEDULE_DAYS, TimeUnit.DAYS);
|
2021-08-24 16:35:31 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("定时器任务执行失败", e);
|
|
|
|
|
|
}
|
2021-07-30 10:55:01 +08:00
|
|
|
|
PERCENT_INSTANCE.setMinimumFractionDigits(2);
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-08-18 19:15:49 +08:00
|
|
|
|
public DosEventLog map(DosSketchLog value) {
|
2021-08-20 18:34:40 +08:00
|
|
|
|
DosEventLog finalResult = null;
|
2021-07-30 10:55:01 +08:00
|
|
|
|
try {
|
|
|
|
|
|
String destinationIp = value.getDestination_ip();
|
|
|
|
|
|
String attackType = value.getAttack_type();
|
2021-08-20 18:34:40 +08:00
|
|
|
|
IPAddress destinationIpAddress = new IPAddressString(destinationIp).getAddress();
|
2021-10-20 18:23:12 +08:00
|
|
|
|
DosDetectionThreshold threshold = thresholdRangeMap.getOrDefault(attackType, TreeRangeMap.create()).get(destinationIpAddress);
|
2021-08-18 19:15:49 +08:00
|
|
|
|
logger.debug("当前判断IP:{}, 类型: {}", destinationIp, attackType);
|
2021-10-20 18:23:12 +08:00
|
|
|
|
if (threshold == null && baselineMap.containsKey(destinationIp)) {
|
2021-09-23 18:36:27 +08:00
|
|
|
|
finalResult = getDosEventLogByBaseline(value);
|
2021-10-20 18:23:12 +08:00
|
|
|
|
} else if (threshold == null && !baselineMap.containsKey(destinationIp)) {
|
2021-09-14 18:46:23 +08:00
|
|
|
|
finalResult = getDosEventLogBySensitivityThreshold(value);
|
2021-10-20 18:23:12 +08:00
|
|
|
|
} else if (threshold != null) {
|
|
|
|
|
|
finalResult = getDosEventLogByStaticThreshold(value, threshold);
|
2021-10-19 18:39:13 +08:00
|
|
|
|
} else {
|
2021-08-20 18:34:40 +08:00
|
|
|
|
logger.debug("未获取到当前server IP:{} 类型 {} 静态阈值 和 baseline", destinationIp, attackType);
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
2021-08-24 16:35:31 +08:00
|
|
|
|
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("判定失败\n {} \n{}", value, e);
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
2021-08-20 18:34:40 +08:00
|
|
|
|
return finalResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-19 18:39:13 +08:00
|
|
|
|
private DosEventLog getDosEventLogBySensitivityThreshold(DosSketchLog value) {
|
2021-09-14 18:46:23 +08:00
|
|
|
|
DosEventLog result = null;
|
|
|
|
|
|
long sketchSessions = value.getSketch_sessions();
|
2021-10-19 18:39:13 +08:00
|
|
|
|
if (sketchSessions > CommonConfig.STATIC_SENSITIVITY_THRESHOLD) {
|
|
|
|
|
|
result = getDosEventLog(value, CommonConfig.STATIC_SENSITIVITY_THRESHOLD, sketchSessions - CommonConfig.STATIC_SENSITIVITY_THRESHOLD, 3, "sessions");
|
2021-09-14 18:46:23 +08:00
|
|
|
|
result.setSeverity(Severity.MAJOR.severity);
|
2021-08-24 16:35:31 +08:00
|
|
|
|
}
|
2021-09-14 18:46:23 +08:00
|
|
|
|
return result;
|
2021-08-20 18:34:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-23 18:36:27 +08:00
|
|
|
|
private DosEventLog getDosEventLogByBaseline(DosSketchLog value) {
|
2021-09-14 18:46:23 +08:00
|
|
|
|
DosEventLog result = null;
|
2021-09-23 18:36:27 +08:00
|
|
|
|
String destinationIp = value.getDestination_ip();
|
|
|
|
|
|
String attackType = value.getAttack_type();
|
2021-09-09 10:46:50 +08:00
|
|
|
|
long sketchSessions = value.getSketch_sessions();
|
2021-10-19 18:39:13 +08:00
|
|
|
|
if (sketchSessions > CommonConfig.STATIC_SENSITIVITY_THRESHOLD) {
|
2021-10-21 18:27:48 +08:00
|
|
|
|
DosBaselineThreshold dosBaselineThreshold = baselineMap.get(destinationIp).get(attackType);
|
|
|
|
|
|
Integer base = getBaseValue(dosBaselineThreshold, value);
|
2021-10-19 18:39:13 +08:00
|
|
|
|
result = getDosEventLog(value, base, sketchSessions - base, 2, "sessions");
|
2021-09-14 18:46:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
return result;
|
2021-08-20 18:34:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-20 18:23:12 +08:00
|
|
|
|
private DosEventLog getDosEventLogByStaticThreshold(DosSketchLog value, DosDetectionThreshold threshold) {
|
|
|
|
|
|
long base = threshold.getSessionsPerSec();
|
|
|
|
|
|
long diff = value.getSketch_sessions() - base;
|
|
|
|
|
|
DosEventLog result = getDosEventLog(value, base, diff, 1, "sessions");
|
|
|
|
|
|
if (result == null) {
|
|
|
|
|
|
base = threshold.getPacketsPerSec();
|
|
|
|
|
|
diff = value.getSketch_packets() - base;
|
|
|
|
|
|
result = getDosEventLog(value, base, diff, 1, "packets");
|
2021-10-19 18:39:13 +08:00
|
|
|
|
if (result == null) {
|
2021-10-20 18:23:12 +08:00
|
|
|
|
base = threshold.getBitsPerSec();
|
|
|
|
|
|
diff = value.getSketch_bytes() - base;
|
|
|
|
|
|
result = getDosEventLog(value, base, diff, 1, "bits");
|
2021-10-19 18:39:13 +08:00
|
|
|
|
}
|
2021-08-20 18:34:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-19 18:39:13 +08:00
|
|
|
|
private DosEventLog getDosEventLog(DosSketchLog value, long base, long diff, int type, String tag) {
|
2021-08-20 18:34:40 +08:00
|
|
|
|
DosEventLog result = null;
|
|
|
|
|
|
String destinationIp = value.getDestination_ip();
|
|
|
|
|
|
String attackType = value.getAttack_type();
|
|
|
|
|
|
if (diff > 0 && base != 0) {
|
2021-08-26 18:42:28 +08:00
|
|
|
|
double percent = getDiffPercent(diff, base);
|
2021-09-14 18:46:23 +08:00
|
|
|
|
Severity severity = judgeSeverity(percent);
|
2021-08-20 18:34:40 +08:00
|
|
|
|
if (severity != Severity.NORMAL) {
|
2021-10-21 18:27:48 +08:00
|
|
|
|
if (type == BASELINE_CONDITION_TYPE && percent < CommonConfig.BASELINE_SENSITIVITY_THRESHOLD) {
|
2021-10-19 18:39:13 +08:00
|
|
|
|
logger.debug("当前server IP:{},类型:{},基线值{}百分比{}未超过基线敏感阈值,日志详情\n{}", destinationIp, attackType, base, percent, value);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
result = getResult(value, base, severity, percent, type, tag);
|
2021-10-20 18:23:12 +08:00
|
|
|
|
logger.info("检测到当前server IP {} 存在 {} 异常,超出基线{} {}倍,基于{}:{}检测,日志详情\n {}", destinationIp,attackType,base,percent,type,tag,result);
|
2021-09-16 18:47:00 +08:00
|
|
|
|
}
|
2021-08-20 18:34:40 +08:00
|
|
|
|
} else {
|
2021-09-16 18:47:00 +08:00
|
|
|
|
logger.debug("当前server IP:{} 未出现 {} 异常,日志详情 {}", destinationIp, attackType, value);
|
2021-08-20 18:34:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-09-14 18:46:23 +08:00
|
|
|
|
return result;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-19 18:39:13 +08:00
|
|
|
|
private DosEventLog getResult(DosSketchLog value, long base, Severity severity, double percent, int type, String tag) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
DosEventLog dosEventLog = new DosEventLog();
|
|
|
|
|
|
dosEventLog.setLog_id(SnowflakeId.generateId());
|
|
|
|
|
|
dosEventLog.setStart_time(value.getSketch_start_time());
|
2021-09-26 18:41:36 +08:00
|
|
|
|
dosEventLog.setEnd_time(value.getSketch_start_time() + value.getSketch_duration());
|
2021-07-29 10:02:31 +08:00
|
|
|
|
dosEventLog.setAttack_type(value.getAttack_type());
|
2021-08-24 16:35:31 +08:00
|
|
|
|
dosEventLog.setSeverity(severity.severity);
|
2021-10-19 18:39:13 +08:00
|
|
|
|
dosEventLog.setConditions(getConditions(PERCENT_INSTANCE.format(percent), base, value.getSketch_sessions(), type, tag));
|
2021-07-29 10:02:31 +08:00
|
|
|
|
dosEventLog.setDestination_ip(value.getDestination_ip());
|
|
|
|
|
|
dosEventLog.setDestination_country(IpUtils.ipLookup.countryLookup(value.getDestination_ip()));
|
|
|
|
|
|
String ipList = value.getSource_ip();
|
|
|
|
|
|
dosEventLog.setSource_ip_list(ipList);
|
|
|
|
|
|
dosEventLog.setSource_country_list(getSourceCountryList(ipList));
|
|
|
|
|
|
dosEventLog.setSession_rate(value.getSketch_sessions());
|
|
|
|
|
|
dosEventLog.setPacket_rate(value.getSketch_packets());
|
|
|
|
|
|
dosEventLog.setBit_rate(value.getSketch_bytes());
|
|
|
|
|
|
return dosEventLog;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-21 18:27:48 +08:00
|
|
|
|
private Integer getBaseValue(DosBaselineThreshold dosBaselineThreshold, DosSketchLog value) {
|
2021-08-18 19:15:49 +08:00
|
|
|
|
Integer base = 0;
|
2021-08-17 18:56:53 +08:00
|
|
|
|
try {
|
2021-10-21 18:27:48 +08:00
|
|
|
|
if (dosBaselineThreshold != null) {
|
|
|
|
|
|
ArrayList<Integer> baselines = dosBaselineThreshold.getSession_rate();
|
|
|
|
|
|
Integer defaultVaule = dosBaselineThreshold.getSession_rate_default_value();
|
2021-08-18 19:15:49 +08:00
|
|
|
|
if (baselines != null && baselines.size() == BASELINE_SIZE) {
|
|
|
|
|
|
int timeIndex = getCurrentTimeIndex(value.getSketch_start_time());
|
|
|
|
|
|
base = baselines.get(timeIndex);
|
|
|
|
|
|
if (base == 0) {
|
|
|
|
|
|
logger.debug("获取到当前IP: {},类型: {} baseline值为0,替换为P95观测值{}", value.getDestination_ip(), value.getAttack_type(), defaultVaule);
|
|
|
|
|
|
base = defaultVaule;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-17 18:56:53 +08:00
|
|
|
|
}
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("解析baseline数据失败,返回默认值0", e);
|
2021-08-17 18:56:53 +08:00
|
|
|
|
}
|
2021-08-18 19:15:49 +08:00
|
|
|
|
return base;
|
2021-08-17 18:56:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-19 18:39:13 +08:00
|
|
|
|
private String getConditions(String percent, long base, long sessions, int type, String tag) {
|
|
|
|
|
|
switch (type) {
|
2021-10-21 18:27:48 +08:00
|
|
|
|
case STATIC_CONDITION_TYPE:
|
2021-10-19 18:39:13 +08:00
|
|
|
|
return new StrBuilder()
|
|
|
|
|
|
.append(tag).append(" > ")
|
|
|
|
|
|
.append(base).append(" ")
|
|
|
|
|
|
.append(tag).append("/s")
|
|
|
|
|
|
.toString();
|
2021-10-21 18:27:48 +08:00
|
|
|
|
case BASELINE_CONDITION_TYPE:
|
2021-10-19 18:39:13 +08:00
|
|
|
|
return new StrBuilder()
|
|
|
|
|
|
.append(tag).append(" > ")
|
|
|
|
|
|
.append(percent).append(" of baseline")
|
|
|
|
|
|
.toString();
|
2021-10-21 18:27:48 +08:00
|
|
|
|
case SENSITIVITY_CONDITION_TYPE:
|
2021-10-19 18:39:13 +08:00
|
|
|
|
return new StrBuilder()
|
|
|
|
|
|
.append(sessions).append(" ")
|
|
|
|
|
|
.append(tag).append("/s Unusually high ")
|
|
|
|
|
|
.append(StringUtils.capitalize(tag))
|
|
|
|
|
|
.toString();
|
2021-08-24 16:35:31 +08:00
|
|
|
|
default:
|
2021-10-21 18:27:48 +08:00
|
|
|
|
throw new IllegalArgumentException("Illegal Argument type:" + type + ", known types = [1,2,3]");
|
2021-08-24 16:35:31 +08:00
|
|
|
|
}
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-18 19:15:49 +08:00
|
|
|
|
private String getSourceCountryList(String sourceIpList) {
|
2021-10-19 18:39:13 +08:00
|
|
|
|
if (StringUtil.isNotBlank(sourceIpList)) {
|
|
|
|
|
|
String countryList;
|
|
|
|
|
|
try {
|
|
|
|
|
|
String[] ipArr = sourceIpList.split(",");
|
|
|
|
|
|
HashSet<String> countrySet = new HashSet<>();
|
|
|
|
|
|
for (String ip : ipArr) {
|
|
|
|
|
|
countrySet.add(IpUtils.ipLookup.countryLookup(ip));
|
|
|
|
|
|
}
|
|
|
|
|
|
countryList = StringUtils.join(countrySet, ",");
|
|
|
|
|
|
return countryList;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("{} source IP lists 获取国家失败", sourceIpList, e);
|
|
|
|
|
|
return StringUtil.EMPTY;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new IllegalArgumentException("Illegal Argument sourceIpList = null");
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-18 19:15:49 +08:00
|
|
|
|
private int getCurrentTimeIndex(long sketchStartTime) {
|
2021-10-19 18:39:13 +08:00
|
|
|
|
int index = 0;
|
|
|
|
|
|
try {
|
|
|
|
|
|
long currentDayTime = DateUtils.getTimeFloor(new Date(sketchStartTime * 1000L), "P1D").getTime() / 1000;
|
|
|
|
|
|
long indexLong = (sketchStartTime - currentDayTime) / (86400 / BASELINE_SIZE);
|
|
|
|
|
|
index = Integer.parseInt(Long.toString(indexLong));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
logger.error("获取time index失败", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
return index;
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-14 18:46:23 +08:00
|
|
|
|
public static void main(String[] args) {
|
2021-09-15 10:08:17 +08:00
|
|
|
|
Date date = new Date(1631548860 * 1000L);
|
|
|
|
|
|
System.out.println(date);
|
|
|
|
|
|
Date p1D = DateUtils.getTimeFloor(date, "P1D");
|
2021-10-19 18:39:13 +08:00
|
|
|
|
System.out.println(p1D + " " + p1D.getTime() / 1000);
|
|
|
|
|
|
System.out.println(new DosDetection().getCurrentTimeIndex(1634659080));
|
|
|
|
|
|
System.out.println(new DosDetection().getConditions(PERCENT_INSTANCE.format(1.64862), 100, 100, 3, "packets"));
|
|
|
|
|
|
System.out.println(10 + 10 * 0.2);
|
2021-09-14 18:46:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-26 18:42:28 +08:00
|
|
|
|
private Double getDiffPercent(long diff, long base) {
|
2021-10-19 18:39:13 +08:00
|
|
|
|
return BigDecimal.valueOf((float) diff / base).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-18 19:15:49 +08:00
|
|
|
|
private Severity judgeSeverity(double diffPercent) {
|
|
|
|
|
|
if (diffPercent >= CommonConfig.BASELINE_SESSIONS_MINOR_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_WARNING_THRESHOLD) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.MINOR;
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_WARNING_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_MAJOR_THRESHOLD) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.WARNING;
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_MAJOR_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_SEVERE_THRESHOLD) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.MAJOR;
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_SEVERE_THRESHOLD && diffPercent < CommonConfig.BASELINE_SESSIONS_CRITICAL_THRESHOLD) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.SEVERE;
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} else if (diffPercent >= CommonConfig.BASELINE_SESSIONS_CRITICAL_THRESHOLD) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.CRITICAL;
|
2021-08-18 19:15:49 +08:00
|
|
|
|
} else {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
return Severity.NORMAL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private enum Severity {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断严重程度枚举类型
|
|
|
|
|
|
*/
|
2021-10-21 18:27:48 +08:00
|
|
|
|
CRITICAL("Critical"),
|
|
|
|
|
|
SEVERE("Severe"),
|
|
|
|
|
|
MAJOR("Major"),
|
|
|
|
|
|
WARNING("Warning"),
|
|
|
|
|
|
MINOR("Minor"),
|
|
|
|
|
|
NORMAL("Normal");
|
2021-07-29 10:02:31 +08:00
|
|
|
|
|
|
|
|
|
|
private final String severity;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
return this.severity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-21 18:27:48 +08:00
|
|
|
|
Severity(String severity) {
|
2021-07-29 10:02:31 +08:00
|
|
|
|
this.severity = severity;
|
2021-09-14 18:46:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-29 10:02:31 +08:00
|
|
|
|
}
|