|
|
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
|
...
|
...
|
|