mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-02-05 16:48:32 -06:00
Refactored to deal with empty data set
This commit is contained in:
@@ -9,6 +9,25 @@ import HostStatus from "../HostStatus";
|
||||
* @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 }) => {
|
||||
return (
|
||||
<div className="current-monitors-table-holder">
|
||||
@@ -30,17 +49,10 @@ const HostsTable = ({ monitors }) => {
|
||||
monitor.url
|
||||
);
|
||||
|
||||
const status = HostStatus(
|
||||
monitor.checks[monitor.checks.length - 1].status === true
|
||||
? "var(--env-var-color-20)"
|
||||
: "var(--env-var-color-21)",
|
||||
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)"
|
||||
);
|
||||
const { color, currentStatus, dotColor } =
|
||||
getLastCheckStatus(monitor);
|
||||
|
||||
const status = HostStatus(color, currentStatus, dotColor);
|
||||
|
||||
return (
|
||||
<tr className="tbody-row" key={monitor._id}>
|
||||
|
||||
@@ -12,15 +12,17 @@ import PropTypes from "prop-types";
|
||||
|
||||
const CurrentStats = ({ monitors }) => {
|
||||
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 0;
|
||||
}, 0);
|
||||
|
||||
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 0;
|
||||
}, 0);
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,6 +2,7 @@ const axios = require("axios");
|
||||
const ping = require("ping");
|
||||
const logger = require("../utils/logger");
|
||||
const Check = require("../models/Check");
|
||||
const { Console } = require("winston/lib/winston/transports");
|
||||
|
||||
class NetworkService {
|
||||
constructor(db) {
|
||||
@@ -149,9 +150,9 @@ class NetworkService {
|
||||
const insertedCheck = await check.save();
|
||||
return insertedCheck.status;
|
||||
} catch (error) {
|
||||
logger.error(`Error wrtiting check for ${job.id}`, {
|
||||
logger.error(`Error wrtiting check for ${check.monitorId}`, {
|
||||
service: this.SERVICE_NAME,
|
||||
jobId: job.id,
|
||||
monitorId: check.monitorId,
|
||||
error: error,
|
||||
});
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user