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 { Schema, model, Types, type UpdateQuery } from "mongoose";
|
||||||
import type { Monitor, MonitorMatchMethod, MonitorThresholds, CheckSnapshot } from "@/types/monitor.js";
|
import type { Monitor, MonitorMatchMethod, MonitorThresholds, CheckSnapshot } from "@/types/monitor.js";
|
||||||
import { MonitorTypes } from "@/types/monitor.js";
|
import { MonitorTypes, MonitorStatuses } from "@/types/monitor.js";
|
||||||
import Check from "./Check.js";
|
|
||||||
import MonitorStats from "./MonitorStats.js";
|
|
||||||
import StatusPage from "./StatusPage.js";
|
|
||||||
|
|
||||||
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
|
||||||
|
|
||||||
@@ -68,8 +65,9 @@ const MonitorSchema = new Schema<MonitorDocument>(
|
|||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
type: Boolean,
|
type: String,
|
||||||
default: undefined,
|
enum: MonitorStatuses,
|
||||||
|
default: "initializing",
|
||||||
},
|
},
|
||||||
statusWindow: {
|
statusWindow: {
|
||||||
type: [Boolean],
|
type: [Boolean],
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
query.isActive = filter === "true";
|
query.isActive = filter === "true";
|
||||||
break;
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
query.status = filter === "true";
|
query.status = filter;
|
||||||
break;
|
break;
|
||||||
case "type":
|
case "type":
|
||||||
query.type = filter;
|
query.type = filter;
|
||||||
@@ -223,17 +223,27 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
totalMonitors: { $sum: 1 },
|
totalMonitors: { $sum: 1 },
|
||||||
upMonitors: {
|
upMonitors: {
|
||||||
$sum: {
|
$sum: {
|
||||||
$cond: [{ $eq: ["$status", true] }, 1, 0],
|
$cond: [{ $eq: ["$status", "up"] }, 1, 0],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
downMonitors: {
|
downMonitors: {
|
||||||
$sum: {
|
$sum: {
|
||||||
$cond: [{ $eq: ["$status", false] }, 1, 0],
|
$cond: [{ $eq: ["$status", "down"] }, 1, 0],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pausedMonitors: {
|
pausedMonitors: {
|
||||||
$sum: {
|
$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);
|
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[]> => {
|
findGroupsByTeamId = async (teamId: string): Promise<string[]> => {
|
||||||
@@ -284,7 +294,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
teamId: toStringId(doc.teamId),
|
teamId: toStringId(doc.teamId),
|
||||||
name: doc.name,
|
name: doc.name,
|
||||||
description: doc.description ?? undefined,
|
description: doc.description ?? undefined,
|
||||||
status: doc.status ?? undefined,
|
status: doc.status ?? "initializing",
|
||||||
statusWindow: doc.statusWindow ?? [],
|
statusWindow: doc.statusWindow ?? [],
|
||||||
statusWindowSize: doc.statusWindowSize,
|
statusWindowSize: doc.statusWindowSize,
|
||||||
statusWindowThreshold: doc.statusWindowThreshold,
|
statusWindowThreshold: doc.statusWindowThreshold,
|
||||||
@@ -331,45 +341,13 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
|
|
||||||
const notificationIds = (doc.notifications ?? []).map((notification: unknown) => toStringId(notification));
|
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 {
|
return {
|
||||||
id: toStringId(doc._id),
|
id: toStringId(doc._id),
|
||||||
userId: toStringId(doc.userId),
|
userId: toStringId(doc.userId),
|
||||||
teamId: toStringId(doc.teamId),
|
teamId: toStringId(doc.teamId),
|
||||||
name: doc.name,
|
name: doc.name,
|
||||||
description: doc.description ?? undefined,
|
description: doc.description ?? undefined,
|
||||||
status: doc.status ?? undefined,
|
status: doc.status ?? "initializing",
|
||||||
statusWindow: doc.statusWindow ?? [],
|
statusWindow: doc.statusWindow ?? [],
|
||||||
statusWindowSize: doc.statusWindowSize,
|
statusWindowSize: doc.statusWindowSize,
|
||||||
statusWindowThreshold: doc.statusWindowThreshold,
|
statusWindowThreshold: doc.statusWindowThreshold,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export interface Monitor {
|
|||||||
teamId: string;
|
teamId: string;
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
status?: MonitorStatus;
|
status: MonitorStatus;
|
||||||
statusWindow: boolean[];
|
statusWindow: boolean[];
|
||||||
statusWindowSize: number;
|
statusWindowSize: number;
|
||||||
statusWindowThreshold: number;
|
statusWindowThreshold: number;
|
||||||
|
|||||||
Reference in new issue
Block a user