Refactored to deal with empty data set
This commit is contained in:
1 parent
68cb5b4597
commit
d883898384
3 files changed
+30
-15
No files matched your search
@@ -9,6 +9,25 @@ import HostStatus from "../HostStatus";
|
|||||||
* @param {Array<Monitor>} monitors - An array of monitor objects to be displayed.
|
* @param {Array<Monitor>} monitors - An array of monitor objects to be displayed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const getLastCheckStatus = (monitor) => {
|
||||||
|
if (monitor.checks.length === 0) {
|
||||||
|
// Default values for when there are no checks
|
||||||
|
return {
|
||||||
|
color: "var(--env-var-color-21)",
|
||||||
|
statusText: "No Data",
|
||||||
|
dotColor: "var(--env-var-color-19)",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastCheck = monitor.checks[monitor.checks.length - 1];
|
||||||
|
const isUp = lastCheck.status === true;
|
||||||
|
return {
|
||||||
|
color: isUp ? "var(--env-var-color-20)" : "var(--env-var-color-21)",
|
||||||
|
statusText: isUp ? "Up" : "Down",
|
||||||
|
dotColor: isUp ? "var(--env-var-color-17)" : "var(--env-var-color-19)",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const HostsTable = ({ monitors }) => {
|
const HostsTable = ({ monitors }) => {
|
||||||
return (
|
return (
|
||||||
<div className="current-monitors-table-holder">
|
<div className="current-monitors-table-holder">
|
||||||
@@ -30,17 +49,10 @@ const HostsTable = ({ monitors }) => {
|
|||||||
monitor.url
|
monitor.url
|
||||||
);
|
);
|
||||||
|
|
||||||
const status = HostStatus(
|
const { color, currentStatus, dotColor } =
|
||||||
monitor.checks[monitor.checks.length - 1].status === true
|
getLastCheckStatus(monitor);
|
||||||
? "var(--env-var-color-20)"
|
|
||||||
: "var(--env-var-color-21)",
|
const status = HostStatus(color, currentStatus, dotColor);
|
||||||
monitor.checks[monitor.checks.length - 1].status === true
|
|
||||||
? "Up"
|
|
||||||
: "Down",
|
|
||||||
monitor.checks[monitor.checks.length - 1].status === true
|
|
||||||
? "var(--env-var-color-17)"
|
|
||||||
: "var(--env-var-color-19)"
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className="tbody-row" key={monitor._id}>
|
<tr className="tbody-row" key={monitor._id}>
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
const CurrentStats = ({ monitors }) => {
|
const CurrentStats = ({ monitors }) => {
|
||||||
const up = monitors.reduce((acc, cur) => {
|
const up = monitors.reduce((acc, cur) => {
|
||||||
if (cur.checks) {
|
if (cur.checks.length > 0) {
|
||||||
return cur.checks[cur.checks.length - 1].status === true ? acc + 1 : acc;
|
return cur.checks[cur.checks.length - 1].status === true ? acc + 1 : acc;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
const down = monitors.reduce((acc, cur) => {
|
const down = monitors.reduce((acc, cur) => {
|
||||||
if (cur.checks) {
|
if (cur.checks.length > 0) {
|
||||||
return cur.checks[cur.checks.length - 1].status === false ? acc + 1 : acc;
|
return cur.checks[cur.checks.length - 1].status === false ? acc + 1 : acc;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const axios = require("axios");
|
|||||||
const ping = require("ping");
|
const ping = require("ping");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const Check = require("../models/Check");
|
const Check = require("../models/Check");
|
||||||
|
const { Console } = require("winston/lib/winston/transports");
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
@@ -149,9 +150,9 @@ class NetworkService {
|
|||||||
const insertedCheck = await check.save();
|
const insertedCheck = await check.save();
|
||||||
return insertedCheck.status;
|
return insertedCheck.status;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error wrtiting check for ${job.id}`, {
|
logger.error(`Error wrtiting check for ${check.monitorId}`, {
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
jobId: job.id,
|
monitorId: check.monitorId,
|
||||||
error: error,
|
error: error,
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user