Commit 6f0c2c4e authored by renjie's avatar renjie

健康检查

parent e9a05d94
...@@ -37,6 +37,7 @@ public class IpResource implements Serializable { ...@@ -37,6 +37,7 @@ public class IpResource implements Serializable {
private double price; private double price;
private boolean specialLine; //是否使用专线 private boolean specialLine; //是否使用专线
private boolean usingSpecialLine; //是否正在使用专线
//专线数据 //专线数据
private String proxyUsername; //专线的代理用户名 private String proxyUsername; //专线的代理用户名
private String proxyPassword; //专线的代理密码 private String proxyPassword; //专线的代理密码
...@@ -293,4 +294,12 @@ public class IpResource implements Serializable { ...@@ -293,4 +294,12 @@ public class IpResource implements Serializable {
public void setHealthLockTimestamp(long healthLockTimestamp) { public void setHealthLockTimestamp(long healthLockTimestamp) {
this.healthLockTimestamp = healthLockTimestamp; this.healthLockTimestamp = healthLockTimestamp;
} }
public boolean isUsingSpecialLine() {
return usingSpecialLine;
}
public void setUsingSpecialLine(boolean usingSpecialLine) {
this.usingSpecialLine = usingSpecialLine;
}
} }
...@@ -231,16 +231,33 @@ public class BrowserTask { ...@@ -231,16 +231,33 @@ public class BrowserTask {
if (ipResource.isSpecialLine()) { if (ipResource.isSpecialLine()) {
Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword()); Trans trans = new Trans(ipResource.getProxyUsername(), ipResource.getProxyPassword());
String sp_result = trans.get(queryIpUrlList.getUrl(), true); String sp_result = trans.get(queryIpUrlList.getUrl(), true);
if (!sp_result.contains(ipResource.getAddr())) int failTime = 0;
while (!sp_result.contains(ipResource.getAddr())) {
failTime ++;
Thread.sleep(2000);
sp_result = trans.get(queryIpUrlList.getUrl(), true);
if (failTime >= 5) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常", NotifyUtils.MsgType.WEBHOOK); NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常", NotifyUtils.MsgType.WEBHOOK);
log.error(sp_result); log.error("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常 " + sp_result);
break;
}
}
} }
String result; String result;
Trans trans = new Trans(ipResource.getAddr(), Integer.valueOf(ipResource.getPort().size() > 1?ipResource.getPort().get(1):ipResource.getPort().get(0)), ipResource.getUsername(), ipResource.getPassword()); 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(queryIpUrlList.getUrl(), false); result = trans.get(queryIpUrlList.getUrl(), false);
if (!result.contains(ipResource.getAddr())) { if (!result.contains(ipResource.getAddr())) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常 " + result, NotifyUtils.MsgType.WEBHOOK); int failTime = 0;
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常 " + result); while (!result.contains(ipResource.getAddr())) {
failTime ++;
Thread.sleep(2000);
result = trans.get(queryIpUrlList.getUrl(), true);
if (failTime >= 5) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常", NotifyUtils.MsgType.WEBHOOK);
log.error("防关联浏览器 ip " + ipResource.getAddr() + " 专线代理异常 " + result);
break;
}
}
} }
} catch (Exception e) { } catch (Exception e) {
NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK); NotifyUtils.sendMessage("防关联浏览器 ip " + ipResource.getAddr() + " 代理异常", e, NotifyUtils.MsgType.WEBHOOK);
......
...@@ -47,7 +47,6 @@ public class Set3proxyTask { ...@@ -47,7 +47,6 @@ public class Set3proxyTask {
@Scheduled(cron = "0 0/10 * * * ?") @Scheduled(cron = "0 0/10 * * * ?")
@SchedulerLock(name = "proxyTask", lockAtLeastFor = 60*1000*5, lockAtMostFor = 60*1000*9) @SchedulerLock(name = "proxyTask", lockAtLeastFor = 60*1000*5, lockAtMostFor = 60*1000*9)
public void set3proxy() { public void set3proxy() {
long validTime = Instant.now().minusSeconds(43200).toEpochMilli();
long nowtime = Instant.now().toEpochMilli(); long nowtime = Instant.now().toEpochMilli();
// List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList()); // List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList());
// List<String> accountParents = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList()); // List<String> accountParents = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList());
...@@ -71,6 +70,7 @@ public class Set3proxyTask { ...@@ -71,6 +70,7 @@ public class Set3proxyTask {
for (IpResource ipResource : ipResources) { for (IpResource ipResource : ipResources) {
if (StringUtils.isNotBlank(ipResource.getAddr())) if (StringUtils.isNotBlank(ipResource.getAddr()))
bw.write("users \"" + ipResource.getProxyUsername() + ":CL:" + ipResource.getProxyPassword() + "\"\n"); bw.write("users \"" + ipResource.getProxyUsername() + ":CL:" + ipResource.getProxyPassword() + "\"\n");
ipResource.setUsingSpecialLine(true);
} }
bw.write("\nauth strong\n"); bw.write("\nauth strong\n");
...@@ -102,6 +102,7 @@ public class Set3proxyTask { ...@@ -102,6 +102,7 @@ public class Set3proxyTask {
proxyConfigRepository.updateProxy(file, nowtime); proxyConfigRepository.updateProxy(file, nowtime);
file.delete(); file.delete();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("出错了"); log.error("出错了");
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
......
...@@ -62,9 +62,9 @@ public class NotifyUtils { ...@@ -62,9 +62,9 @@ public class NotifyUtils {
} catch (Exception e) { } catch (Exception e) {
} }
if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) { // if (!StringUtils.isEmpty(env) && !env.equalsIgnoreCase("prod")) {
return; // return;
} // }
String envPrefix = "执行环境: " + env + "\n"; String envPrefix = "执行环境: " + env + "\n";
text.put("content", envPrefix + message.getContent()); text.put("content", envPrefix + message.getContent());
json.put("text", text); json.put("text", text);
......
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