Commit 12206673 authored by xuxin's avatar xuxin

去除对客户自有的且不走专线的ip的健康检查

parent 06880979
......@@ -206,15 +206,11 @@ public class BrowserTask {
() -> {
if (ipResourceRepository.lockTask(ipResource)) {
try {
log.error("test");
String url = URL + "/ecc/ipinfo?accountId=browser&ip=" + ipResource.getAddr();
Map<String, String> header = buildGetHeader();
String rs = HttpClientutils.doGet(url, header);
IpInfoResultDto ipInfoResultDto = JSONObject.parseObject(rs, IpInfoResultDto.class);
if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
log.error(ipInfoResultDto.getErrorCode());
log.error(ipInfoResultDto.getStatus());
log.error(ipInfoResultDto.getEipIPAddr());
if (StringUtils.isNotEmpty(ipInfoResultDto.getStatus())) {
ipResourceRepository.updateStatus(ipResource.getId(), 0);
}
......@@ -242,25 +238,31 @@ public class BrowserTask {
@Scheduled(cron = "0 0/5 * * * ?")
public void healthCheck() {
// 1. 随机获取未被删除的 20 个 ip 做健康检查
List<IpResource> ipResources = ipResourceRepository.sampleTasks(Arrays.asList(0, 2));
for (IpResource ipResource : ipResources) {
long start = System.currentTimeMillis();
// todo ipResourceRepository.healthLock(ipResource) 始终为 true,感觉有些多余
if (ipResourceRepository.healthLock(ipResource)) {
try {
int failTime = 0;
// 获取查询 ip 地址的 5个网址
List<QueryIpUrlList> queryIpUrlLists = queryIpUrlListRepository.findAll();
final int maxRetry = Math.max(queryIpUrlLists.size(), 5);
// 如果 ip 已经失效,且 ip 的状态不是 3:正在分配 和 6:未分配,则将 ip 的状态设置为 1 已过期
if (ipResource.getValidTime() <= Instant.now().toEpochMilli() && ipResource.getStatus() != 3 && ipResource.getStatus() != 6) {
ipResource.setStatus(1);
ipResourceRepository.save(ipResource);
// 如果 ip 为专线 ip,或者 ip 为用户自己的,但是使用了系统的专线功能
} else if (ipResource.isSpecialLine() || (ipResource.getIpType() == IpType.OWN && ipResource.isUsingSpecialLine())) {
Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword());
String sp_result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
while (!sp_result.contains(ipResource.getAddr())) {
if (failTime > maxRetry) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常:" + ipResource.getIpType(),
NotifyUtils.MsgType.WEBHOOK);
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常:" + ipResource.getIpType(), NotifyUtils.MsgType.WEBHOOK);
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常 " + sp_result);
break;
}
......@@ -268,16 +270,15 @@ public class BrowserTask {
Thread.sleep(2000);
sp_result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
}
} else if (ipResource.getIpType() == IpType.VENDOR
|| (ipResource.getIpType() == IpType.OWN && !ipResource.isUsingSpecialLine())) {
String result;
// 如果 ip 类型为 vendor
} else if (ipResource.getIpType() == IpType.VENDOR) {
Trans trans = new Trans(ipResource.getAddr(), Integer.valueOf(ipResource.getPort().size() > 1 ? ipResource.getPort().get(1) : ipResource.getPort().get(0)), ipResource.getUsername(), ipResource.getPassword());
result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
String result = trans.get(getNextUrl(queryIpUrlLists, failTime).getUrl());
if (!result.contains(ipResource.getAddr())) {
while (!result.contains(ipResource.getAddr())) {
if (failTime > maxRetry) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常:" + ipResource.getIpType(),
NotifyUtils.MsgType.WEBHOOK);
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常:" + ipResource.getIpType(), NotifyUtils.MsgType.WEBHOOK);
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常 " + result);
break;
}
......@@ -288,7 +289,8 @@ public class BrowserTask {
}
}
} catch (Exception e) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
// todo 将代理异常改为 健康检查异常
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 健康检查异常", e, NotifyUtils.MsgType.WEBHOOK);
log.error(e.getMessage(), e);
} finally {
long end = System.currentTimeMillis();
......
......@@ -59,7 +59,9 @@ public class Trans {
String url = "http://free.ipwhois.io/json/";
Trans trans = new Trans("112.74.47.217", 20001, "fangguanlianbrowser", "5D753F36QKqIaA1");
String rs = trans.get(url);
System.out.println(rs);
System.out.println(rs.contains("112.74.47.217"));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment