...
|
...
|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.contants.AlarmGroupContants;
|
|
|
import com.model.MalIpRule;
|
|
|
import com.model.MaliciousIpsRecord;
|
|
|
import com.model.MaliciousIpsRecordForbid;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import com.monitor.influxdb.contants.InfluxDBContants;
|
|
|
import com.monitor.influxdb.mapper.MaliciousIpMapper;
|
...
|
...
|
@@ -15,6 +16,7 @@ import com.monitor.model.request.MaliciousIpRecordReq; |
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.model.response.PageResponse;
|
|
|
import com.monitor.mysql.mapper.MalIpRuleMapper;
|
|
|
import com.monitor.mysql.mapper.MaliciousIpsRecordForbidMapper;
|
|
|
import com.monitor.mysql.mapper.MaliciousIpsRecordMapper;
|
|
|
import com.monitor.other.maliciousip.contants.MaliciousIpContants;
|
|
|
import com.monitor.other.maliciousip.contants.MaliciousIpModel;
|
...
|
...
|
@@ -70,6 +72,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
private MaliciousIpsRecordMapper maliciousIpsRecordMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private MaliciousIpsRecordForbidMapper maliciousIpsRecordForbidMapper;
|
|
|
|
|
|
@Autowired
|
|
|
@Qualifier("awsRedisTemplate")
|
|
|
private RedisTemplate<String,String> awsRedisTemplate;
|
|
|
|
...
|
...
|
@@ -183,7 +188,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
|
|
|
|
|
|
public void writeMipsInfoToOpsDb(String ipsObjs){
|
|
|
logger.info("begin writeMipsInfoToOpsDb :"+ipsObjs);
|
|
|
//logger.info("begin writeMipsInfoToOpsDb :"+ipsObjs);
|
|
|
if(StringUtils.isNotBlank(ipsObjs)){
|
|
|
JSONArray ipsObjArray=JSON.parseArray(ipsObjs);
|
|
|
for(int i=0;i<ipsObjArray.size();i++){
|
...
|
...
|
@@ -200,6 +205,32 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
public void writeForbidMipsInfoToOpsDb(String ipsObjs){
|
|
|
//logger.info("begin writeForbidMipsInfoToOpsDb :"+ipsObjs);
|
|
|
if(StringUtils.isNotBlank(ipsObjs)){
|
|
|
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.toJSONString();
|
|
|
|
|
|
//写入mysql
|
|
|
MaliciousIpsRecordForbid record=new MaliciousIpsRecordForbid();
|
|
|
record.setIp(ip);
|
|
|
record.setReason(reason);
|
|
|
maliciousIpsRecordForbidMapper.insert(record);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void updateForbidStatus(int id ,String status){
|
|
|
MaliciousIpsRecordForbid recordForbid=new MaliciousIpsRecordForbid();
|
|
|
recordForbid.setId(id);
|
|
|
recordForbid.setForbidStatus(status);
|
|
|
maliciousIpsRecordForbidMapper.updateForbidStatusByPrimaryKey(recordForbid);
|
|
|
}
|
|
|
|
|
|
|
|
|
public BaseResponse getMipsInfoToOpsDb(MaliciousIpRecordReq request){
|
|
|
PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
|
|
|
maliciousIpsRecordMapper.selectByPage(page);
|
...
|
...
|
@@ -237,6 +268,43 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
return new BaseResponse<>(pageResp);
|
|
|
}
|
|
|
|
|
|
public BaseResponse getForbidMipsInfoToOpsDb(MaliciousIpRecordReq request){
|
|
|
PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
|
|
|
maliciousIpsRecordForbidMapper.selectByPage(page);
|
|
|
// 先查询符合条件的总数量
|
|
|
int total = maliciousIpsRecordForbidMapper.selectCount(page);
|
|
|
// 数量为0 直接返回
|
|
|
if (total == 0) {
|
|
|
return new BaseResponse<>();
|
|
|
}
|
|
|
// 获取列表
|
|
|
List<MaliciousIpsRecordForbid> ls = maliciousIpsRecordForbidMapper.selectByPage(page);
|
|
|
if (org.springframework.util.CollectionUtils.isEmpty(ls)) {
|
|
|
return new BaseResponse<>();
|
|
|
}
|
|
|
//解析reason到汉字
|
|
|
for(MaliciousIpsRecordForbid record:ls){
|
|
|
String reasonForbid=record.getReason();
|
|
|
if(StringUtils.isNotBlank(reasonForbid)){
|
|
|
try{
|
|
|
MaliciousIpModel model=JSON.parseObject(reasonForbid,MaliciousIpModel.class);
|
|
|
reasonForbid=model.toHtmlString4DB();
|
|
|
record.setReason(reasonForbid);
|
|
|
}catch (Exception e){
|
|
|
///查询异常就不管了
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
PageResponse<MaliciousIpsRecordForbid> pageResp = new PageResponse<>();
|
|
|
pageResp.setCurrentPage(request.getCurrentPage());
|
|
|
pageResp.setPageSize(request.getPageSize());
|
|
|
pageResp.setTotal(total);
|
|
|
pageResp.setRows(ls);
|
|
|
return new BaseResponse<>(pageResp);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*从运维系统的redis查询恶意ip,并且从influxdb中取对应的ip信息
|
|
|
*/
|
...
|
...
|
|