initial commit
This commit is contained in:
1 parent
d296aec02e
commit
7b658a9e52
3 files changed
+22
-46
No files matched your search
@@ -1,9 +1,6 @@
|
||||
import { Schema, model, Types, type UpdateQuery } from "mongoose";
|
||||
import type { Monitor, MonitorMatchMethod, MonitorThresholds, CheckSnapshot } from "@/types/monitor.js";
|
||||
import { MonitorTypes } from "@/types/monitor.js";
|
||||
import Check from "./Check.js";
|
||||
import MonitorStats from "./MonitorStats.js";
|
||||
import StatusPage from "./StatusPage.js";
|
||||
import { MonitorTypes, MonitorStatuses } from "@/types/monitor.js";
|
||||
|
||||
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
||||
|
||||
@@ -68,8 +65,9 @@ const MonitorSchema = new Schema<MonitorDocument>(
|
||||
type: String,
|
||||
},
|
||||
status: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
type: String,
|
||||
enum: MonitorStatuses,
|
||||
default: "initializing",
|
||||
},
|
||||
statusWindow: {
|
||||
type: [Boolean],
|
||||
|
||||
@@ -55,7 +55,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
query.isActive = filter === "true";
|
||||
break;
|
||||
case "status":
|
||||
query.status = filter === "true";
|
||||
query.status = filter;
|
||||
break;
|
||||
case "type":
|
||||
query.type = filter;
|
||||
@@ -223,17 +223,27 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
totalMonitors: { $sum: 1 },
|
||||
upMonitors: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$status", true] }, 1, 0],
|
||||
$cond: [{ $eq: ["$status", "up"] }, 1, 0],
|
||||
},
|
||||
},
|
||||
downMonitors: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$status", false] }, 1, 0],
|
||||
$cond: [{ $eq: ["$status", "down"] }, 1, 0],
|
||||
},
|
||||
},
|
||||
pausedMonitors: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$isActive", false] }, 1, 0],
|
||||
$cond: [{ $eq: ["$status", "paused"] }, 1, 0],
|
||||
},
|
||||
},
|
||||
initializingMonitors: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$status", "initializing"] }, 1, 0],
|
||||
},
|
||||
},
|
||||
maintenanceMonitors: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$status", "maintenance"] }, 1, 0],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -242,7 +252,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
];
|
||||
|
||||
const [summary] = await MonitorModel.aggregate(pipeline);
|
||||
return summary ?? { totalMonitors: 0, upMonitors: 0, downMonitors: 0, pausedMonitors: 0 };
|
||||
return summary ?? { totalMonitors: 0, upMonitors: 0, downMonitors: 0, pausedMonitors: 0, initializingMonitors: 0, maintenanceMonitors: 0 };
|
||||
};
|
||||
|
||||
findGroupsByTeamId = async (teamId: string): Promise<string[]> => {
|
||||
@@ -284,7 +294,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
teamId: toStringId(doc.teamId),
|
||||
name: doc.name,
|
||||
description: doc.description ?? undefined,
|
||||
status: doc.status ?? undefined,
|
||||
status: doc.status ?? "initializing",
|
||||
statusWindow: doc.statusWindow ?? [],
|
||||
statusWindowSize: doc.statusWindowSize,
|
||||
statusWindowThreshold: doc.statusWindowThreshold,
|
||||
@@ -331,45 +341,13 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
||||
|
||||
const notificationIds = (doc.notifications ?? []).map((notification: unknown) => toStringId(notification));
|
||||
|
||||
const checks: Check[] = (doc.checks ?? []).map((check: any) => ({
|
||||
id: toStringId(check._id),
|
||||
metadata: {
|
||||
monitorId: toStringId(check.metadata?.monitorId),
|
||||
teamId: toStringId(check.metadata?.teamId),
|
||||
type: check.metadata?.type,
|
||||
},
|
||||
status: check.status,
|
||||
responseTime: check.responseTime,
|
||||
timings: check.timings,
|
||||
statusCode: check.statusCode,
|
||||
message: check.message,
|
||||
ack: check.ack,
|
||||
ackAt: check.ackAt ?? null,
|
||||
expiry: toDateString(check.expiry),
|
||||
cpu: check.cpu,
|
||||
memory: check.memory,
|
||||
disk: check.disk,
|
||||
host: check.host,
|
||||
errors: check.errors,
|
||||
capture: check.capture,
|
||||
net: check.net,
|
||||
accessibility: check.accessibility,
|
||||
bestPractices: check.bestPractices,
|
||||
seo: check.seo,
|
||||
performance: check.performance,
|
||||
audits: check.audits,
|
||||
__v: check.__v,
|
||||
createdAt: toDateString(check.createdAt),
|
||||
updatedAt: toDateString(check.updatedAt),
|
||||
}));
|
||||
|
||||
return {
|
||||
id: toStringId(doc._id),
|
||||
userId: toStringId(doc.userId),
|
||||
teamId: toStringId(doc.teamId),
|
||||
name: doc.name,
|
||||
description: doc.description ?? undefined,
|
||||
status: doc.status ?? undefined,
|
||||
status: doc.status ?? "initializing",
|
||||
statusWindow: doc.statusWindow ?? [],
|
||||
statusWindowSize: doc.statusWindowSize,
|
||||
statusWindowThreshold: doc.statusWindowThreshold,
|
||||
|
||||
@@ -22,7 +22,7 @@ export interface Monitor {
|
||||
teamId: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
status?: MonitorStatus;
|
||||
status: MonitorStatus;
|
||||
statusWindow: boolean[];
|
||||
statusWindowSize: number;
|
||||
statusWindowThreshold: number;
|
||||
|
||||
Reference in new issue
Block a user