|
|
|
@ -451,29 +451,34 @@ class Monitor extends BeanModel {
|
|
|
|
|
let tls_info_bean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
|
|
|
|
this.id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (tls_info_bean == null) {
|
|
|
|
|
tls_info_bean = R.dispense("monitor_tls_info");
|
|
|
|
|
tls_info_bean.monitor_id = this.id;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// Clear sent history if the cert changed.
|
|
|
|
|
let oldCertInfo = JSON.parse(tls_info_bean.info_json);
|
|
|
|
|
// Clear sent history if the cert changed.
|
|
|
|
|
try {
|
|
|
|
|
let oldCertInfo = JSON.parse(tls_info_bean.info_json);
|
|
|
|
|
|
|
|
|
|
let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo;
|
|
|
|
|
let isValidObjects = oldCertInfo && oldCertInfo.certInfo && checkCertificateResult && checkCertificateResult.certInfo;
|
|
|
|
|
|
|
|
|
|
if (isValidObjects) {
|
|
|
|
|
if (oldCertInfo.certInfo.fingerprint256 !== checkCertificateResult.certInfo.fingerprint256) {
|
|
|
|
|
debug("Resetting sent_history");
|
|
|
|
|
await R.exec("DELETE FROM notification_sent_history WHERE type = 'certificate' AND monitor_id = ?", [
|
|
|
|
|
this.id
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
debug("No need to reset sent_history");
|
|
|
|
|
debug(oldCertInfo.certInfo.fingerprint256);
|
|
|
|
|
debug(checkCertificateResult.certInfo.fingerprint256);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debug("Not valid object");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { }
|
|
|
|
|
|
|
|
|
|
if (isValidObjects) {
|
|
|
|
|
if (oldCertInfo.certInfo.fingerprint256 !== checkCertificateResult.certInfo.fingerprint256) {
|
|
|
|
|
debug("Resetting sent_history");
|
|
|
|
|
await R.exec("DELETE FROM notification_sent_history WHERE type = 'certificate' AND monitor_id = ?", [
|
|
|
|
|
this.id
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
debug("No need to reset sent_history");
|
|
|
|
|
debug(oldCertInfo.certInfo.fingerprint256);
|
|
|
|
|
debug(checkCertificateResult.certInfo.fingerprint256);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debug("Not valid object");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tls_info_bean.info_json = JSON.stringify(checkCertificateResult);
|
|
|
|
@ -690,7 +695,7 @@ class Monitor extends BeanModel {
|
|
|
|
|
for (let notification of notificationList) {
|
|
|
|
|
try {
|
|
|
|
|
debug("Sending to " + notification.name);
|
|
|
|
|
await Notification.send(JSON.parse(notification.config), `The certificate of ${this.url} will be expired in ${daysRemaining} days`);
|
|
|
|
|
await Notification.send(JSON.parse(notification.config), `[${this.name}][${this.url}] Certificate will be expired in ${daysRemaining} days`);
|
|
|
|
|
sent = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error("Cannot send cert notification to " + notification.name);
|
|
|
|
|