|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; |
|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; |
6
|
import com.contants.AlarmGroupContants;
|
6
|
import com.contants.AlarmGroupContants;
|
7
|
import com.model.MalIpRule;
|
7
|
import com.model.MalIpRule;
|
8
|
import com.model.MaliciousIpsRecord;
|
8
|
import com.model.MaliciousIpsRecord;
|
|
|
9
|
+import com.model.MaliciousIpsRecordForbid;
|
9
|
import com.monitor.common.service.AlarmMsgService;
|
10
|
import com.monitor.common.service.AlarmMsgService;
|
10
|
import com.monitor.influxdb.contants.InfluxDBContants;
|
11
|
import com.monitor.influxdb.contants.InfluxDBContants;
|
11
|
import com.monitor.influxdb.mapper.MaliciousIpMapper;
|
12
|
import com.monitor.influxdb.mapper.MaliciousIpMapper;
|
|
@@ -15,6 +16,7 @@ import com.monitor.model.request.MaliciousIpRecordReq; |
|
@@ -15,6 +16,7 @@ import com.monitor.model.request.MaliciousIpRecordReq; |
15
|
import com.monitor.model.response.BaseResponse;
|
16
|
import com.monitor.model.response.BaseResponse;
|
16
|
import com.monitor.model.response.PageResponse;
|
17
|
import com.monitor.model.response.PageResponse;
|
17
|
import com.monitor.mysql.mapper.MalIpRuleMapper;
|
18
|
import com.monitor.mysql.mapper.MalIpRuleMapper;
|
|
|
19
|
+import com.monitor.mysql.mapper.MaliciousIpsRecordForbidMapper;
|
18
|
import com.monitor.mysql.mapper.MaliciousIpsRecordMapper;
|
20
|
import com.monitor.mysql.mapper.MaliciousIpsRecordMapper;
|
19
|
import com.monitor.other.maliciousip.contants.MaliciousIpContants;
|
21
|
import com.monitor.other.maliciousip.contants.MaliciousIpContants;
|
20
|
import com.monitor.other.maliciousip.contants.MaliciousIpModel;
|
22
|
import com.monitor.other.maliciousip.contants.MaliciousIpModel;
|
|
@@ -70,6 +72,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
@@ -70,6 +72,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
70
|
private MaliciousIpsRecordMapper maliciousIpsRecordMapper;
|
72
|
private MaliciousIpsRecordMapper maliciousIpsRecordMapper;
|
71
|
|
73
|
|
72
|
@Autowired
|
74
|
@Autowired
|
|
|
75
|
+ private MaliciousIpsRecordForbidMapper maliciousIpsRecordForbidMapper;
|
|
|
76
|
+
|
|
|
77
|
+ @Autowired
|
73
|
@Qualifier("awsRedisTemplate")
|
78
|
@Qualifier("awsRedisTemplate")
|
74
|
private RedisTemplate<String,String> awsRedisTemplate;
|
79
|
private RedisTemplate<String,String> awsRedisTemplate;
|
75
|
|
80
|
|
|
@@ -183,7 +188,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
@@ -183,7 +188,7 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
183
|
|
188
|
|
184
|
|
189
|
|
185
|
public void writeMipsInfoToOpsDb(String ipsObjs){
|
190
|
public void writeMipsInfoToOpsDb(String ipsObjs){
|
186
|
- logger.info("begin writeMipsInfoToOpsDb :"+ipsObjs);
|
191
|
+ //logger.info("begin writeMipsInfoToOpsDb :"+ipsObjs);
|
187
|
if(StringUtils.isNotBlank(ipsObjs)){
|
192
|
if(StringUtils.isNotBlank(ipsObjs)){
|
188
|
JSONArray ipsObjArray=JSON.parseArray(ipsObjs);
|
193
|
JSONArray ipsObjArray=JSON.parseArray(ipsObjs);
|
189
|
for(int i=0;i<ipsObjArray.size();i++){
|
194
|
for(int i=0;i<ipsObjArray.size();i++){
|
|
@@ -200,6 +205,32 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
@@ -200,6 +205,32 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
200
|
}
|
205
|
}
|
201
|
}
|
206
|
}
|
202
|
|
207
|
|
|
|
208
|
+ public void writeForbidMipsInfoToOpsDb(String ipsObjs){
|
|
|
209
|
+ //logger.info("begin writeForbidMipsInfoToOpsDb :"+ipsObjs);
|
|
|
210
|
+ if(StringUtils.isNotBlank(ipsObjs)){
|
|
|
211
|
+ JSONArray ipsObjArray=JSON.parseArray(ipsObjs);
|
|
|
212
|
+ for(int i=0;i<ipsObjArray.size();i++){
|
|
|
213
|
+ JSONObject jo= ipsObjArray.getJSONObject(i);
|
|
|
214
|
+ String ip=jo.getString("ip");
|
|
|
215
|
+ String reason=jo.toJSONString();
|
|
|
216
|
+
|
|
|
217
|
+ //写入mysql
|
|
|
218
|
+ MaliciousIpsRecordForbid record=new MaliciousIpsRecordForbid();
|
|
|
219
|
+ record.setIp(ip);
|
|
|
220
|
+ record.setReason(reason);
|
|
|
221
|
+ maliciousIpsRecordForbidMapper.insert(record);
|
|
|
222
|
+ }
|
|
|
223
|
+ }
|
|
|
224
|
+ }
|
|
|
225
|
+
|
|
|
226
|
+ public void updateForbidStatus(int id ,String status){
|
|
|
227
|
+ MaliciousIpsRecordForbid recordForbid=new MaliciousIpsRecordForbid();
|
|
|
228
|
+ recordForbid.setId(id);
|
|
|
229
|
+ recordForbid.setForbidStatus(status);
|
|
|
230
|
+ maliciousIpsRecordForbidMapper.updateForbidStatusByPrimaryKey(recordForbid);
|
|
|
231
|
+ }
|
|
|
232
|
+
|
|
|
233
|
+
|
203
|
public BaseResponse getMipsInfoToOpsDb(MaliciousIpRecordReq request){
|
234
|
public BaseResponse getMipsInfoToOpsDb(MaliciousIpRecordReq request){
|
204
|
PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
|
235
|
PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
|
205
|
maliciousIpsRecordMapper.selectByPage(page);
|
236
|
maliciousIpsRecordMapper.selectByPage(page);
|
|
@@ -237,6 +268,43 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
@@ -237,6 +268,43 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
237
|
return new BaseResponse<>(pageResp);
|
268
|
return new BaseResponse<>(pageResp);
|
238
|
}
|
269
|
}
|
239
|
|
270
|
|
|
|
271
|
+ public BaseResponse getForbidMipsInfoToOpsDb(MaliciousIpRecordReq request){
|
|
|
272
|
+ PageBean page = PageBean.initPageInfo(request.getCurrentPage(), request.getPageSize(), request);
|
|
|
273
|
+ maliciousIpsRecordForbidMapper.selectByPage(page);
|
|
|
274
|
+ // 先查询符合条件的总数量
|
|
|
275
|
+ int total = maliciousIpsRecordForbidMapper.selectCount(page);
|
|
|
276
|
+ // 数量为0 直接返回
|
|
|
277
|
+ if (total == 0) {
|
|
|
278
|
+ return new BaseResponse<>();
|
|
|
279
|
+ }
|
|
|
280
|
+ // 获取列表
|
|
|
281
|
+ List<MaliciousIpsRecordForbid> ls = maliciousIpsRecordForbidMapper.selectByPage(page);
|
|
|
282
|
+ if (org.springframework.util.CollectionUtils.isEmpty(ls)) {
|
|
|
283
|
+ return new BaseResponse<>();
|
|
|
284
|
+ }
|
|
|
285
|
+ //解析reason到汉字
|
|
|
286
|
+ for(MaliciousIpsRecordForbid record:ls){
|
|
|
287
|
+ String reasonForbid=record.getReason();
|
|
|
288
|
+ if(StringUtils.isNotBlank(reasonForbid)){
|
|
|
289
|
+ try{
|
|
|
290
|
+ MaliciousIpModel model=JSON.parseObject(reasonForbid,MaliciousIpModel.class);
|
|
|
291
|
+ reasonForbid=model.toHtmlString4DB();
|
|
|
292
|
+ record.setReason(reasonForbid);
|
|
|
293
|
+ }catch (Exception e){
|
|
|
294
|
+ ///查询异常就不管了
|
|
|
295
|
+ }
|
|
|
296
|
+
|
|
|
297
|
+ }
|
|
|
298
|
+ }
|
|
|
299
|
+
|
|
|
300
|
+ PageResponse<MaliciousIpsRecordForbid> pageResp = new PageResponse<>();
|
|
|
301
|
+ pageResp.setCurrentPage(request.getCurrentPage());
|
|
|
302
|
+ pageResp.setPageSize(request.getPageSize());
|
|
|
303
|
+ pageResp.setTotal(total);
|
|
|
304
|
+ pageResp.setRows(ls);
|
|
|
305
|
+ return new BaseResponse<>(pageResp);
|
|
|
306
|
+ }
|
|
|
307
|
+
|
240
|
/**
|
308
|
/**
|
241
|
*从运维系统的redis查询恶意ip,并且从influxdb中取对应的ip信息
|
309
|
*从运维系统的redis查询恶意ip,并且从influxdb中取对应的ip信息
|
242
|
*/
|
310
|
*/
|