diff --git a/src/main/java/com/zdjizhi/common/CommonConfig.java b/src/main/java/com/zdjizhi/common/CommonConfig.java index 55b58fe..361fe9e 100644 --- a/src/main/java/com/zdjizhi/common/CommonConfig.java +++ b/src/main/java/com/zdjizhi/common/CommonConfig.java @@ -48,8 +48,7 @@ public class CommonConfig { public static final double BASELINE_SESSIONS_CRITICAL_THRESHOLD = CommonConfigurations.getDoubleProperty("baseline.sessions.critical.threshold"); public static final String BIFANG_SERVER_URI = CommonConfigurations.getStringProperty("bifang.server.uri"); - public static final String BIFANG_SERVER_USER = CommonConfigurations.getStringProperty("bifang.server.user"); - public static final String BIFANG_SERVER_PASSWORD = CommonConfigurations.getStringProperty("bifang.server.password"); + public static final String BIFANG_SERVER_TOKEN = CommonConfigurations.getStringProperty("bifang.server.token"); public static final String BIFANG_SERVER_ENCRYPTPWD_PATH = CommonConfigurations.getStringProperty("bifang.server.encryptpwd.path"); public static final String BIFANG_SERVER_LOGIN_PATH = CommonConfigurations.getStringProperty("bifang.server.login.path"); public static final String BIFANG_SERVER_POLICY_THRESHOLD_PATH = CommonConfigurations.getStringProperty("bifang.server.policy.threshold.path"); diff --git a/src/main/java/com/zdjizhi/etl/DosDetection.java b/src/main/java/com/zdjizhi/etl/DosDetection.java index 69660d2..42bbbd7 100644 --- a/src/main/java/com/zdjizhi/etl/DosDetection.java +++ b/src/main/java/com/zdjizhi/etl/DosDetection.java @@ -4,6 +4,7 @@ import com.zdjizhi.common.CommonConfig; import com.zdjizhi.common.DosDetectionThreshold; import com.zdjizhi.common.DosEventLog; import com.zdjizhi.common.DosSketchLog; +import com.zdjizhi.utils.DateUtils; import com.zdjizhi.utils.HbaseUtils; import com.zdjizhi.utils.IpUtils; import com.zdjizhi.utils.SnowflakeId; @@ -194,14 +195,17 @@ public class DosDetection extends RichMapFunction { } private int getCurrentTimeIndex(long sketchStartTime) { - long currentDayTime = sketchStartTime / (60 * 60 * 24) * 60 * 60 * 24; + long currentDayTime = DateUtils.getTimeFloor(new Date(sketchStartTime * 1000L), "P1D").getTime()/1000; long indexLong = (sketchStartTime - currentDayTime) / 600; return Integer.parseInt(Long.toString(indexLong)); } public static void main(String[] args) { - System.out.println(1631579940 / (60 * 60) * 60 * 60); - System.out.println(new DosDetection().getCurrentTimeIndex(1631579940)); + Date date = new Date(1631548860 * 1000L); + System.out.println(date); + Date p1D = DateUtils.getTimeFloor(date, "P1D"); + System.out.println(p1D+" "+p1D.getTime()/1000); + System.out.println(new DosDetection().getCurrentTimeIndex(1631548860)); } private Double getDiffPercent(long diff, long base) { diff --git a/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java b/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java index ab8c5cd..999b14f 100644 --- a/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java +++ b/src/main/java/com/zdjizhi/etl/ParseStaticThreshold.java @@ -43,7 +43,7 @@ public class ParseStaticThreshold { try { URIBuilder uriBuilder = new URIBuilder(CommonConfig.BIFANG_SERVER_URI); HashMap parms = new HashMap<>(); - parms.put("password", CommonConfig.BIFANG_SERVER_PASSWORD); + parms.put("password", "admin"); HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_ENCRYPTPWD_PATH, parms); String resposeJsonStr = HttpClientUtils.httpGet(uriBuilder.build()); if (!HttpClientUtils.ERROR_MESSAGE.equals(resposeJsonStr)) { @@ -76,7 +76,7 @@ public class ParseStaticThreshold { if (!HttpClientUtils.ERROR_MESSAGE.equals(encryptpwd)) { URIBuilder uriBuilder = new URIBuilder(CommonConfig.BIFANG_SERVER_URI); HashMap parms = new HashMap<>(); - parms.put("username", CommonConfig.BIFANG_SERVER_USER); + parms.put("username", "admin"); parms.put("password", encryptpwd); HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_LOGIN_PATH, parms); String resposeJsonStr = HttpClientUtils.httpPost(uriBuilder.build(), null); @@ -110,7 +110,7 @@ public class ParseStaticThreshold { HashMap parms = new HashMap<>(); parms.put("pageSize",-1); HttpClientUtils.setUrlWithParams(uriBuilder, CommonConfig.BIFANG_SERVER_POLICY_THRESHOLD_PATH, parms); - String token = loginBifangServer(); + String token = CommonConfig.BIFANG_SERVER_TOKEN; if (!HttpClientUtils.ERROR_MESSAGE.equals(token)) { BasicHeader authorization = new BasicHeader("Authorization", token); String resposeJsonStr = HttpClientUtils.httpGet(uriBuilder.build(), authorization); diff --git a/src/main/resources/common.properties b/src/main/resources/common.properties index 31487fa..b700e2c 100644 --- a/src/main/resources/common.properties +++ b/src/main/resources/common.properties @@ -88,9 +88,8 @@ baseline.sessions.critical.threshold=8 #bifang服务访问地址 bifang.server.uri=http://192.168.44.3:80 -#访问bifang服务用户名密码 -bifang.server.user=admin -bifang.server.password=admin +#访问bifang只读权限token,bifang内置,无需修改 +bifang.server.token=ed04b942-7df4-4e3d-b9a9-a881ca98a867 #加密密码路径信息 bifang.server.encryptpwd.path=/v1/user/encryptpwd