Authored by qinchao

恶意ip添加新的字段:hbasetime

... ... @@ -11,7 +11,7 @@ import java.util.Set;
*/
public interface MaliciousIpMapper {
void insertMip(String influxDBName, String ip);
void insertMipObj(String influxDBName, String ip,String reason,String duration);
void insertMipObj(String influxDBName, String ip,String reason,String duration,String hbaseTime);
Map<String,Map<String,String>> getMaliousIpInfo(Set<String> listMaliciousIp, String cloud);
... ...
... ... @@ -51,13 +51,13 @@ public class MaliciousIpMapperImpl extends InfluxDBQuery implements MaliciousIpM
//duration 是influxdb关键字,因此字段名称取为dur,保留策略: rp_thirtyweek
//由于不是默认的保留策略,因此执行查询时,select * from rp_thirtyweek.monitor_malicousips where value= '127.0.0.1';
public void insertMipObj(String influxDBName, String ip,String reason,String duration){
public void insertMipObj(String influxDBName, String ip,String reason,String duration,String hbaseTime){
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOMO_MONITOR).retentionPolicy(mip_rpname)
.build();
Point point = Point.measurement("monitor_malicousips")
.tag("ip",ip)
.addField("value", ip).addField("dur",duration).addField("reason",reason).build();
.addField("value", ip).addField("dur",duration).addField("reason",reason).addField("hbasetime",hbaseTime).build();
batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);
... ...
... ... @@ -14,6 +14,11 @@ public class MaliciousIpsRecordForbid {
private String reason;
/**
*获取hbase数据的时间戳
*/
private String hbaseTime;
/**
* 创建时间
*/
private Date createTime;
... ...
... ... @@ -6,10 +6,11 @@
<result column="ip" property="ip" jdbcType="VARCHAR" />
<result column="reason" property="reason" jdbcType="VARCHAR" />
<result column="forbid_status" property="forbidStatus" jdbcType="VARCHAR" />
<result column="hbase_time" property="hbaseTime" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, ip,reason,create_time,forbid_status
id, ip,reason,create_time,forbid_status,hbase_time
</sql>
<select id="getAlarmCountMipsInfoToOpsDb" resultType="java.lang.Integer">
... ... @@ -44,8 +45,8 @@
</select>
<insert id="insert" parameterType="com.model.MaliciousIpsRecordForbid">
insert into malicious_ips_record_forbid(ip,reason,create_time)
values(#{ip,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR},now())
insert into malicious_ips_record_forbid(ip,reason,hbase_time,create_time)
values(#{ip,jdbcType=VARCHAR},#{reason,jdbcType=VARCHAR},#{hbaseTime,jdbcType=VARCHAR},now())
</insert>
<update id="updateForbidStatusByPrimaryKey" parameterType="com.model.MaliciousIpsRecordForbid" >
... ...
... ... @@ -176,12 +176,13 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
String ip=jo.getString("ip");
String reason=jo.getString("reason");
String duration=jo.get("duration")==null?"":""+jo.get("duration");
String hbaseTime=String.valueOf(jo.getLongValue("timestamp"));
if(StringUtils.isNotBlank(ip)){
String smsStr = "成功捕获恶意ip->" + ip ;
alarmMsgService.sendSms("MaliciousIp", smsStr, mobile_yunwei);
try {
maliciousIpMapper.insertMipObj(influxDBStr, ip, reason, duration);
maliciousIpMapper.insertMipObj(influxDBStr, ip, reason, duration,hbaseTime);
} catch (Exception e) {
logger.error("writeMipsObjToOpsReids insert mip into influxdb failed", e);
}
... ... @@ -207,12 +208,14 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
JSONObject jo= ipsObjArray.getJSONObject(i);
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");
if(StringUtils.isNotBlank(ip)){
MaliciousIpsRecordForbid record=new MaliciousIpsRecordForbid();
record.setIp(ip);
record.setReason(reason);
record.setHbaseTime(hbaseTime);
maliciousIpsRecordForbidMapper.insert(record);
logger.info("MaliciousIpServiceImpl writeMipsObjToOpsReids - "+ip);
... ... @@ -888,7 +891,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
}
}
}catch(Exception e){
e.printStackTrace();
}
return list;
... ...
... ... @@ -12,6 +12,7 @@ import java.io.IOException;
*/
public class HbasePool {
private static final String QUORUM = "10.66.80.5";
//private static final String QUORUM = "server3";
private static final String CLIENTPORT = "2181";
private static Configuration conf = null;
private static Connection conn = null;
... ...