Merge pull request #784 from bluewave-labs/revert-782-feat/indeterminate-state

Revert "Add indeterminate state to monitors, resolves #765"
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-09-03 10:07:04 -07:00
commit f10a7d7f25
6 files changed
+36 -49

No files matched your search

+1 -7
View File
@@ -126,7 +126,6 @@ ColoredLabel.propTypes = {
*/ */
const StatusLabel = ({ status, text, customStyles }) => { const StatusLabel = ({ status, text, customStyles }) => {
console.log(status);
const theme = useTheme(); const theme = useTheme();
const colors = { const colors = {
up: { up: {
@@ -139,11 +138,6 @@ const StatusLabel = ({ status, text, customStyles }) => {
bgColor: theme.palette.error.bg, bgColor: theme.palette.error.bg,
borderColor: theme.palette.error.light, borderColor: theme.palette.error.light,
}, },
unknown: {
dotColor: theme.palette.unresolved.main,
bgColor: theme.palette.unresolved.bg,
borderColor: theme.palette.unresolved.light,
},
"cannot resolve": { "cannot resolve": {
dotColor: theme.palette.unresolved.main, dotColor: theme.palette.unresolved.main,
bgColor: theme.palette.unresolved.bg, bgColor: theme.palette.unresolved.bg,
@@ -176,7 +170,7 @@ const StatusLabel = ({ status, text, customStyles }) => {
}; };
StatusLabel.propTypes = { StatusLabel.propTypes = {
status: PropTypes.oneOf(["up", "down", "unknown", "cannot resolve"]), status: PropTypes.oneOf(["up", "down", "cannot resolve"]),
text: PropTypes.string, text: PropTypes.string,
customStyles: PropTypes.object, customStyles: PropTypes.object,
}; };
@@ -48,6 +48,15 @@ export const buildData = (monitors, isAdmin, navigate) => {
monitor.uptimePercentage === 0 monitor.uptimePercentage === 0
? "0" ? "0"
: (monitor.uptimePercentage * 100).toFixed(2); : (monitor.uptimePercentage * 100).toFixed(2);
percentageColor =
monitor.uptimePercentage < 0.25
? theme.palette.percentage.uptimePoor
: monitor.uptimePercentage < 0.5
? theme.palette.percentage.uptimeFair
: monitor.uptimePercentage < 0.75
? theme.palette.percentage.uptimeGood
: theme.palette.percentage.uptimeExcellent;
} }
const params = { const params = {
-1
View File
@@ -359,7 +359,6 @@ const pauseMonitor = async (req, res, next) => {
await req.jobQueue.addJob(monitor._id, monitor); await req.jobQueue.addJob(monitor._id, monitor);
} }
monitor.isActive = !monitor.isActive; monitor.isActive = !monitor.isActive;
monitor.status = undefined;
monitor.save(); monitor.save();
return res.status(200).json({ return res.status(200).json({
success: true, success: true,
+1 -1
View File
@@ -24,7 +24,7 @@ const MonitorSchema = mongoose.Schema(
}, },
status: { status: {
type: Boolean, type: Boolean,
default: undefined, default: true,
}, },
type: { type: {
type: String, type: String,
+1
View File
@@ -238,6 +238,7 @@ class JobQueue {
console.log("Adding job", payload.url); console.log("Adding job", payload.url);
// Execute job immediately // Execute job immediately
await this.queue.add(jobName, payload); await this.queue.add(jobName, payload);
await this.queue.add(jobName, payload, { await this.queue.add(jobName, payload, {
repeat: { repeat: {
every: payload.interval, every: payload.interval,
+24 -40
View File
@@ -15,59 +15,43 @@ class NetworkService {
this.NETWORK_ERROR = 5000; this.NETWORK_ERROR = 5000;
} }
async handleNotification(monitor, isAlive) { async handleNotification(job, isAlive) {
try {
let template =
isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
let status = isAlive === true ? "up" : "down";
const notifications = await this.db.getNotificationsByMonitorId(
monitor._id
);
for (const notification of notifications) {
if (notification.type === "email") {
await this.emailService.buildAndSendEmail(
template,
{ monitorName: monitor.name, monitorUrl: monitor.url },
notification.address,
`Monitor ${monitor.name} is ${status}`
);
}
}
} catch (error) {
logger.error(error.message, {
method: "handleNotification",
service: this.SERVICE_NAME,
monitorId: monitor._id,
});
}
}
async handleStatusUpdate(job, isAlive) {
try { try {
const { _id } = job.data; const { _id } = job.data;
const monitor = await this.db.getMonitorById(_id); const monitor = await this.db.getMonitorById(_id);
if (monitor === null || monitor === undefined) { if (monitor === null || monitor === undefined) {
logger.error(`Null Monitor: ${_id}`, { logger.error(`Null Monitor: ${_id}`, {
method: "handleStatusUpdate", method: "handleNotification",
service: this.SERVICE_NAME, service: this.SERVICE_NAME,
jobId: job.id, jobId: job.id,
}); });
return; return;
} }
if (monitor.status === undefined || monitor.status !== isAlive) {
const oldStatus = monitor.status; // If monitor status changes, update monitor status and send notification
monitor.status = isAlive; if (monitor.status !== isAlive) {
monitor.status = !monitor.status;
await monitor.save(); await monitor.save();
if (oldStatus !== undefined && oldStatus !== isAlive) { let template =
this.handleNotification(monitor, isAlive); isAlive === true ? "serverIsUpTemplate" : "serverIsDownTemplate";
let status = isAlive === true ? "up" : "down";
const notifications = await this.db.getNotificationsByMonitorId(_id);
for (const notification of notifications) {
if (notification.type === "email") {
await this.emailService.buildAndSendEmail(
template,
{ monitorName: monitor.name, monitorUrl: monitor.url },
notification.address,
`Monitor ${monitor.name} is ${status}`
);
}
} }
} }
} catch (error) { } catch (error) {
logger.error(error.message, { logger.error(error.message, {
method: "handleStatusUpdate", method: "handleNotification",
service: this.SERVICE_NAME, service: this.SERVICE_NAME,
jobId: job.id, jobId: job.id,
}); });
@@ -129,7 +113,7 @@ class NetworkService {
}; };
return await this.logAndStoreCheck(checkData, this.db.createCheck); return await this.logAndStoreCheck(checkData, this.db.createCheck);
} finally { } finally {
this.handleStatusUpdate(job, isAlive); this.handleNotification(job, isAlive);
} }
} }
@@ -177,7 +161,7 @@ class NetworkService {
return await this.logAndStoreCheck(checkData, this.db.createCheck); return await this.logAndStoreCheck(checkData, this.db.createCheck);
} finally { } finally {
this.handleStatusUpdate(job, isAlive); this.handleNotification(job, isAlive);
} }
} }
@@ -257,7 +241,7 @@ class NetworkService {
}; };
this.logAndStoreCheck(checkData, this.db.createPageSpeedCheck); this.logAndStoreCheck(checkData, this.db.createPageSpeedCheck);
} finally { } finally {
this.handleStatusUpdate(job, isAlive); this.handleNotification(job, isAlive);
} }
} }