Commit 6f0c2c4e authored by renjie's avatar renjie

健康检查

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