Authored by qinchao

增加新方法:恶意ip写入支持拦截原因

... ... @@ -6,5 +6,6 @@ import org.influxdb.dto.QueryResult;
* Created by craig.qin on 2017/8/18.
*/
public interface MaliciousIpMapper {
public void insertMip(String influxDBName, String ip);
void insertMip(String influxDBName, String ip);
void insertMipObj(String influxDBName, String ip,String reason,String duration);
}
... ...
... ... @@ -36,4 +36,16 @@ public class MaliciousIpMapperImpl extends InfluxDBQuery implements MaliciousIpM
inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);
}
public void insertMipObj(String influxDBName, String ip,String reason,String duration){
BatchPoints batchPoints = BatchPoints
.database(InfluxDBContants.YOMO_MONITOR).retentionPolicy("default")
.build();
Point point = Point.measurement("monitor_malicousips")
.tag("ip",ip)
.addField("value", ip).addField("duration",duration).addField("reason",reason).build();
batchPoints.point(point);
inluxDBSingle.getInfluxDBByName(influxDBName).getInfluxDB()
.write(batchPoints);
}
}
... ...
... ... @@ -59,6 +59,16 @@ public class MaliciousIpController {
}
/**
* 捕获的恶意ip写入运维系统的redis
* @return
*/
@RequestMapping("/writeMipsObjToOpsReids")
@ResponseBody
public void writeMipsObjToOpsReids(String ipsObjs) {
ipImpl.writeMipsObjToOpsReids(ipsObjs);
}
/**
* 从运维系统的redis获取恶意ip
* @return
*/
... ...
... ... @@ -17,6 +17,8 @@ public interface MaliciousIpService {
*/
void writeMipsToOpsReids(String ips);
void writeMipsObjToOpsReids(String ipsObjs);
/**
*从运维系统的redis查询恶意ip
*/
... ...
package com.monitor.other.maliciousip.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.contants.AlarmGroupContants;
import com.model.MalIpRule;
import com.monitor.common.service.AlarmMsgService;
... ... @@ -125,6 +127,47 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
}
/**
*捕获的恶意ipsObj写入运维系统的redis
* ipsObj:json格式数据,包括 ip reason duration
*/
@Override
public void writeMipsObjToOpsReids(String ipsObjs){
logger.info("begin writeMipsObjToOpsReids :"+ipsObjs);
if(StringUtils.isBlank(ipsObjs)){
return ;
}
String influxDBStr=InfluxDBContants.AWS;
if(("qcloud").equals(cloudName)){
influxDBStr=InfluxDBContants.Q_CLOUD;
}
//发送拦截短信
String mobile_yunwei = getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_MALICIOUS_IP);
JSONArray ipsObjArray=JSON.parseArray(ipsObjs);
for(int i=0;i<ipsObjArray.size();i++){
JSONObject jo= ipsObjArray.getJSONObject(i);
String ip=jo.getString("ip");
String reason=jo.getString("reason");
String duration=(jo.get("duration")==null?"":(String)jo.get("duration"));
if(StringUtils.isNotBlank(ip)){
//String key=MALICIOUS_IP + ip;
awsRedisTemplate.opsForSet().add(MALICIOUS_IP_SET,ip);//.opsForValue().set(key, "0");
//awsRedisTemplate.expire(key, MALICIOUS_IP_EXPIRE, TimeUnit.SECONDS);
try {
maliciousIpMapper.insertMipObj(influxDBStr, ip, reason, duration);
} catch (Exception e) {
logger.error("writeMipsObjToOpsReids insert sms into influxdb failed", e);
}
String smsStr = "成功捕获恶意ip->" + ip ;
alarmMsgService.sendSms("MaliciousIp", smsStr, mobile_yunwei);
logger.info("MaliciousIpServiceImpl writeMipsObjToOpsReids - "+ip);
}
}
}
/**
*从运维系统的redis查询恶意ip
*/
@Override
... ...