minor bug fixes
This commit is contained in:
parent
67b41fb91a
commit
3a4b543754
2 changed files with 4 additions and 2 deletions
|
@ -11,4 +11,4 @@ RUN mkdir -p /monitor/data \
|
||||||
&& npm install \
|
&& npm install \
|
||||||
&& apk del git
|
&& apk del git
|
||||||
|
|
||||||
CMD npm run start
|
CMD ["node", "index.js"]
|
4
index.js
4
index.js
|
@ -6,6 +6,8 @@ const abort = require('abort-controller');
|
||||||
const nmap = require('libnmap');
|
const nmap = require('libnmap');
|
||||||
|
|
||||||
const cache = fs.existsSync("data/cache.json") ? JSON.parse(fs.readFileSync("data/cache.json", {encoding: "utf8"})) : {};
|
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', () => {
|
process.on('SIGINT', () => {
|
||||||
fs.writeFileSync("data/cache.json", JSON.stringify(cache), {encoding: "utf8"});
|
fs.writeFileSync("data/cache.json", JSON.stringify(cache), {encoding: "utf8"});
|
||||||
|
@ -85,7 +87,7 @@ async function checkStatus(service) {
|
||||||
const checkService = async (service, oldStatus) => {
|
const checkService = async (service, oldStatus) => {
|
||||||
const newStatus = await checkStatus(service);
|
const newStatus = await checkStatus(service);
|
||||||
newStatus.changed = new Date().getTime();
|
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) {
|
oldStatus.changed + config.offlineTimeUntilMajor * 1000 < newStatus.changed) {
|
||||||
newStatus.status = "INCIDENT";
|
newStatus.status = "INCIDENT";
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue