Authored by mlge

风控zk配置管理模块

package com.monitor.cloudtools.model;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import java.util.List;
/**
* Created by meiling.ge on 2018/3/6.
*/
//风控zk配置管理列表
public enum RiskCtrolZkNodeEnum {
//登录相关
gateway_degrade_users_checkUdid_enable("gateway.degrade.users.checkUdid.enable", "登录相关", "根据设备校验点击流降级开关(默认不降级)"),
uic_login_ip_limit_times("uic.login.ip.limit.times", "登录相关", "登录失败次数配置"),
users_loginip_limit_time("users.loginip.limit.time", "登录相关", "封的时间配置"),
uic_login_fail_limit_times("uic.login.fail.limit.times", "登录相关", "登录失败次数配置" ),
//图形验证码风控规则配置
gateway_degrade_uic_verifiedGraphic_enable("gateway.degrade.uic.verifiedGraphic.enable", "图形验证码风控规则配置", "开启或关闭图形验证码"),
gateway_degrade_uic_verifiedGraphic_h5web_enable("gateway.degrade.uic.verifiedGraphic.h5web.enable", "图形验证码风控规则配置","图形验证码/极验证"),
gateway_degrade_uic_verifiedGraphic_innerOutIp_ignore("gateway.degrade.uic.verifiedGraphic.innerOutIp.ignore", "图形验证码风控规则配置", "公司网络是否展示图形验证码 true-不展示 false-展示" ),
graphic_access_exceed_max_times("graphic.access.exceed.max.times", "图形验证码风控规则配置", "一个ip10分钟内请求次数"),
graphic_access_exceed_forbid_ip_time("graphic.access.exceed.forbid.ip.time", "图形验证码风控规则配置", "一个ip请求超限之后禁止请求图形时间"),
login_safe_times("login.safe.times", "图形验证码风控规则配置", "登录超过次数(短信登录,普通登录,第三方登录),展示图形验证码"),
smsSend_safe_times("smsSend.safe.times", "图形验证码风控规则配置", "短信发送超过次数(短信登录,注册,绑定,找回密码),展示图形验证码"),
//短信风控
message_iplimit_times_in_oneMin("message.iplimit.times.in.oneMin", "短信风控", "同一个ip一分钟限制发送条数"),
message_iplimit_times_in_tenMin("message.iplimit.times.in.tenMin", "短信风控", "同一个ip10分钟限制号码维度"),
message_mobile_limit_in_oneMin("message.mobile.limit.in.oneMin", "短信风控", "同一个号码一分钟发送次数"),
message_mobile_limit_in_tenMin("message.mobile.limit.in.tenMin", "短信风控", "同一个号码10分钟发送次数"),
message_mobile_limit_in_tweFour("message.mobile.limit.in.tweFour", "短信风控", "同一个号码24h发送次数");
private String nodeName;//节点名称
private String type;//所属类型
private String desc;//备注
RiskCtrolZkNodeEnum(String nodeName, String type, String desc) {
this.nodeName = nodeName;
this.type = type;
this.desc = desc;
}
public static List<String> getAllNodeNames(){
RiskCtrolZkNodeEnum[] allValues = RiskCtrolZkNodeEnum.values();
List<String> nodeNames = Lists.newArrayListWithCapacity(allValues.length);
for(RiskCtrolZkNodeEnum item : allValues){
nodeNames.add(item.nodeName);
}
return nodeNames;
}
//根据名称获取 类型
public static String getTypeByNodeName(String nodeName){
RiskCtrolZkNodeEnum[] allValues = RiskCtrolZkNodeEnum.values();
for(RiskCtrolZkNodeEnum item : allValues){
if(StringUtils.equals(nodeName, item.nodeName)){
return item.type;
}
}
return null;
}
}
... ...
package com.monitor.cmdb.ctrl;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
... ... @@ -98,6 +99,29 @@ public class ZkMonitorCtrl {
}
/**
* 根据 ip && zkPath 查找 与风控相关的 zk配置信息
* @param req -- (ip --表示 所属的监控对象名称; zkPath--需要查询的目录)
* @return
* @throws Exception
*/
@RequestMapping("/getRiskCtrolZkMonitorDetail")
@ResponseBody
public BaseResponse<PageResponse<ZkConfigAll>> getRiskCtrolZkMonitorDetail(@RequestBody ZkTreeAllReq req) throws Exception {
log.debug("getZkMonitorTree with req is {} ", req);
List<ZkConfigAll> list = zkMoitorService.getRiskCtrolZkMonitorDetail(req);
if(CollectionUtils.isEmpty(list) ){
return new BaseResponse();
}else{
PageResponse<ZkConfigAll> pageResponse = new PageResponse<>();
pageResponse.setCurrentPage(req.getCurrentPage());//其实并没有做分页
pageResponse.setPageSize(req.getPageSize());
pageResponse.setTotal(list.size());
pageResponse.setRows(list);
return new BaseResponse(pageResponse);
}
}
/**
* 修改某个子节点的值
* @param req
* @return
... ...
... ... @@ -34,4 +34,5 @@ public interface IZkMoitorService {
String getData(ZkTreeAllReq req);
List<ZkConfigAll> getRiskCtrolZkMonitorDetail(ZkTreeAllReq req);
}
... ...
... ... @@ -3,6 +3,7 @@ package com.monitor.cmdb.service.impl;
import com.model.MObjectInfo;
import com.model.ZkConfig;
import com.model.ZkConfigAll;
import com.monitor.cloudtools.model.RiskCtrolZkNodeEnum;
import com.monitor.cmdb.service.IZkMoitorService;
import com.monitor.common.util.ZkOnlineClientUtil;
import com.monitor.influxdb.mapper.IZkMapper;
... ... @@ -22,10 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by yoho on 2016/6/22.
... ... @@ -34,7 +33,8 @@ import java.util.Map;
@Service
public class ZkMoitorServiceImpl implements IZkMoitorService {
Logger logger = LoggerFactory.getLogger(HostInfoServiceImpl.class);
public static final Logger logger = LoggerFactory.getLogger(ZkMoitorServiceImpl.class);
@Autowired
IZkMapper zkMapper;
... ... @@ -245,6 +245,42 @@ public class ZkMoitorServiceImpl implements IZkMoitorService {
}
@Override
public List<ZkConfigAll> getRiskCtrolZkMonitorDetail(ZkTreeAllReq req) {
List<ZkConfigAll> resultList = new ArrayList<>();
//获取连接
CuratorFramework client = zkOnlineClientUtil.getOnlineCuratorFrameworkByKey(req.getIp());
try {
List<ZkConfigAll> allZkConfigs = getAllChildren(req.getZkPath(), client, req.getIp());//当前目录下所有的节点信息
if(CollectionUtils.isEmpty(allZkConfigs)){
logger.info("getRiskCtrolZkMonitorDetail-- allZkConfigs is empty");
return resultList;
}
//过滤--只保留风控相关的配置 并且按照类型 的名称 排序
List<String> filterNodeNames = RiskCtrolZkNodeEnum.getAllNodeNames();//相关的名称集合
//过滤 设置类型 并且排序
resultList = allZkConfigs.stream().filter(Objects::nonNull).filter(zk -> filterNodeNames.contains(zk.getZkName()))
.map(zk -> {zk.setConfigDesc(RiskCtrolZkNodeEnum.getTypeByNodeName(zk.getZkName()));return zk;})
.sorted(((o1, o2) -> o1.getConfigDesc().compareTo(o2.getConfigDesc())))
.collect(Collectors.toList());
} catch (Exception e) {
logger.error("getRiskCtrolZkMonitorDetail fail with ip is {} and path is {}, e: {} ",req.getIp(), req.getZkPath(), e);
return resultList;
}finally {
//client修改为缓存的方式不再需要关闭了,并且不能关闭
//client.close();
}
logger.info("getRiskCtrolZkMonitorDetail success, resultList is {}", resultList);
return resultList;
}
/*public static int compareByZkType(ZkConfigAll zk1, ZkConfigAll zk2) {
String type_zk1 = RiskCtrolZkNodeEnum.getTypeByNodeName(zk1.getZkName());
String type_zk2 = RiskCtrolZkNodeEnum.getTypeByNodeName(zk2.getZkName());
return type_zk1.compareTo(type_zk2);
}*/
public List<ZkConfigAll> getAllChildren(String parentPath,CuratorFramework client,String ip) {
List<ZkConfigAll> childList=new ArrayList<ZkConfigAll>();
try {
... ...