This commit is contained in:
rouja 2025-03-24 18:07:38 +00:00 committed by GitHub
commit af2078423d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View File

@ -24,6 +24,7 @@ const { CookieJar } = require("tough-cookie");
const { HttpsCookieAgent } = require("http-cookie-agent/http");
const https = require("https");
const http = require("http");
const tls = require("tls");
const rootCertificates = rootCertificatesFingerprints();
@ -613,6 +614,45 @@ class Monitor extends BeanModel {
} else if (this.type === "port") {
bean.ping = await tcping(this.hostname, this.port);
if (this.isEnabledExpiryNotification()) {
const host = this.hostname;
const port = this.port || 443;
try {
const options = {
host,
port,
servername: host,
};
// Convert TLS connect to a Promise and await it
const tlsInfoObject = await new Promise((resolve, reject) => {
const socket = tls.connect(options);
socket.on("secureConnect", () => {
try {
const info = checkCertificate(socket);
socket.end();
resolve(info);
} catch (error) {
socket.end();
reject(error);
}
});
socket.on("error", (error) => {
reject(error);
});
socket.setTimeout(10000, () => {
socket.end();
reject(new Error("Connection timed out"));
});
});
await this.handleTlsInfo(tlsInfoObject);
} catch (error) {
console.log("Retrieve certificate failed");
}
}
bean.msg = "";
bean.status = UP;

View File

@ -612,7 +612,7 @@
<h2 v-if="monitor.type !== 'push'" class="mt-5 mb-2">{{ $t("Advanced") }}</h2>
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' " class="my-3 form-check" :title="monitor.ignoreTls ? $t('ignoredTLSError') : ''">
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'port' " class="my-3 form-check" :title="monitor.ignoreTls ? $t('ignoredTLSError') : ''">
<input id="expiry-notification" v-model="monitor.expiryNotification" class="form-check-input" type="checkbox" :disabled="monitor.ignoreTls">
<label class="form-check-label" for="expiry-notification">
{{ $t("Certificate Expiry Notification") }}