mirror of https://github.com/certd/certd
perf: 站点IP监控前先同步一下IP
parent
7c0f43c8a3
commit
a080b606ab
|
@ -17,12 +17,12 @@
|
|||
</div>
|
||||
<div class="helper">{{ t("certd.monitor.setting.monitorRetryTimes") }}</div>
|
||||
</a-form-item>
|
||||
<a-form-item :label="t('certd.monitor.setting.dnsServer')" :name="['dnsServer']">
|
||||
<!-- <a-form-item :label="t('certd.monitor.setting.dnsServer')" :name="['dnsServer']">
|
||||
<div class="flex">
|
||||
<a-select v-model:value="formState.dnsServer" mode="tags" :open="false" />
|
||||
</div>
|
||||
<div class="helper">{{ t("certd.monitor.setting.dnsServerHelper") }}</div>
|
||||
</a-form-item>
|
||||
</a-form-item> -->
|
||||
<a-form-item :label="t('certd.monitor.setting.monitorCronSetting')" :name="['cron']">
|
||||
<div class="flex flex-baseline">
|
||||
<cron-editor v-model="formState.cron" :disabled="!settingsStore.isPlus" :allow-every-min="userStore.isAdmin" />
|
||||
|
|
|
@ -96,7 +96,7 @@ export class SiteInfoController extends CrudController<SiteIpService> {
|
|||
const userId = this.getUserId();
|
||||
await this.siteInfoService.checkUserId(siteId, userId);
|
||||
const siteEntity = await this.siteInfoService.info(siteId);
|
||||
await this.service.checkAll(siteEntity);
|
||||
await this.service.syncAndCheck(siteEntity);
|
||||
return this.ok();
|
||||
}
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
|
|||
logger.error("send notify error", e);
|
||||
}
|
||||
};
|
||||
await this.siteIpService.checkAll(site, retryTimes,onFinished);
|
||||
await this.siteIpService.syncAndCheck(site, retryTimes,onFinished);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,33 +59,58 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
|
||||
|
||||
|
||||
async sync(entity: SiteInfoEntity) {
|
||||
async sync(entity: SiteInfoEntity,check:boolean = true) {
|
||||
|
||||
const domain = entity.domain;
|
||||
//从域名解析中获取所有ip
|
||||
const ips = await this.getAllIpsFromDomain(domain);
|
||||
if (ips.length === 0 ) {
|
||||
throw new Error(`没有发现${domain}的IP`)
|
||||
logger.warn(`没有发现${domain}的IP`)
|
||||
return
|
||||
}
|
||||
//删除所有的ip
|
||||
await this.repository.delete({
|
||||
siteId: entity.id,
|
||||
from: "sync"
|
||||
});
|
||||
|
||||
//添加新的ip
|
||||
for (const ip of ips) {
|
||||
await this.repository.save({
|
||||
ipAddress: ip,
|
||||
userId: entity.userId,
|
||||
const oldIps = await this.repository.find({
|
||||
where:{
|
||||
siteId: entity.id,
|
||||
from:"sync"
|
||||
}
|
||||
})
|
||||
|
||||
let hasChanged = true
|
||||
if (oldIps.length === ips.length ){
|
||||
//检查是否有变化
|
||||
const oldIpList = oldIps.map(ip=>ip.ipAddress).sort().join(",")
|
||||
const newIpList = ips.filter(ip=>!oldIpList.includes(ip)).sort().join(",")
|
||||
if(oldIpList === newIpList){
|
||||
//无变化
|
||||
hasChanged = false
|
||||
}
|
||||
}
|
||||
|
||||
if(hasChanged){
|
||||
logger.info(`发现${domain}的IP变化,需要更新,旧IP:${oldIps.map(ip=>ip.ipAddress).join(",")},新IP:${ips.join(",")}`)
|
||||
//有变化需要更新
|
||||
//删除所有的ip
|
||||
await this.repository.delete({
|
||||
siteId: entity.id,
|
||||
from: "sync",
|
||||
disabled:false,
|
||||
from: "sync"
|
||||
});
|
||||
}
|
||||
|
||||
await this.checkAll(entity);
|
||||
await this.updateIpCount(entity.id)
|
||||
//添加新的ip
|
||||
for (const ip of ips) {
|
||||
await this.repository.save({
|
||||
ipAddress: ip,
|
||||
userId: entity.userId,
|
||||
siteId: entity.id,
|
||||
from: "sync",
|
||||
disabled:false,
|
||||
});
|
||||
await this.updateIpCount(entity.id)
|
||||
}
|
||||
}
|
||||
if (check){
|
||||
await this.checkAll(entity);
|
||||
}
|
||||
}
|
||||
|
||||
async check(ipId: number, domain: string, port: number,retryTimes = null) {
|
||||
|
@ -278,4 +303,9 @@ export class SiteIpService extends BaseService<SiteIpEntity> {
|
|||
};
|
||||
await batchAdd(list);
|
||||
}
|
||||
|
||||
async syncAndCheck(siteEntity:SiteInfoEntity,retryTimes = null,onFinish?: (e: any) => void){
|
||||
await this.sync(siteEntity,false);
|
||||
await this.checkAll(siteEntity,retryTimes,onFinish);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue