Authored by qinchao

恶意ip

... ... @@ -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,String hbaseTime);
void insertMipObj(String influxDBName, String ip,String reason,String duration,String hbaseTime,String createTimeStr);
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,String hbaseTime){
public void insertMipObj(String influxDBName, String ip,String reason,String duration,String hbaseTime,String createTimeStr){
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).addField("hbasetime",hbaseTime).build();
.addField("value", ip).addField("dur",duration).addField("reason",reason).addField("hbasetime",hbaseTime).addField("createtime",createTimeStr).build();
batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);
... ... @@ -98,11 +98,13 @@ public class MaliciousIpMapperImpl extends InfluxDBQuery implements MaliciousIpM
continue;
String ip = tags.get("ip");//ip
if(s.getValues() == null ) continue;
for(List<Object> ls : s.getValues()){
Map<String,String> m = new HashMap();
m.put("createtime",""+ ls.get(s.getColumns().indexOf("createtime"))==null?"":String.valueOf(ls.get(s.getColumns().indexOf("createtime"))));
m.put("reason",(String) ls.get(s.getColumns().indexOf("reason")));
m.put("dur",(String) ls.get(s.getColumns().indexOf("dur")));
m.put("time",""+ls.get(s.getColumns().indexOf("time")));
m.put("hbasetime", ls.get(s.getColumns().indexOf("hbasetime"))==null?"":String.valueOf(ls.get(s.getColumns().indexOf("hbasetime"))));
resultMap.put(ip,m);
}
}
... ...
... ... @@ -2,15 +2,12 @@ package com.monitor.other.maliciousip.model;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* 恶意ip内容集合
* @author hui.xu
*
*/
@Data
public class MaliciousIp {
/**
... ... @@ -61,106 +58,14 @@ public class MaliciousIp {
private long ts;
private String hbaseTime;
/**/
/*private List<String> reason;
private List<String> duration;*/
private String reasonDur;
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public long getAllCount() {
return allCount;
}
public void setAllCount(long allCount) {
this.allCount = allCount;
}
public long getQps() {
return qps;
}
public void setQps(long qps) {
this.qps = qps;
}
public long getImpCount() {
return impCount;
}
public void setImpCount(long impCount) {
this.impCount = impCount;
}
public double getIpPrecent() {
return ipPrecent;
}
public void setIpPrecent(double ipPrecent) {
this.ipPrecent = ipPrecent;
}
public double getImpApiPrecent() {
return impApiPrecent;
}
public void setImpApiPrecent(double impApiPrecent) {
this.impApiPrecent = impApiPrecent;
}
public long getUdidCount() {
return udidCount;
}
public void setUdidCount(long udidCount) {
this.udidCount = udidCount;
}
public long getNotExsitUdidCount() {
return notExsitUdidCount;
}
public void setNotExsitUdidCount(long notExsitUdidCount) {
this.notExsitUdidCount = notExsitUdidCount;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getReasonDur() {
return reasonDur;
}
public void setReasonDur(String reasonDur) {
this.reasonDur = reasonDur;
}
public long getTs() {
return ts;
}
public void setTs(long ts) {
this.ts = ts;
}
@Override
... ...
... ... @@ -171,6 +171,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
//发送拦截短信
String mobile_yunwei = getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_MALICIOUS_IP);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createTimeStr=sdf.format(new Date());
for(int i=0;i<ipsObjArray.size();i++){
JSONObject jo= ipsObjArray.getJSONObject(i);
String ip=jo.getString("ip");
... ... @@ -182,7 +184,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
alarmMsgService.sendSms("MaliciousIp", smsStr, mobile_yunwei);
try {
maliciousIpMapper.insertMipObj(influxDBStr, ip, reason, duration,hbaseTime);
maliciousIpMapper.insertMipObj(influxDBStr, ip, reason, duration,hbaseTime,createTimeStr);
} catch (Exception e) {
logger.error("writeMipsObjToOpsReids insert mip into influxdb failed", e);
}
... ... @@ -359,6 +361,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
long ts=0l;
String insertTime="";
String insertTime2="";
String hbaseTime="";
String hbaseTime2="";
for(String mipKey : mipKeys){
MaliciousIp mip = new MaliciousIp();
mip.setIp(mipKey);
... ... @@ -368,7 +372,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
if( awsIpInfo.get(mipKey) != null){
Map<String,String> awsInfo = awsIpInfo.get(mipKey);
String reason=awsInfo.get("reason");
insertTime=awsInfo.get("time");
insertTime=awsInfo.get("createtime");
hbaseTime=awsInfo.get("hbasetime");
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
... ... @@ -386,7 +391,8 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
reasonDur += "</br>";
}
String reason=qcloudInfo.get("reason");
insertTime2=qcloudInfo.get("time");
insertTime2=qcloudInfo.get("createtime");
hbaseTime2=qcloudInfo.get("hbasetime");
try{
MaliciousIpModel model=JSON.parseObject(reason,MaliciousIpModel.class);
reason=model.toHtmlString();
... ... @@ -414,15 +420,23 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
}*/
mip.setTs(ts);
if(StringUtils.isNotBlank(insertTime)&&StringUtils.isNotBlank(insertTime2)){
try{
if(insertTime.compareTo(insertTime2)>0){
mip.setTime(insertTime.substring(0,10)+" "+insertTime.substring(11,19));
mip.setTime(insertTime);
}else{
mip.setTime(insertTime2.substring(0,10)+" "+insertTime2.substring(11,19));
mip.setTime(insertTime2);
}
}
}catch (Exception e){
if(StringUtils.isNotBlank(hbaseTime)&&StringUtils.isNotBlank(hbaseTime2)){
if(hbaseTime.compareTo(hbaseTime2)>0){
mip.setHbaseTime(hbaseTime);
}else{
mip.setHbaseTime(hbaseTime2);
}
}else if(StringUtils.isNotBlank(hbaseTime2)){
mip.setHbaseTime(hbaseTime);
}else{
mip.setHbaseTime(hbaseTime2);
}
listMaliciousIp.add(mip);
... ...