chore: improve some domain expiry logs (#6623)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
07d3dce3d6
commit
56175bce85
@ -86,19 +86,18 @@ async function getRdapDomainExpiryDate(domain) {
|
|||||||
*/
|
*/
|
||||||
async function sendDomainNotificationByTargetDays(domain, daysRemaining, targetDays, notificationList) {
|
async function sendDomainNotificationByTargetDays(domain, daysRemaining, targetDays, notificationList) {
|
||||||
let sent = false;
|
let sent = false;
|
||||||
log.debug("domain", `Send domain expiry notification for ${targetDays} deadline.`);
|
log.debug("domain_expiry", `Send domain expiry notification for ${targetDays} deadline.`);
|
||||||
|
|
||||||
for (let notification of notificationList) {
|
for (let notification of notificationList) {
|
||||||
try {
|
try {
|
||||||
log.debug("domain", `Sending to ${notification.name}`);
|
log.debug("domain_expiry", `Sending to ${notification.name}`);
|
||||||
await Notification.send(
|
await Notification.send(
|
||||||
JSON.parse(notification.config),
|
JSON.parse(notification.config),
|
||||||
`Domain name ${domain} will expire in ${daysRemaining} days`
|
`Domain name ${domain} will expire in ${daysRemaining} days`
|
||||||
);
|
);
|
||||||
sent = true;
|
sent = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("domain", `Cannot send domain notification to ${notification.name}`);
|
log.error("domain_expiry", `Cannot send domain notification to ${notification.name}:`, e);
|
||||||
log.error("domain", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +151,7 @@ class DomainExpiry extends BeanModel {
|
|||||||
const tld = parseTld(urlTypes.includes(m.type) ? m.url : m.type === "grpc-keyword" ? m.grpcUrl : m.hostname);
|
const tld = parseTld(urlTypes.includes(m.type) ? m.url : m.type === "grpc-keyword" ? m.grpcUrl : m.hostname);
|
||||||
const rdap = await getRdapServer(tld.publicSuffix);
|
const rdap = await getRdapServer(tld.publicSuffix);
|
||||||
if (!rdap) {
|
if (!rdap) {
|
||||||
log.warn("domain", `Domain expiry unsupported for '.${tld.publicSuffix}' because its RDAP endpoint is not listed in the IANA database.`);
|
log.warn("domain_expiry", `Domain expiry unsupported for '.${tld.publicSuffix}' because its RDAP endpoint is not listed in the IANA database.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const existing = await DomainExpiry.findByName(tld.domain);
|
const existing = await DomainExpiry.findByName(tld.domain);
|
||||||
@ -188,7 +187,7 @@ class DomainExpiry extends BeanModel {
|
|||||||
|
|
||||||
let expiryDate;
|
let expiryDate;
|
||||||
if (bean?.lastCheck && getDaysBetween(new Date(bean.lastCheck), new Date()) < 1) {
|
if (bean?.lastCheck && getDaysBetween(new Date(bean.lastCheck), new Date()) < 1) {
|
||||||
log.debug("domain", `Domain expiry already checked recently for ${bean.domain}, won't re-check.`);
|
log.debug("domain_expiry", `Domain expiry already checked recently for ${bean.domain}, won't re-check.`);
|
||||||
return bean.expiry;
|
return bean.expiry;
|
||||||
} else if (bean) {
|
} else if (bean) {
|
||||||
expiryDate = await bean.getExpiryDate();
|
expiryDate = await bean.getExpiryDate();
|
||||||
@ -220,13 +219,13 @@ class DomainExpiry extends BeanModel {
|
|||||||
|
|
||||||
if (!notificationList.length > 0) {
|
if (!notificationList.length > 0) {
|
||||||
// fail fast. If no notification is set, all the following checks can be skipped.
|
// fail fast. If no notification is set, all the following checks can be skipped.
|
||||||
log.debug("domain", "No notification, no need to send domain notification");
|
log.debug("domain_expiry", "No notification, no need to send domain notification");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const daysRemaining = getDaysRemaining(new Date(), domain.expiry);
|
const daysRemaining = getDaysRemaining(new Date(), domain.expiry);
|
||||||
const lastSent = domain.lastExpiryNotificationSent;
|
const lastSent = domain.lastExpiryNotificationSent;
|
||||||
log.debug("domain", `${name} expires in ${daysRemaining} days`);
|
log.debug("domain_expiry", `${name} expires in ${daysRemaining} days`);
|
||||||
|
|
||||||
let notifyDays = await setting("domainExpiryNotifyDays");
|
let notifyDays = await setting("domainExpiryNotifyDays");
|
||||||
if (notifyDays == null || !Array.isArray(notifyDays)) {
|
if (notifyDays == null || !Array.isArray(notifyDays)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user