Files

51 lines
1.4 KiB
JavaScript

import https from "https";
export const name = "SpamTitan";
export const url = "https://mailportal.nhsd.net";
const HOST = "mailportal.nhsd.net";
const TIMEOUT_MS = 8000;
// TODO: TitanHQ has extensive API docs — investigate using the SpamTitan API
// for richer status data (queue depth, filtering stats, etc.) rather than
// a simple synthetic check.
// Synthetic check — hit the appliance directly and see if it responds.
// Uses https.request so we can skip self-signed cert verification.
function probe(host) {
return new Promise((resolve, reject) => {
const req = https.request(
{
hostname: host,
path: "/",
method: "HEAD",
rejectUnauthorized: false, // local appliance may have self-signed cert
timeout: TIMEOUT_MS,
},
(res) => resolve(res.statusCode)
);
req.on("timeout", () => {
req.destroy();
reject(new Error("Connection timed out"));
});
req.on("error", reject);
req.end();
});
}
export async function checkStatus() {
const statusCode = await probe(HOST);
const ok = statusCode >= 200 && statusCode < 400;
return {
name,
status: ok ? "operational" : "degraded",
message: ok
? `Mail portal responding (HTTP ${statusCode}).`
: `Unexpected response from mail portal (HTTP ${statusCode}).`,
lastUpdated: new Date().toISOString(),
};
}