Added health checker.
This commit is contained in:
parent
35e27546b7
commit
dffd4b0507
|
@ -1,9 +1,52 @@
|
|||
|
||||
import getLogger from "../../libs/logger.js"
|
||||
import settings from "../../libs/settings.js"
|
||||
import settings from "../../libs/settings.js"
|
||||
import https from "https"
|
||||
|
||||
const log = getLogger("Health Checker", settings.checkers["health-checker"].color)
|
||||
|
||||
export function start() {
|
||||
log("Starting up the health checker...")
|
||||
function checkService(serviceDomain) {
|
||||
log(`Checking service '${serviceDomain}'`)
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
const req = https.request({
|
||||
hostname: serviceDomain,
|
||||
port: 443,
|
||||
path: "/",
|
||||
method: "GET"
|
||||
}, res => {
|
||||
if (res.statusCode === 200) resolve(`Service '${serviceDomain}' seems to be running!`)
|
||||
res.on("error", () => reject(`Service '${serviceDomain}' seems to have stopped!`))
|
||||
})
|
||||
req.on("error", () => reject(`Service '${serviceDomain}' seems to have stopped!`))
|
||||
req.end()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function start(sendMessage) {
|
||||
log("Starting up the health checker...")
|
||||
log("Services to watch:", settings.checkers["health-checker"].services)
|
||||
|
||||
function checkServices(serviceDomains) {
|
||||
for (const serviceDomain of serviceDomains) {
|
||||
checkService(serviceDomain).then(
|
||||
status => log(status)
|
||||
).catch(
|
||||
status => {
|
||||
log(status)
|
||||
sendMessage(status)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
checkServices(settings.checkers["health-checker"].services)
|
||||
|
||||
setInterval(
|
||||
() => checkServices(settings.checkers["health-checker"].services),
|
||||
(settings.checkers["health-checker"].interval ?? 300) * 1000
|
||||
)
|
||||
|
||||
return
|
||||
}
|
|
@ -12,7 +12,7 @@ const currentIp = await getIp()
|
|||
const cachedOldIp = fs.readFileSync("./ip.cache").toString()
|
||||
let oldIp = cachedOldIp ? oldIp : currentIp
|
||||
|
||||
async function checkIp() {
|
||||
async function checkIp(sendMessage) {
|
||||
log("Checking for IP changes...")
|
||||
const nowIp = await getIp()
|
||||
if (nowIp !== oldIp) {
|
||||
|
@ -27,7 +27,11 @@ async function checkIp() {
|
|||
|
||||
export async function start(sendMessage) {
|
||||
log("Starting up the IP watcher...")
|
||||
checkIp()
|
||||
setInterval(checkIp, (settings.checkers["ip-changed"].interval ?? 3600) * 1000)
|
||||
checkIp(sendMessage)
|
||||
setInterval(
|
||||
() => checkIp(sendMessage),
|
||||
(settings.checkers["ip-changed"].interval ?? 3600) * 1000
|
||||
)
|
||||
|
||||
return
|
||||
}
|
|
@ -13,7 +13,7 @@ export async function start() {
|
|||
password: settings.notifiers.xmpp.sender.pass
|
||||
})
|
||||
|
||||
xmpp.on("error", err => console.error(err))
|
||||
xmpp.on("error", err => console.error(err))
|
||||
xmpp.on("offline", () => console.log("OFFLINE!"))
|
||||
|
||||
async function sendMessage(msg) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user