From 3a4b54375428af6133ddde328a29167e5babbc0f Mon Sep 17 00:00:00 2001 From: samuel-p Date: Thu, 27 Feb 2020 20:02:03 +0100 Subject: [PATCH] minor bug fixes --- Dockerfile | 2 +- index.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 136eb50..9883413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,4 @@ RUN mkdir -p /monitor/data \ && npm install \ && apk del git -CMD npm run start \ No newline at end of file +CMD ["node", "index.js"] \ No newline at end of file diff --git a/index.js b/index.js index b826fdd..a8810e7 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,8 @@ const abort = require('abort-controller'); const nmap = require('libnmap'); const cache = fs.existsSync("data/cache.json") ? JSON.parse(fs.readFileSync("data/cache.json", {encoding: "utf8"})) : {}; +// delete cache file to remove orphaned cache values +fs.unlinkSync("data/cache.json"); process.on('SIGINT', () => { fs.writeFileSync("data/cache.json", JSON.stringify(cache), {encoding: "utf8"}); @@ -85,7 +87,7 @@ async function checkStatus(service) { const checkService = async (service, oldStatus) => { const newStatus = await checkStatus(service); newStatus.changed = new Date().getTime(); - if (newStatus.status === "OFFLINE" && ["OFFLINE", "INCIDENT"].includes(oldStatus.status) && + if (newStatus.status === "OFFLINE" && oldStatus && ["OFFLINE", "INCIDENT"].includes(oldStatus.status) && oldStatus.changed + config.offlineTimeUntilMajor * 1000 < newStatus.changed) { newStatus.status = "INCIDENT"; }