Authored by qinchao

恶意ip添加统计周期

... ... @@ -25,4 +25,7 @@ public class MaliciousIpsRecordForbid {
//封禁status 1 表示封
private String forbidStatus;
//统计周期
private String dur;
}
... ...
... ... @@ -8,9 +8,10 @@
<result column="forbid_status" property="forbidStatus" jdbcType="VARCHAR" />
<result column="hbase_time" property="hbaseTime" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="dur" property="dur" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, ip,reason,create_time,forbid_status,hbase_time
id, ip,reason,create_time,forbid_status,hbase_time,dur
</sql>
<select id="getAlarmCountMipsInfoToOpsDb" resultType="java.lang.Integer">
... ... @@ -45,8 +46,8 @@
</select>
<insert id="insert" parameterType="com.model.MaliciousIpsRecordForbid">
insert into malicious_ips_record_forbid(ip,reason,hbase_time,create_time)
values(#{ip,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR},#{hbaseTime,jdbcType=VARCHAR},now())
insert into malicious_ips_record_forbid(ip,reason,dur,hbase_time,create_time)
values(#{ip,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR},#{dur,jdbcType=VARCHAR},#{hbaseTime,jdbcType=VARCHAR},now())
</insert>
<update id="updateForbidStatusByPrimaryKey" parameterType="com.model.MaliciousIpsRecordForbid" >
... ...
... ... @@ -65,6 +65,8 @@ public class MaliciousIp {
private List<String> duration;*/
private String reasonDur;
private String dur;
... ...
... ... @@ -211,13 +211,14 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
String ip=jo.getString("ip");
String reason=jo.getString("reason");
String hbaseTime=String.valueOf(jo.getLongValue("timestamp"));
//String duration=jo.get("duration")==null?"":""+jo.get("duration");
String duration=jo.get("duration")==null?"":""+jo.get("duration");
if(StringUtils.isNotBlank(ip)){
MaliciousIpsRecordForbid record=new MaliciousIpsRecordForbid();
record.setIp(ip);
record.setReason(reason);
record.setHbaseTime(hbaseTime);
record.setDur(duration);
maliciousIpsRecordForbidMapper.insert(record);
logger.info("MaliciousIpServiceImpl writeMipsObjToOpsReids - "+ip);
... ... @@ -363,6 +364,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
String insertTime2="";
String hbaseTime="";
String hbaseTime2="";
String dur="";
String dur2="";
for(String mipKey : mipKeys){
MaliciousIp mip = new MaliciousIp();
mip.setIp(mipKey);
... ... @@ -374,6 +377,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
String reason=awsInfo.get("reason");
insertTime=awsInfo.get("createtime");
hbaseTime=awsInfo.get("hbasetime");
dur=awsInfo.get("dur");
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
... ... @@ -393,6 +397,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
String reason=qcloudInfo.get("reason");
insertTime2=qcloudInfo.get("createtime");
hbaseTime2=qcloudInfo.get("hbasetime");
dur2=qcloudInfo.get("dur");
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
... ... @@ -424,16 +429,20 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
if(hbaseTime.compareTo(hbaseTime2)>0){
mip.setHbaseTime(hbaseTime);
mip.setTime(insertTime);
mip.setDur(dur);
}else{
mip.setHbaseTime(hbaseTime2);
mip.setTime(insertTime2);
mip.setDur(dur2);
}
}else if(StringUtils.isNotBlank(hbaseTime2)){
mip.setHbaseTime(hbaseTime2);
mip.setTime(insertTime2);
mip.setDur(dur2);
}else{
mip.setHbaseTime(hbaseTime);
mip.setTime(insertTime);
mip.setDur(dur);
}
listMaliciousIp.add(mip);
... ...