Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afd6a12e7d | ||
|
|
9fe8b7572f | ||
|
|
a424092fbd | ||
|
|
ad427dc765 | ||
|
|
116eb80fc9 | ||
|
|
c094a5fd73 | ||
|
|
206e28d1b9 | ||
|
|
2f1a164c26 | ||
|
|
124a8c0b07 | ||
|
|
188445c57a | ||
|
|
35f018623f | ||
|
|
d64526fed2 | ||
|
|
9a8a175f7c | ||
|
|
6ecb27d522 | ||
|
|
24b9b64979 | ||
|
|
a4e4e1313e | ||
|
|
990dc7875a | ||
|
|
69e98a51ec | ||
|
|
3063b9cf22 | ||
|
|
bd32854c7a | ||
|
|
0718e63e2f | ||
|
|
cdb70f9171 | ||
|
|
a1068f1d7e | ||
|
|
75eca743b4 |
No files matched your search
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
"format-check": "prettier --check ."
|
"format-check": "prettier --check ."
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"**/*": "npm run format"
|
"**/*": "prettier --write"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "^11.13.3",
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import BackgroundSVG from "@/assets/Images/background.svg";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
import { OfflineBanner } from "@/Components/design-elements";
|
import { OfflineBanner } from "@/Components/design-elements";
|
||||||
import { setServerUnreachableCallback, get } from "@/Utils/ApiClient";
|
import { setServerUnreachableCallback, get } from "@/Utils/ApiClient";
|
||||||
|
|
||||||
@@ -13,7 +10,6 @@ interface AppLayoutProps {
|
|||||||
|
|
||||||
const AppLayout = ({ children }: AppLayoutProps) => {
|
const AppLayout = ({ children }: AppLayoutProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const mode = useSelector((state: RootState) => state.ui.mode);
|
|
||||||
const [serverUnreachable, setServerUnreachable] = useState(false);
|
const [serverUnreachable, setServerUnreachable] = useState(false);
|
||||||
const retryIntervalRef = useRef<number | null>(null);
|
const retryIntervalRef = useRef<number | null>(null);
|
||||||
|
|
||||||
@@ -47,10 +43,6 @@ const AppLayout = ({ children }: AppLayoutProps) => {
|
|||||||
sx={{
|
sx={{
|
||||||
minHeight: "100vh",
|
minHeight: "100vh",
|
||||||
backgroundColor: theme.palette.background.default,
|
backgroundColor: theme.palette.background.default,
|
||||||
backgroundImage: mode === "dark" ? `url("${BackgroundSVG}")` : "none",
|
|
||||||
backgroundSize: "100% 100%",
|
|
||||||
backgroundPosition: "center",
|
|
||||||
backgroundRepeat: "no-repeat",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<OfflineBanner visible={serverUnreachable} />
|
<OfflineBanner visible={serverUnreachable} />
|
||||||
|
|||||||
@@ -32,7 +32,12 @@ import {
|
|||||||
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
import { SPACING, LAYOUT } from "@/Utils/Theme/constants";
|
||||||
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
||||||
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
||||||
import type { Monitor, MonitorType, GamesMap } from "@/Types/Monitor";
|
import {
|
||||||
|
type Monitor,
|
||||||
|
type MonitorType,
|
||||||
|
type GamesMap,
|
||||||
|
supportsGeoCheck,
|
||||||
|
} from "@/Types/Monitor";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
import type { MonitorFormData } from "@/Validation/monitor";
|
import type { MonitorFormData } from "@/Validation/monitor";
|
||||||
|
|
||||||
@@ -885,7 +890,7 @@ const CreateMonitorPage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{watchedType === "http" && (
|
{supportsGeoCheck(watchedType) && (
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.createMonitor.form.geoChecks.title")}
|
title={t("pages.createMonitor.form.geoChecks.title")}
|
||||||
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { useState, useMemo } from "react";
|
|||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useGet } from "@/Hooks/UseApi";
|
import { useGet } from "@/Hooks/UseApi";
|
||||||
import type { MonitorDetailsResponse } from "@/Types/Monitor";
|
import { type MonitorDetailsResponse, supportsGeoCheck } from "@/Types/Monitor";
|
||||||
import type { ChecksResponse } from "@/Types/Check";
|
import type { ChecksResponse } from "@/Types/Check";
|
||||||
import type {
|
import type {
|
||||||
GeoChecksResult,
|
GeoChecksResult,
|
||||||
@@ -122,7 +122,7 @@ const UptimeDetailsPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const geoChecksUrl = useMemo(() => {
|
const geoChecksUrl = useMemo(() => {
|
||||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
if (!monitorId || !supportsGeoCheck(monitor?.type) || !monitor?.geoCheckEnabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -141,7 +141,7 @@ const UptimeDetailsPage = () => {
|
|||||||
|
|
||||||
// Fetch paginated geo checks for the table
|
// Fetch paginated geo checks for the table
|
||||||
const geoChecksTableUrl = useMemo(() => {
|
const geoChecksTableUrl = useMemo(() => {
|
||||||
if (!monitorId || monitor?.type !== "http" || !monitor?.geoCheckEnabled) {
|
if (!monitorId || !supportsGeoCheck(monitor?.type) || !monitor?.geoCheckEnabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ export const MonitorTypes = [
|
|||||||
] as const;
|
] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
|
|
||||||
|
export const GeoCheckSupportedTypes: readonly MonitorType[] = ["http", "ping"] as const;
|
||||||
|
|
||||||
|
export const supportsGeoCheck = (type: MonitorType | undefined): boolean => {
|
||||||
|
if (!type) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return GeoCheckSupportedTypes.includes(type);
|
||||||
|
};
|
||||||
|
|
||||||
export const MonitorStatuses = [
|
export const MonitorStatuses = [
|
||||||
"up",
|
"up",
|
||||||
"down",
|
"down",
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export const typographyLevels = {
|
|||||||
export const colors = {
|
export const colors = {
|
||||||
gray200: "#EFEFEF",
|
gray200: "#EFEFEF",
|
||||||
gray700: "#313131",
|
gray700: "#313131",
|
||||||
|
gray900: "#151518",
|
||||||
|
gray850: "#1c1c21",
|
||||||
blueBlueWave: "#1570EF",
|
blueBlueWave: "#1570EF",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,4 +33,8 @@ export const darkPalette = {
|
|||||||
secondary: {
|
secondary: {
|
||||||
main: colors.gray700,
|
main: colors.gray700,
|
||||||
},
|
},
|
||||||
|
background: {
|
||||||
|
default: colors.gray900,
|
||||||
|
paper: colors.gray850,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
"format-check": "prettier --check ."
|
"format-check": "prettier --check ."
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"**/*": "npm run format"
|
"**/*": "prettier --write"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@@ -1,31 +1,65 @@
|
|||||||
import MongoDB from "../db/MongoDB.js";
|
import MongoDB from "../db/MongoDB.js";
|
||||||
import NetworkService from "../service/infrastructure/networkService.js";
|
import { IDb } from "@/db/IDb.js";
|
||||||
import EmailService from "../service/infrastructure/emailService.js";
|
|
||||||
import BufferService from "../service/infrastructure/bufferService.js";
|
|
||||||
import {
|
import {
|
||||||
|
// Service classes
|
||||||
|
NetworkService,
|
||||||
|
EmailService,
|
||||||
|
BufferService,
|
||||||
|
GlobalPingService,
|
||||||
|
SuperSimpleQueue,
|
||||||
|
SuperSimpleQueueHelper,
|
||||||
NotificationsService,
|
NotificationsService,
|
||||||
StatusService,
|
StatusService,
|
||||||
|
NotificationMessageBuilder,
|
||||||
|
MonitorService,
|
||||||
|
StatusPageService,
|
||||||
|
UserService,
|
||||||
|
CheckService,
|
||||||
|
GeoChecksService,
|
||||||
|
DiagnosticService,
|
||||||
|
InviteService,
|
||||||
|
MaintenanceWindowService,
|
||||||
|
IncidentService,
|
||||||
|
// Notification providers
|
||||||
WebhookProvider,
|
WebhookProvider,
|
||||||
SlackProvider,
|
SlackProvider,
|
||||||
EmailProvider,
|
EmailProvider,
|
||||||
DiscordProvider,
|
DiscordProvider,
|
||||||
PagerDutyProvider,
|
PagerDutyProvider,
|
||||||
MatrixProvider,
|
MatrixProvider,
|
||||||
|
// Interfaces
|
||||||
|
INetworkService,
|
||||||
|
IEmailService,
|
||||||
|
IBufferService,
|
||||||
|
ISuperSimpleQueue,
|
||||||
INotificationsService,
|
INotificationsService,
|
||||||
|
IStatusService,
|
||||||
|
IMonitorService,
|
||||||
|
IUserService,
|
||||||
|
ICheckService,
|
||||||
|
IGeoChecksService,
|
||||||
|
IDiagnosticService,
|
||||||
|
IInviteService,
|
||||||
|
IMaintenanceWindowService,
|
||||||
|
IStatusPageService,
|
||||||
|
IIncidentService,
|
||||||
|
INotificationMessageBuilder,
|
||||||
|
ISettingsService,
|
||||||
|
EnvConfig,
|
||||||
} from "@/service/index.js";
|
} from "@/service/index.js";
|
||||||
import SuperSimpleQueueHelper from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
|
||||||
import SuperSimpleQueue from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
// Network providers
|
||||||
import UserService from "../service/business/userService.js";
|
import { PingProvider } from "@/service/infrastructure/network/PingProvider.js";
|
||||||
import CheckService from "../service/business/checkService.js";
|
import { HttpProvider } from "@/service/infrastructure/network/HttpProvider.js";
|
||||||
import GeoChecksService from "../service/business/geoChecksService.js";
|
import { AdvancedMatcher } from "@/service/infrastructure/network/AdvancedMatcher.js";
|
||||||
import GlobalPingService from "../service/infrastructure/globalPingService.js";
|
import { PageSpeedProvider } from "@/service/infrastructure/network/PageSpeedProvider.js";
|
||||||
import DiagnosticService from "../service/business/diagnosticService.js";
|
import { HardwareProvider } from "@/service/infrastructure/network/HardwareProvider.js";
|
||||||
import InviteService from "../service/business/inviteService.js";
|
import { DockerProvider } from "@/service/infrastructure/network/DockerProvider.js";
|
||||||
import MaintenanceWindowService from "../service/business/maintenanceWindowService.js";
|
import { PortProvider } from "@/service/infrastructure/network/PortProvider.js";
|
||||||
import { MonitorService } from "@/service/index.js";
|
import { GameProvider } from "@/service/infrastructure/network/GameProvider.js";
|
||||||
import { StatusPageService, IStatusPageService } from "../service/business/statusPageService.js";
|
import { GrpcProvider } from "@/service/infrastructure/network/GrpcProvider.js";
|
||||||
import IncidentService from "../service/business/incidentService.js";
|
|
||||||
import { NotificationMessageBuilder, INotificationMessageBuilder } from "../service/infrastructure/notificationMessageBuilder.js";
|
// Third-party
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
import ping from "ping";
|
import ping from "ping";
|
||||||
@@ -44,7 +78,7 @@ import jmespath from "jmespath";
|
|||||||
import * as grpc from "@grpc/grpc-js";
|
import * as grpc from "@grpc/grpc-js";
|
||||||
import * as protoLoader from "@grpc/proto-loader";
|
import * as protoLoader from "@grpc/proto-loader";
|
||||||
|
|
||||||
// repositories
|
// Repositories
|
||||||
import {
|
import {
|
||||||
MongoMonitorsRepository,
|
MongoMonitorsRepository,
|
||||||
MongoChecksRepository,
|
MongoChecksRepository,
|
||||||
@@ -73,33 +107,23 @@ import {
|
|||||||
IMaintenanceWindowsRepository,
|
IMaintenanceWindowsRepository,
|
||||||
} from "@/repositories/index.js";
|
} from "@/repositories/index.js";
|
||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import { EnvConfig } from "@/service/system/settingsService.js";
|
|
||||||
import { PingProvider } from "@/service/infrastructure/network/PingProvider.js";
|
|
||||||
import { HttpProvider } from "@/service/infrastructure/network/HttpProvider.js";
|
|
||||||
import { AdvancedMatcher } from "@/service/infrastructure/network/AdvancedMatcher.js";
|
|
||||||
import { PageSpeedProvider } from "@/service/infrastructure/network/PageSpeedProvider.js";
|
|
||||||
import { HardwareProvider } from "@/service/infrastructure/network/HardwareProvider.js";
|
|
||||||
import { DockerProvider } from "@/service/infrastructure/network/DockerProvider.js";
|
|
||||||
import { PortProvider } from "@/service/infrastructure/network/PortProvider.js";
|
|
||||||
import { GameProvider } from "@/service/infrastructure/network/GameProvider.js";
|
|
||||||
import { GrpcProvider } from "@/service/infrastructure/network/GrpcProvider.js";
|
|
||||||
|
|
||||||
export type InitializedServices = {
|
export type InitializedServices = {
|
||||||
settingsService: any;
|
settingsService: ISettingsService;
|
||||||
db: any;
|
db: IDb;
|
||||||
networkService: any;
|
networkService: INetworkService;
|
||||||
emailService: any;
|
emailService: IEmailService;
|
||||||
bufferService: any;
|
bufferService: IBufferService;
|
||||||
statusService: any;
|
statusService: IStatusService;
|
||||||
jobQueue: any;
|
jobQueue: ISuperSimpleQueue;
|
||||||
userService: any;
|
userService: IUserService;
|
||||||
checkService: any;
|
checkService: ICheckService;
|
||||||
geoChecksService: any;
|
geoChecksService: IGeoChecksService;
|
||||||
diagnosticService: any;
|
diagnosticService: IDiagnosticService;
|
||||||
inviteService: any;
|
inviteService: IInviteService;
|
||||||
maintenanceWindowService: any;
|
maintenanceWindowService: IMaintenanceWindowService;
|
||||||
monitorService: any;
|
monitorService: IMonitorService;
|
||||||
incidentService: any;
|
incidentService: IIncidentService;
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
notificationsService: INotificationsService;
|
notificationsService: INotificationsService;
|
||||||
statusPageService: IStatusPageService;
|
statusPageService: IStatusPageService;
|
||||||
@@ -129,7 +153,7 @@ export const initializeServices = async ({
|
|||||||
}: {
|
}: {
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
envSettings: EnvConfig;
|
envSettings: EnvConfig;
|
||||||
settingsService: any;
|
settingsService: ISettingsService;
|
||||||
settingsRepository: ISettingsRepository;
|
settingsRepository: ISettingsRepository;
|
||||||
}): Promise<InitializedServices> => {
|
}): Promise<InitializedServices> => {
|
||||||
// Create DB
|
// Create DB
|
||||||
@@ -152,8 +176,7 @@ export const initializeServices = async ({
|
|||||||
const teamsRepository = new MongoTeamsRepository();
|
const teamsRepository = new MongoTeamsRepository();
|
||||||
const maintenanceWindowsRepository = new MongoMaintenanceWindowsRepository();
|
const maintenanceWindowsRepository = new MongoMaintenanceWindowsRepository();
|
||||||
|
|
||||||
// Providers
|
// Network providers
|
||||||
|
|
||||||
const pingProvider = new PingProvider(ping);
|
const pingProvider = new PingProvider(ping);
|
||||||
const httpProvider = new HttpProvider(got, new AdvancedMatcher(jmespath));
|
const httpProvider = new HttpProvider(got, new AdvancedMatcher(jmespath));
|
||||||
const pageSpeedProvider = new PageSpeedProvider(httpProvider, settingsService, logger);
|
const pageSpeedProvider = new PageSpeedProvider(httpProvider, settingsService, logger);
|
||||||
@@ -163,9 +186,7 @@ export const initializeServices = async ({
|
|||||||
const gameProvider = new GameProvider(logger, GameDig);
|
const gameProvider = new GameProvider(logger, GameDig);
|
||||||
const grpcProvider = new GrpcProvider(grpc, protoLoader);
|
const grpcProvider = new GrpcProvider(grpc, protoLoader);
|
||||||
|
|
||||||
const networkService = new NetworkService(
|
const networkService = new NetworkService(axios, logger, [
|
||||||
axios,
|
|
||||||
logger,
|
|
||||||
pingProvider,
|
pingProvider,
|
||||||
httpProvider,
|
httpProvider,
|
||||||
pageSpeedProvider,
|
pageSpeedProvider,
|
||||||
@@ -173,8 +194,8 @@ export const initializeServices = async ({
|
|||||||
dockerProvider,
|
dockerProvider,
|
||||||
portProvider,
|
portProvider,
|
||||||
gameProvider,
|
gameProvider,
|
||||||
grpcProvider
|
grpcProvider,
|
||||||
);
|
]);
|
||||||
const emailService = new EmailService(settingsService, fs, path, compile, mjml2html, nodemailer, logger);
|
const emailService = new EmailService(settingsService, fs, path, compile, mjml2html, nodemailer, logger);
|
||||||
|
|
||||||
const notificationMessageBuilder = new NotificationMessageBuilder();
|
const notificationMessageBuilder = new NotificationMessageBuilder();
|
||||||
@@ -196,6 +217,7 @@ export const initializeServices = async ({
|
|||||||
|
|
||||||
const statusService = new StatusService(logger, bufferService, monitorsRepository, monitorStatsRepository, checksRepository);
|
const statusService = new StatusService(logger, bufferService, monitorsRepository, monitorStatsRepository, checksRepository);
|
||||||
|
|
||||||
|
// Notification providers
|
||||||
const webhookProvider = new WebhookProvider(logger);
|
const webhookProvider = new WebhookProvider(logger);
|
||||||
const slackProvider = new SlackProvider(logger);
|
const slackProvider = new SlackProvider(logger);
|
||||||
const emailProvider = new EmailProvider(emailService, logger);
|
const emailProvider = new EmailProvider(emailService, logger);
|
||||||
@@ -279,7 +301,6 @@ export const initializeServices = async ({
|
|||||||
const statusPageService = new StatusPageService(statusPagesRepository);
|
const statusPageService = new StatusPageService(statusPagesRepository);
|
||||||
|
|
||||||
const services = {
|
const services = {
|
||||||
//v1
|
|
||||||
settingsService,
|
settingsService,
|
||||||
db,
|
db,
|
||||||
networkService,
|
networkService,
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface IDb {
|
||||||
|
connect(): Promise<void>;
|
||||||
|
disconnect(): Promise<void>;
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import AppSettings from "./models/AppSettings.js";
|
import AppSettings from "@/db/models/AppSettings.js";
|
||||||
import { runMigrations } from "./migration/index.js";
|
import { runMigrations } from "@/db/migration/index.js";
|
||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import { EnvConfig } from "@/service/system/settingsService.js";
|
import { EnvConfig } from "@/service/system/settingsService.js";
|
||||||
const SERVICE_NAME = "MongoDB";
|
const SERVICE_NAME = "MongoDB";
|
||||||
class MongoDB {
|
import { IDb } from "@/db/IDb.js";
|
||||||
|
|
||||||
|
class MongoDB implements IDb {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -46,12 +48,12 @@ class MongoDB {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await runMigrations();
|
await runMigrations();
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "connect",
|
method: "connect",
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -63,12 +65,12 @@ class MongoDB {
|
|||||||
await mongoose.disconnect();
|
await mongoose.disconnect();
|
||||||
this.logger.info({ message: "Disconnected from MongoDB", service: SERVICE_NAME, method: "disconnect" });
|
this.logger.info({ message: "Disconnected from MongoDB", service: SERVICE_NAME, method: "disconnect" });
|
||||||
return;
|
return;
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "disconnect",
|
method: "disconnect",
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-4
@@ -9,7 +9,7 @@ import fs from "fs";
|
|||||||
import { runMigrations } from "./db/migration/index.js";
|
import { runMigrations } from "./db/migration/index.js";
|
||||||
|
|
||||||
import Logger, { ILogger } from "@/utils/logger.js";
|
import Logger, { ILogger } from "@/utils/logger.js";
|
||||||
import SettingsService from "@/service/system/settingsService.js";
|
import { SettingsService } from "@/service/index.js";
|
||||||
import { MongoSettingsRepository } from "./repositories/index.js";
|
import { MongoSettingsRepository } from "./repositories/index.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "Server";
|
const SERVICE_NAME = "Server";
|
||||||
@@ -50,9 +50,8 @@ const startApp = async () => {
|
|||||||
openApiSpec,
|
openApiSpec,
|
||||||
});
|
});
|
||||||
|
|
||||||
const port = 52345;
|
const server = app.listen(env.PORT, () => {
|
||||||
const server = app.listen(port, () => {
|
logger.info({ message: `Server started on port:${env.PORT}` });
|
||||||
logger.info({ message: `Server started on port:${port}` });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
initShutdownListener(server, services);
|
initShutdownListener(server, services);
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { IGeoChecksRepository } from "./IGeoChecksRepository.js";
|
import { IGeoChecksRepository } from "./IGeoChecksRepository.js";
|
||||||
import type { GeoCheck, GeoCheckMetadata, GeoCheckResult, GroupedGeoCheck, GeoContinent, FlatGeoCheck } from "@/types/geoCheck.js";
|
import type { GeoCheck, GeoCheckMetadata, GeoCheckResult, GroupedGeoCheck, GeoContinent, FlatGeoCheck } from "@/types/geoCheck.js";
|
||||||
import type { GeoChecksQueryResult, FlatGeoChecksQueryResult } from "./IGeoChecksRepository.js";
|
import type { FlatGeoChecksQueryResult } from "./IGeoChecksRepository.js";
|
||||||
import { GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
import { GeoCheckModel, type GeoCheckDocument } from "@/db/models/index.js";
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import { getDateForRange } from "@/utils/dataUtils.js";
|
import { getDateForRange } from "@/utils/dataUtils.js";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "GeoChecksRepository";
|
const SERVICE_NAME = "GeoChecksRepository";
|
||||||
|
|
||||||
class MongoGeoChecksRepository implements IGeoChecksRepository {
|
class MongoGeoChecksRepository implements IGeoChecksRepository {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: any;
|
private logger: ILogger;
|
||||||
constructor(logger: any) {
|
constructor(logger: ILogger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export interface ICheckService {
|
|||||||
updateChecksTTL(params: { teamId: string; ttl: string }): Promise<void>;
|
updateChecksTTL(params: { teamId: string; ttl: string }): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CheckService implements ICheckService {
|
export class CheckService implements ICheckService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
@@ -194,5 +194,3 @@ class CheckService implements ICheckService {
|
|||||||
throw new AppError({ message: "Not implemented", service: SERVICE_NAME, method: "updateChecksTTL", status: 500, details: { teamId, ttl } });
|
throw new AppError({ message: "Not implemented", service: SERVICE_NAME, method: "updateChecksTTL", status: 500, details: { teamId, ttl } });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CheckService;
|
|
||||||
@@ -3,15 +3,19 @@ import os from "os";
|
|||||||
|
|
||||||
const SERVICE_NAME = "diagnosticService";
|
const SERVICE_NAME = "diagnosticService";
|
||||||
|
|
||||||
interface MemoryUsageMetrics {
|
export interface IDiagnosticService {
|
||||||
rss: number;
|
getCPUUsage(): Promise<{ userUsageMs: number; systemUsageMs: number; usagePercentage: number }>;
|
||||||
heapTotal: number;
|
getSystemStats(): Promise<{
|
||||||
heapUsed: number;
|
osStats: { freeMemoryBytes: number; totalMemoryBytes: number };
|
||||||
external: number;
|
memoryUsage: Record<keyof NodeJS.MemoryUsage, number>;
|
||||||
arrayBuffers: number;
|
cpuUsage: { userUsageMs: number; systemUsageMs: number; usagePercentage: number };
|
||||||
|
v8HeapStats: { totalHeapSizeBytes: number; usedHeapSizeBytes: number; heapSizeLimitBytes: number };
|
||||||
|
eventLoopDelayMs: number;
|
||||||
|
uptimeMs: number;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiagnosticService {
|
export class DiagnosticService implements IDiagnosticService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -103,5 +107,3 @@ class DiagnosticService {
|
|||||||
return diagnostics;
|
return diagnostics;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DiagnosticService;
|
|
||||||
@@ -16,7 +16,7 @@ export interface IGeoChecksService {
|
|||||||
getGeoChecksByMonitor(args: { monitorId: string; query: any; teamId: string }): Promise<any>;
|
getGeoChecksByMonitor(args: { monitorId: string; query: any; teamId: string }): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GeoChecksService implements IGeoChecksService {
|
export class GeoChecksService implements IGeoChecksService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -68,7 +68,7 @@ class GeoChecksService implements IGeoChecksService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 1: Create measurement request
|
// Step 1: Create measurement request
|
||||||
const measurementId = await this.globalPingService.createMeasurement(monitor.url, monitor.geoCheckLocations);
|
const measurementId = await this.globalPingService.createMeasurement(monitor.type, monitor.url, monitor.geoCheckLocations);
|
||||||
|
|
||||||
if (!measurementId) {
|
if (!measurementId) {
|
||||||
// GlobalPing API is down, skip this check
|
// GlobalPing API is down, skip this check
|
||||||
@@ -76,7 +76,6 @@ class GeoChecksService implements IGeoChecksService {
|
|||||||
message: "Skipping geo check due to API unavailability",
|
message: "Skipping geo check due to API unavailability",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id },
|
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -90,7 +89,6 @@ class GeoChecksService implements IGeoChecksService {
|
|||||||
message: "No successful geo check results",
|
message: "No successful geo check results",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, measurementId },
|
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -102,17 +100,16 @@ class GeoChecksService implements IGeoChecksService {
|
|||||||
message: `Geo check completed for monitor ${monitor.id}`,
|
message: `Geo check completed for monitor ${monitor.id}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, resultsCount: results.length },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return geoCheck;
|
return geoCheck;
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
message: "Error executing geo check",
|
message: "Error executing geo check",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "buildGeoCheck",
|
method: "buildGeoCheck",
|
||||||
details: { monitorId: monitor.id, error: error.message },
|
details: { monitorId: monitor.id, error: error instanceof Error ? error.message : "Unknown error" },
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -172,21 +169,9 @@ class GeoChecksService implements IGeoChecksService {
|
|||||||
|
|
||||||
const { sortOrder, dateRange, page, rowsPerPage, continent } = query;
|
const { sortOrder, dateRange, page, rowsPerPage, continent } = query;
|
||||||
const continents = continent ? (Array.isArray(continent) ? continent : [continent]) : undefined;
|
const continents = continent ? (Array.isArray(continent) ? continent : [continent]) : undefined;
|
||||||
|
|
||||||
this.logger.debug({
|
|
||||||
message: "getGeoChecksByMonitor query params",
|
|
||||||
service: SERVICE_NAME,
|
|
||||||
method: "getGeoChecksByMonitor",
|
|
||||||
details: { continent, continents, query },
|
|
||||||
});
|
|
||||||
|
|
||||||
const parsedPage = page ? parseInt(page) : page;
|
const parsedPage = page ? parseInt(page) : page;
|
||||||
const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage;
|
const parsedRowsPerPage = rowsPerPage ? parseInt(rowsPerPage) : rowsPerPage;
|
||||||
|
|
||||||
const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continents);
|
const result = await this.geoChecksRepository.findByMonitorId(monitorId, sortOrder, dateRange, parsedPage, parsedRowsPerPage, continents);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GeoChecksService;
|
|
||||||
@@ -5,12 +5,34 @@ import { AppError } from "@/utils/AppError.js";
|
|||||||
import { ParseBoolean } from "@/utils/utils.js";
|
import { ParseBoolean } from "@/utils/utils.js";
|
||||||
import { getDateForRange } from "@/utils/dataUtils.js";
|
import { getDateForRange } from "@/utils/dataUtils.js";
|
||||||
import type { IIncidentsRepository, IMonitorsRepository, IUsersRepository } from "@/repositories/index.js";
|
import type { IIncidentsRepository, IMonitorsRepository, IUsersRepository } from "@/repositories/index.js";
|
||||||
import type { Incident } from "@/types/index.js";
|
import type { Incident, IncidentSummary, User } from "@/types/index.js";
|
||||||
import type { MonitorActionDecision } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
import type { MonitorActionDecision } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
||||||
import type { INotificationMessageBuilder } from "@/service/infrastructure/notificationMessageBuilder.js";
|
import type { INotificationMessageBuilder } from "@/service/infrastructure/notificationMessageBuilder.js";
|
||||||
import type { ILogger } from "@/utils/logger.js";
|
import type { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
class IncidentService {
|
export interface IIncidentService {
|
||||||
|
handleIncident(
|
||||||
|
monitor: Monitor,
|
||||||
|
code: number,
|
||||||
|
decision: MonitorActionDecision,
|
||||||
|
monitorStatusResponse?: MonitorStatusResponse
|
||||||
|
): Promise<Incident | null>;
|
||||||
|
resolveIncident(incidentId: string, userId: string, teamId: string, comment?: string, userEmail?: string): Promise<Incident>;
|
||||||
|
getIncidentsByTeam(
|
||||||
|
teamId: string,
|
||||||
|
sortOrder: string,
|
||||||
|
dateRange: string,
|
||||||
|
page: string,
|
||||||
|
rowsPerPage: string,
|
||||||
|
status: string,
|
||||||
|
monitorId: string,
|
||||||
|
resolutionType: string
|
||||||
|
): Promise<{ incidents: Incident[]; count: number }>;
|
||||||
|
getIncidentSummary(teamId: string, limit?: string): Promise<IncidentSummary>;
|
||||||
|
getIncidentById(incidentId: string, teamId: string): Promise<{ incident: Incident; monitor: Monitor; user: User | null }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IncidentService implements IIncidentService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -244,5 +266,3 @@ class IncidentService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default IncidentService;
|
|
||||||
@@ -5,7 +5,13 @@ import { AppError } from "@/utils/AppError.js";
|
|||||||
|
|
||||||
const SERVICE_NAME = "inviteService";
|
const SERVICE_NAME = "inviteService";
|
||||||
|
|
||||||
class InviteService {
|
export interface IInviteService {
|
||||||
|
getInviteToken(params: { invite: Partial<Invite>; teamId: string; userRoles: UserRole[] }): Promise<Invite>;
|
||||||
|
sendInviteEmail(params: { invite: Partial<Invite>; firstName: string; userRoles: UserRole[] }): Promise<void>;
|
||||||
|
verifyInviteToken(params: { inviteToken: string }): Promise<Invite>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class InviteService implements IInviteService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private settingsService: any;
|
private settingsService: any;
|
||||||
@@ -88,5 +94,3 @@ class InviteService {
|
|||||||
return await this.invitesRepository.findByToken(inviteToken);
|
return await this.invitesRepository.findByToken(inviteToken);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InviteService;
|
|
||||||
@@ -1,10 +1,23 @@
|
|||||||
import { IMaintenanceWindowsRepository, IMonitorsRepository } from "@/repositories/index.js";
|
import { IMaintenanceWindowsRepository, IMonitorsRepository } from "@/repositories/index.js";
|
||||||
|
import type { MaintenanceWindow } from "@/types/index.js";
|
||||||
import { ParseBoolean } from "@/utils/utils.js";
|
import { ParseBoolean } from "@/utils/utils.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "maintenanceWindowService";
|
const SERVICE_NAME = "maintenanceWindowService";
|
||||||
|
|
||||||
class MaintenanceWindowService {
|
export interface IMaintenanceWindowService {
|
||||||
|
createMaintenanceWindow(params: { teamId: string; body: Partial<MaintenanceWindow> & { monitors: string[] } }): Promise<void>;
|
||||||
|
getMaintenanceWindowById(params: { id: string; teamId: string }): Promise<MaintenanceWindow>;
|
||||||
|
getMaintenanceWindowsByTeamId(params: {
|
||||||
|
teamId: string;
|
||||||
|
query: Record<string, string>;
|
||||||
|
}): Promise<{ maintenanceWindows: MaintenanceWindow[]; maintenanceWindowCount: number }>;
|
||||||
|
getMaintenanceWindowsByMonitorId(params: { monitorId: string; teamId: string }): Promise<MaintenanceWindow[]>;
|
||||||
|
deleteMaintenanceWindow(params: { id: string; teamId: string }): Promise<MaintenanceWindow>;
|
||||||
|
editMaintenanceWindow(params: { id: string; teamId: string; body: Partial<MaintenanceWindow> }): Promise<MaintenanceWindow>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MaintenanceWindowService implements IMaintenanceWindowService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
private maintenanceWindowsRepository: IMaintenanceWindowsRepository;
|
private maintenanceWindowsRepository: IMaintenanceWindowsRepository;
|
||||||
@@ -83,5 +96,3 @@ class MaintenanceWindowService {
|
|||||||
return await this.maintenanceWindowsRepository.updateById(id, teamId, body);
|
return await this.maintenanceWindowsRepository.updateById(id, teamId, body);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MaintenanceWindowService;
|
|
||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
PageSpeedDetailsResult,
|
PageSpeedDetailsResult,
|
||||||
GamesMap,
|
GamesMap,
|
||||||
} from "@/types/monitor.js";
|
} from "@/types/monitor.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
import type { GeoContinent } from "@/types/geoCheck.js";
|
import type { GeoContinent } from "@/types/geoCheck.js";
|
||||||
import type {
|
import type {
|
||||||
IChecksRepository,
|
IChecksRepository,
|
||||||
@@ -340,7 +341,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.type !== "http" || !monitor.geoCheckEnabled) {
|
if (!supportsGeoCheck(monitor.type) || !monitor.geoCheckEnabled) {
|
||||||
return { groupedGeoChecks: [] };
|
return { groupedGeoChecks: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,31 @@ import { canManageRole, type UserRole } from "@/types/user.js";
|
|||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { ISuperSimpleQueue } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
import { ISuperSimpleQueue } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
||||||
|
import { IEmailService } from "@/service/infrastructure/emailService.js";
|
||||||
|
import { ISettingsService } from "@/service/system/settingsService.js";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
import jwt from "jsonwebtoken";
|
||||||
|
type JwtType = typeof jwt;
|
||||||
const SERVICE_NAME = "userService";
|
const SERVICE_NAME = "userService";
|
||||||
|
|
||||||
class UserService {
|
export interface IUserService {
|
||||||
|
issueToken(payload: Partial<User>, appSettings: { jwtTTL?: string; jwtSecret?: string }): string;
|
||||||
|
registerUser(user: Partial<User>, inviteToken: string, file: unknown): Promise<{ user: User; token: string }>;
|
||||||
|
createUser(userData: Partial<User>, teamId: string, actorRoles: UserRole[], file: unknown): Promise<User>;
|
||||||
|
loginUser(email: string, password: string): Promise<{ user: User; token: string }>;
|
||||||
|
editUser(updates: Partial<User & { newPassword?: string }>, file: unknown, currentUser: User): Promise<User>;
|
||||||
|
checkSuperadminExists(): Promise<boolean>;
|
||||||
|
requestRecovery(email: string): Promise<string | false | undefined>;
|
||||||
|
validateRecovery(recoveryToken: string): Promise<void>;
|
||||||
|
resetPassword(password: string, recoveryToken: string): Promise<{ user: User; token: string }>;
|
||||||
|
deleteUser(user: User): Promise<void>;
|
||||||
|
getAllUsers(): Promise<User[]>;
|
||||||
|
getUserById(roles: UserRole[], userId: string): Promise<User>;
|
||||||
|
editUserById(userId: string, patch: Partial<User>): Promise<void>;
|
||||||
|
setPasswordByUserId(userId: string, password: string): Promise<User>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UserService implements IUserService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private hashPassword = (password: string): string => {
|
private hashPassword = (password: string): string => {
|
||||||
@@ -22,10 +43,10 @@ class UserService {
|
|||||||
return bcrypt.hashSync(password, salt);
|
return bcrypt.hashSync(password, salt);
|
||||||
};
|
};
|
||||||
|
|
||||||
private emailService: any;
|
private emailService: IEmailService;
|
||||||
private settingsService: any;
|
private settingsService: ISettingsService;
|
||||||
private logger: any;
|
private logger: ILogger;
|
||||||
private jwt: any;
|
private jwt: JwtType;
|
||||||
private jobQueue: ISuperSimpleQueue;
|
private jobQueue: ISuperSimpleQueue;
|
||||||
private crypto: any;
|
private crypto: any;
|
||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
@@ -50,10 +71,10 @@ class UserService {
|
|||||||
teamsRepository,
|
teamsRepository,
|
||||||
}: {
|
}: {
|
||||||
crypto: any;
|
crypto: any;
|
||||||
emailService: any;
|
emailService: IEmailService;
|
||||||
settingsService: any;
|
settingsService: ISettingsService;
|
||||||
logger: any;
|
logger: ILogger;
|
||||||
jwt: any;
|
jwt: JwtType;
|
||||||
jobQueue: ISuperSimpleQueue;
|
jobQueue: ISuperSimpleQueue;
|
||||||
monitorsRepository: IMonitorsRepository;
|
monitorsRepository: IMonitorsRepository;
|
||||||
usersRepository: IUsersRepository;
|
usersRepository: IUsersRepository;
|
||||||
@@ -120,7 +141,7 @@ class UserService {
|
|||||||
message: "New user created",
|
message: "New user created",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "registerUser",
|
method: "registerUser",
|
||||||
details: newUser.id,
|
details: { userId: newUser.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
delete newUser.profileImage;
|
delete newUser.profileImage;
|
||||||
@@ -134,20 +155,23 @@ class UserService {
|
|||||||
const html = await this.emailService.buildEmail("welcomeEmailTemplate", {
|
const html = await this.emailService.buildEmail("welcomeEmailTemplate", {
|
||||||
name: newUser.firstName,
|
name: newUser.firstName,
|
||||||
});
|
});
|
||||||
this.emailService.sendEmail(newUser.email, "Welcome to Uptime Monitor", html).catch((error: any) => {
|
if (!html) {
|
||||||
|
throw new Error("Failed to build welcome email HTML");
|
||||||
|
}
|
||||||
|
this.emailService.sendEmail(newUser.email, "Welcome to Uptime Monitor", html).catch((error: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "registerUser",
|
method: "registerUser",
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: error.message,
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "registerUser",
|
method: "registerUser",
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +205,7 @@ class UserService {
|
|||||||
message: "New user created by superadmin",
|
message: "New user created by superadmin",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "createUser",
|
method: "createUser",
|
||||||
details: newUser.id,
|
details: { userId: newUser.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
newUser.profileImage = undefined;
|
newUser.profileImage = undefined;
|
||||||
@@ -256,6 +280,14 @@ class UserService {
|
|||||||
email,
|
email,
|
||||||
url,
|
url,
|
||||||
});
|
});
|
||||||
|
if (!html) {
|
||||||
|
throw new AppError({
|
||||||
|
message: "Failed to build password reset email HTML",
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "requestRecovery",
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
const msgId = await this.emailService.sendEmail(email, "Checkmate Password Reset", html);
|
const msgId = await this.emailService.sendEmail(email, "Checkmate Password Reset", html);
|
||||||
return msgId;
|
return msgId;
|
||||||
};
|
};
|
||||||
@@ -313,13 +345,13 @@ class UserService {
|
|||||||
|
|
||||||
if (roles.includes("superadmin")) {
|
if (roles.includes("superadmin")) {
|
||||||
// 2. Remove all jobs, delete checks and alerts
|
// 2. Remove all jobs, delete checks and alerts
|
||||||
res &&
|
if (res && res.length > 0) {
|
||||||
res?.length > 0 &&
|
await Promise.all(
|
||||||
(await Promise.all(
|
|
||||||
res.map(async (monitor) => {
|
res.map(async (monitor) => {
|
||||||
await this.jobQueue.deleteJob(monitor.id);
|
await this.jobQueue.deleteJob(monitor.id);
|
||||||
})
|
})
|
||||||
));
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 6. Delete the user by id
|
// 6. Delete the user by id
|
||||||
await this.usersRepository.deleteById(userId);
|
await this.usersRepository.deleteById(userId);
|
||||||
@@ -348,4 +380,3 @@ class UserService {
|
|||||||
return updatedUser;
|
return updatedUser;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export default UserService;
|
|
||||||
@@ -1,14 +1,33 @@
|
|||||||
|
// Business services
|
||||||
|
export * from "@/service/business/checkService.js";
|
||||||
|
export * from "@/service/business/diagnosticService.js";
|
||||||
|
export * from "@/service/business/geoChecksService.js";
|
||||||
|
export * from "@/service/business/incidentService.js";
|
||||||
|
export * from "@/service/business/inviteService.js";
|
||||||
|
export * from "@/service/business/maintenanceWindowService.js";
|
||||||
export * from "@/service/business/monitorService.js";
|
export * from "@/service/business/monitorService.js";
|
||||||
|
export * from "@/service/business/statusPageService.js";
|
||||||
|
export * from "@/service/business/userService.js";
|
||||||
|
|
||||||
|
// Infrastructure services
|
||||||
|
export * from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
||||||
|
export * from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
||||||
|
export * from "@/service/infrastructure/notificationMessageBuilder.js";
|
||||||
|
export * from "@/service/infrastructure/bufferService.js";
|
||||||
|
export * from "@/service/infrastructure/emailService.js";
|
||||||
|
export * from "@/service/infrastructure/globalPingService.js";
|
||||||
export * from "@/service/infrastructure/networkService.js";
|
export * from "@/service/infrastructure/networkService.js";
|
||||||
|
export * from "@/service/infrastructure/notificationsService.js";
|
||||||
|
export * from "@/service/infrastructure/statusService.js";
|
||||||
|
|
||||||
|
// Notification providers
|
||||||
export * from "@/service/infrastructure/notificationProviders/discord.js";
|
export * from "@/service/infrastructure/notificationProviders/discord.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/email.js";
|
export * from "@/service/infrastructure/notificationProviders/email.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/INotificationProvider.js";
|
export * from "@/service/infrastructure/notificationProviders/INotificationProvider.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/pagerduty.js";
|
|
||||||
export * from "@/service/infrastructure/notificationProviders/matrix.js";
|
export * from "@/service/infrastructure/notificationProviders/matrix.js";
|
||||||
|
export * from "@/service/infrastructure/notificationProviders/pagerduty.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/slack.js";
|
export * from "@/service/infrastructure/notificationProviders/slack.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
||||||
export * from "@/service/infrastructure/notificationsService.js";
|
|
||||||
export * from "@/service/infrastructure/statusService.js";
|
// System services
|
||||||
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
export * from "@/service/system/settingsService.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/matrix.js";
|
|
||||||
export * from "@/service/business/statusPageService.js";
|
|
||||||
@@ -2,6 +2,7 @@ import { IMonitorsRepository } from "@/repositories/index.js";
|
|||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import Scheduler from "super-simple-scheduler";
|
import Scheduler from "super-simple-scheduler";
|
||||||
import { ISuperSimpleQueueHelper } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
import { ISuperSimpleQueueHelper } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
const SERVICE_NAME = "JobQueue";
|
const SERVICE_NAME = "JobQueue";
|
||||||
|
|
||||||
type QueueJobFailure = {
|
type QueueJobFailure = {
|
||||||
@@ -53,7 +54,7 @@ export interface ISuperSimpleQueue {
|
|||||||
obliterate(): Promise<void>;
|
obliterate(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SuperSimpleQueue implements ISuperSimpleQueue {
|
export class SuperSimpleQueue implements ISuperSimpleQueue {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -125,8 +126,13 @@ class SuperSimpleQueue implements ISuperSimpleQueue {
|
|||||||
data: monitor,
|
data: monitor,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Return early if we don't need geo checks
|
||||||
|
if (!supportsGeoCheck(monitor.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Add geo check job if enabled for HTTP monitors
|
// Add geo check job if enabled for HTTP monitors
|
||||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
if (monitor.geoCheckEnabled) {
|
||||||
this.scheduler.addJob({
|
this.scheduler.addJob({
|
||||||
id: `${monitorId}-geo`,
|
id: `${monitorId}-geo`,
|
||||||
template: "geo-check-job",
|
template: "geo-check-job",
|
||||||
@@ -175,7 +181,7 @@ class SuperSimpleQueue implements ISuperSimpleQueue {
|
|||||||
|
|
||||||
// Handle geo check job lifecycle
|
// Handle geo check job lifecycle
|
||||||
const geoJobId = `${monitor.id}-geo`;
|
const geoJobId = `${monitor.id}-geo`;
|
||||||
if (monitor.geoCheckEnabled && monitor.type === "http") {
|
if (monitor.geoCheckEnabled && supportsGeoCheck(monitor.type)) {
|
||||||
// Check if geo job exists
|
// Check if geo job exists
|
||||||
const existingGeoJob = await this.scheduler.getJob(geoJobId);
|
const existingGeoJob = await this.scheduler.getJob(geoJobId);
|
||||||
if (existingGeoJob) {
|
if (existingGeoJob) {
|
||||||
@@ -289,5 +295,3 @@ class SuperSimpleQueue implements ISuperSimpleQueue {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SuperSimpleQueue;
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
const SERVICE_NAME = "JobQueueHelper";
|
const SERVICE_NAME = "JobQueueHelper";
|
||||||
import type { Monitor } from "@/types/monitor.js";
|
import type { Monitor } from "@/types/monitor.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { INetworkService, INotificationsService, IStatusService } from "@/service/index.js";
|
import { INetworkService, INotificationsService, IStatusService, IncidentService, type IGeoChecksService } from "@/service/index.js";
|
||||||
import type { StatusChangeResult } from "@/types/index.js";
|
import type { StatusChangeResult } from "@/types/index.js";
|
||||||
import IncidentService from "@/service/business/incidentService.js";
|
|
||||||
import type { IGeoChecksService } from "@/service/business/geoChecksService.js";
|
|
||||||
import {
|
import {
|
||||||
IMaintenanceWindowsRepository,
|
IMaintenanceWindowsRepository,
|
||||||
IMonitorsRepository,
|
IMonitorsRepository,
|
||||||
@@ -15,7 +14,7 @@ import {
|
|||||||
IGeoChecksRepository,
|
IGeoChecksRepository,
|
||||||
} from "@/repositories/index.js";
|
} from "@/repositories/index.js";
|
||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import { IBufferService } from "../bufferService.js";
|
import { IBufferService } from "@/service/index.js";
|
||||||
|
|
||||||
export interface ISuperSimpleQueueHelper {
|
export interface ISuperSimpleQueueHelper {
|
||||||
readonly serviceName: string;
|
readonly serviceName: string;
|
||||||
@@ -39,7 +38,7 @@ export interface MonitorActionDecision {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
export class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: any;
|
private logger: any;
|
||||||
@@ -282,19 +281,18 @@ class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
|||||||
throw new AppError({ message: "No monitor id", service: SERVICE_NAME, method: "getGeoCheckJob" });
|
throw new AppError({ message: "No monitor id", service: SERVICE_NAME, method: "getGeoCheckJob" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor.type !== "http") {
|
if (!monitor.geoCheckEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!supportsGeoCheck(monitor.type)) {
|
||||||
this.logger.debug({
|
this.logger.debug({
|
||||||
message: `Monitor ${monitorId} is not HTTP type, skipping geo check`,
|
message: `Monitor ${monitorId} type does not support geo checks, skipping`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "getGeoCheckJob",
|
method: "getGeoCheckJob",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!monitor.geoCheckEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!monitor.geoCheckLocations || monitor.geoCheckLocations.length === 0) {
|
if (!monitor.geoCheckLocations || monitor.geoCheckLocations.length === 0) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `No geo check locations configured for monitor ${monitorId}`,
|
message: `No geo check locations configured for monitor ${monitorId}`,
|
||||||
@@ -414,5 +412,3 @@ class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
|
|||||||
return decision;
|
return decision;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SuperSimpleQueueHelper;
|
|
||||||
@@ -15,7 +15,7 @@ export interface IBufferService {
|
|||||||
flushGeoBuffer(): Promise<void>;
|
flushGeoBuffer(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BufferService implements IBufferService {
|
export class BufferService implements IBufferService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
private BUFFER_TIMEOUT: number;
|
private BUFFER_TIMEOUT: number;
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -177,5 +177,3 @@ class BufferService implements IBufferService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BufferService;
|
|
||||||
@@ -23,7 +23,7 @@ export interface IEmailService {
|
|||||||
sendEmail(to: string, subject: string, html: string, transportConfig?: EmailTransportConfig): Promise<string | false | undefined>;
|
sendEmail(to: string, subject: string, html: string, transportConfig?: EmailTransportConfig): Promise<string | false | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmailService implements IEmailService {
|
export class EmailService implements IEmailService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private settingsService: ISettingsService;
|
private settingsService: ISettingsService;
|
||||||
@@ -178,5 +178,3 @@ class EmailService implements IEmailService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EmailService;
|
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import type { GeoContinent, GeoCheckResult, GeoCheckTimings, GeoCheckLocation } from "@/types/geoCheck.js";
|
import type { GeoContinent, GeoCheckResult, GeoCheckTimings, GeoCheckLocation } from "@/types/geoCheck.js";
|
||||||
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
|
import { MonitorType } from "@/types/index.js";
|
||||||
import type { ILogger } from "@/utils/logger.js";
|
import type { ILogger } from "@/utils/logger.js";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
|
|
||||||
@@ -8,7 +10,7 @@ const POLL_INTERVAL_MS = 2000;
|
|||||||
const MAX_POLL_TIMEOUT_MS = 30000;
|
const MAX_POLL_TIMEOUT_MS = 30000;
|
||||||
|
|
||||||
interface GlobalPingMeasurementRequest {
|
interface GlobalPingMeasurementRequest {
|
||||||
type: "http";
|
type: MonitorType;
|
||||||
target: string;
|
target: string;
|
||||||
locations: Array<{ continent: GeoContinent }>;
|
locations: Array<{ continent: GeoContinent }>;
|
||||||
limit: number;
|
limit: number;
|
||||||
@@ -44,17 +46,26 @@ interface GlobalPingProbeResult {
|
|||||||
firstByte: number;
|
firstByte: number;
|
||||||
download: number;
|
download: number;
|
||||||
};
|
};
|
||||||
|
stats?: {
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
avg: number;
|
||||||
|
total: number;
|
||||||
|
loss: number;
|
||||||
|
rcv: number;
|
||||||
|
drop: number;
|
||||||
|
};
|
||||||
rawOutput?: string;
|
rawOutput?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGlobalPingService {
|
export interface IGlobalPingService {
|
||||||
readonly serviceName: string;
|
readonly serviceName: string;
|
||||||
createMeasurement(url: string, locations: GeoContinent[]): Promise<string | null>;
|
createMeasurement(monitorType: MonitorType, url: string, locations: GeoContinent[]): Promise<string | null>;
|
||||||
pollForResults(measurementId: string, timeoutMs?: number): Promise<GeoCheckResult[]>;
|
pollForResults(measurementId: string, timeoutMs?: number): Promise<GeoCheckResult[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GlobalPingService implements IGlobalPingService {
|
export class GlobalPingService implements IGlobalPingService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
@@ -67,13 +78,16 @@ class GlobalPingService implements IGlobalPingService {
|
|||||||
return GlobalPingService.SERVICE_NAME;
|
return GlobalPingService.SERVICE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createMeasurement(url: string, locations: GeoContinent[]): Promise<string | null> {
|
async createMeasurement(monitorType: MonitorType, url: string, locations: GeoContinent[]): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
|
if (!supportsGeoCheck(monitorType)) {
|
||||||
|
throw new Error(`Unsupported monitor type for GlobalPing: ${monitorType}`);
|
||||||
|
}
|
||||||
// GlobalPing API expects target without protocol (http:// or https://)
|
// GlobalPing API expects target without protocol (http:// or https://)
|
||||||
const cleanTarget = url.replace(/^https?:\/\//, "");
|
const cleanTarget = url.replace(/^https?:\/\//, "");
|
||||||
|
|
||||||
const requestBody: GlobalPingMeasurementRequest = {
|
const requestBody: GlobalPingMeasurementRequest = {
|
||||||
type: "http",
|
type: monitorType,
|
||||||
target: cleanTarget,
|
target: cleanTarget,
|
||||||
locations: locations.map((continent) => ({ continent })),
|
locations: locations.map((continent) => ({ continent })),
|
||||||
limit: locations.length,
|
limit: locations.length,
|
||||||
@@ -88,10 +102,9 @@ class GlobalPingService implements IGlobalPingService {
|
|||||||
const measurementId = response.body.id;
|
const measurementId = response.body.id;
|
||||||
|
|
||||||
this.logger.debug({
|
this.logger.debug({
|
||||||
message: `Created GlobalPing measurement: ${measurementId}`,
|
message: `Created GlobalPing measurement: ${measurementId} for target: ${cleanTarget}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "createMeasurement",
|
method: "createMeasurement",
|
||||||
details: { measurementId, url, locations },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return measurementId;
|
return measurementId;
|
||||||
@@ -165,8 +178,7 @@ class GlobalPingService implements IGlobalPingService {
|
|||||||
const successfulResults: GeoCheckResult[] = [];
|
const successfulResults: GeoCheckResult[] = [];
|
||||||
|
|
||||||
for (const probeResult of probeResults) {
|
for (const probeResult of probeResults) {
|
||||||
// Skip failed or timeout results
|
if (probeResult.result.status !== "finished") {
|
||||||
if (probeResult.result.status !== "finished" || !probeResult.result.statusCode || !probeResult.result.timings) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,23 +192,38 @@ class GlobalPingService implements IGlobalPingService {
|
|||||||
latitude: probeResult.probe.latitude,
|
latitude: probeResult.probe.latitude,
|
||||||
};
|
};
|
||||||
|
|
||||||
const timings: GeoCheckTimings = {
|
// HTTP results have statusCode and timings, ping results have stats
|
||||||
total: probeResult.result.timings.total,
|
if (probeResult.result.statusCode && probeResult.result.timings) {
|
||||||
dns: probeResult.result.timings.dns,
|
const timings: GeoCheckTimings = {
|
||||||
tcp: probeResult.result.timings.tcp,
|
total: probeResult.result.timings.total,
|
||||||
tls: probeResult.result.timings.tls,
|
dns: probeResult.result.timings.dns,
|
||||||
firstByte: probeResult.result.timings.firstByte,
|
tcp: probeResult.result.timings.tcp,
|
||||||
download: probeResult.result.timings.download,
|
tls: probeResult.result.timings.tls,
|
||||||
};
|
firstByte: probeResult.result.timings.firstByte,
|
||||||
|
download: probeResult.result.timings.download,
|
||||||
|
};
|
||||||
|
|
||||||
const result: GeoCheckResult = {
|
successfulResults.push({
|
||||||
location,
|
location,
|
||||||
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
status: probeResult.result.statusCode >= 200 && probeResult.result.statusCode < 300,
|
||||||
statusCode: probeResult.result.statusCode,
|
statusCode: probeResult.result.statusCode,
|
||||||
timings,
|
timings,
|
||||||
};
|
});
|
||||||
|
} else if (probeResult.result.stats) {
|
||||||
successfulResults.push(result);
|
successfulResults.push({
|
||||||
|
location,
|
||||||
|
status: probeResult.result.stats.loss === 0,
|
||||||
|
statusCode: probeResult.result.stats.loss === 0 ? 200 : 5000,
|
||||||
|
timings: {
|
||||||
|
total: probeResult.result.stats.avg,
|
||||||
|
dns: 0,
|
||||||
|
tcp: 0,
|
||||||
|
tls: 0,
|
||||||
|
firstByte: 0,
|
||||||
|
download: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return successfulResults;
|
return successfulResults;
|
||||||
@@ -206,5 +233,3 @@ class GlobalPingService implements IGlobalPingService {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GlobalPingService;
|
|
||||||
@@ -4,7 +4,7 @@ import { MonitorType, Monitor } from "@/types/monitor.js";
|
|||||||
import { MonitorStatusResponse } from "@/types/network.js";
|
import { MonitorStatusResponse } from "@/types/network.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import ping from "ping";
|
import ping from "ping";
|
||||||
import { buildStatusResponse, timeRequest } from "@/service/infrastructure/network/utils.js";
|
import { timeRequest } from "@/service/infrastructure/network/utils.js";
|
||||||
const SERVICE_NAME = "PingProvider";
|
const SERVICE_NAME = "PingProvider";
|
||||||
|
|
||||||
type Ping = typeof ping;
|
type Ping = typeof ping;
|
||||||
@@ -33,7 +33,7 @@ export class PingProvider implements IStatusProvider<PingStatusPayload> {
|
|||||||
|
|
||||||
const sanitizedHost = this.sanitizeHost(monitor.url);
|
const sanitizedHost = this.sanitizeHost(monitor.url);
|
||||||
const { response, error } = await timeRequest<PingStatusPayload>(() => this.ping.promise.probe(sanitizedHost));
|
const { response, error } = await timeRequest<PingStatusPayload>(() => this.ping.promise.probe(sanitizedHost));
|
||||||
const safeTime = typeof response?.time === "number" ? response.time : parseFloat(String(response?.time)) || 0;
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -42,16 +42,18 @@ export class PingProvider implements IStatusProvider<PingStatusPayload> {
|
|||||||
throw new Error(`No response from ping for host: ${sanitizedHost}`);
|
throw new Error(`No response from ping for host: ${sanitizedHost}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildStatusResponse<PingStatusPayload>({
|
const responseTime = typeof response.time === "number" ? response.time : parseFloat(String(response.time)) || 0;
|
||||||
monitor,
|
|
||||||
|
return {
|
||||||
|
monitorId: monitor.id,
|
||||||
|
teamId: monitor.teamId,
|
||||||
|
type: monitor.type,
|
||||||
|
status: response.alive ?? false,
|
||||||
|
code: response.alive ? 200 : 5000,
|
||||||
|
message: response.alive ? "Success" : "Ping failed",
|
||||||
|
responseTime,
|
||||||
payload: response,
|
payload: response,
|
||||||
overrides: {
|
};
|
||||||
status: response.alive ?? false,
|
|
||||||
code: 200,
|
|
||||||
message: "Success",
|
|
||||||
responseTime: safeTime,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const message = err instanceof Error ? err.message : String(err);
|
const message = err instanceof Error ? err.message : String(err);
|
||||||
throw new AppError({
|
throw new AppError({
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ export class PortProvider implements IStatusProvider<PortStatusPayload> {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error);
|
|
||||||
const errorMessage = error instanceof Error ? error.message : "Port check failed";
|
const errorMessage = error instanceof Error ? error.message : "Port check failed";
|
||||||
return {
|
return {
|
||||||
monitorId: monitor.id,
|
monitorId: monitor.id,
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
import { HTTPError, RequestError } from "got";
|
|
||||||
import type { Response } from "got";
|
|
||||||
import type { Monitor } from "@/types/monitor.js";
|
|
||||||
import { MonitorStatusResponse, MonitorStatusResponseOverrides } from "@/types/network.js";
|
|
||||||
|
|
||||||
export const timeRequest = async <T>(operation: () => Promise<T>): Promise<{ response: T | null; responseTime: number; error: unknown }> => {
|
export const timeRequest = async <T>(operation: () => Promise<T>): Promise<{ response: T | null; responseTime: number; error: unknown }> => {
|
||||||
const start = process.hrtime.bigint();
|
const start = process.hrtime.bigint();
|
||||||
try {
|
try {
|
||||||
@@ -17,69 +12,3 @@ export const timeRequest = async <T>(operation: () => Promise<T>): Promise<{ res
|
|||||||
|
|
||||||
export const NETWORK_ERROR = 5000;
|
export const NETWORK_ERROR = 5000;
|
||||||
export const PING_ERROR = 5001;
|
export const PING_ERROR = 5001;
|
||||||
|
|
||||||
interface BuildStatusResponseArgs<T> {
|
|
||||||
monitor: Monitor;
|
|
||||||
response?: Response<T> | null;
|
|
||||||
error?: Error | RequestError | HTTPError | null;
|
|
||||||
payload?: T | null;
|
|
||||||
jsonPath?: string;
|
|
||||||
matchMethod?: MonitorStatusResponse["matchMethod"];
|
|
||||||
expectedValue?: string;
|
|
||||||
extracted?: unknown;
|
|
||||||
overrides?: MonitorStatusResponseOverrides<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const buildStatusResponse = <T>({
|
|
||||||
monitor,
|
|
||||||
response,
|
|
||||||
error,
|
|
||||||
payload,
|
|
||||||
jsonPath,
|
|
||||||
matchMethod,
|
|
||||||
expectedValue,
|
|
||||||
extracted,
|
|
||||||
overrides,
|
|
||||||
}: BuildStatusResponseArgs<T>): MonitorStatusResponse<T> => {
|
|
||||||
if (error) {
|
|
||||||
const statusResponse: MonitorStatusResponse<T> = {
|
|
||||||
monitorId: monitor.id,
|
|
||||||
teamId: monitor.teamId,
|
|
||||||
type: monitor.type,
|
|
||||||
status: false,
|
|
||||||
code: NETWORK_ERROR,
|
|
||||||
message: error.message ?? "Network error",
|
|
||||||
responseTime: 0,
|
|
||||||
timings: undefined,
|
|
||||||
jsonPath,
|
|
||||||
matchMethod,
|
|
||||||
expectedValue,
|
|
||||||
extracted,
|
|
||||||
payload,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (error instanceof HTTPError || error instanceof RequestError) {
|
|
||||||
statusResponse.code = error?.response?.statusCode ?? NETWORK_ERROR;
|
|
||||||
statusResponse.message = error.message;
|
|
||||||
statusResponse.responseTime = error.timings?.phases?.total ?? 0;
|
|
||||||
statusResponse.timings = error.timings;
|
|
||||||
}
|
|
||||||
return { ...statusResponse, ...(overrides ?? {}) };
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
monitorId: monitor.id,
|
|
||||||
teamId: monitor.teamId,
|
|
||||||
type: monitor.type,
|
|
||||||
status: response?.ok ?? false,
|
|
||||||
code: response?.statusCode ?? NETWORK_ERROR,
|
|
||||||
message: response?.statusMessage ?? "",
|
|
||||||
responseTime: response?.timings?.phases?.total ?? 0,
|
|
||||||
timings: response?.timings,
|
|
||||||
payload: payload ?? response?.body,
|
|
||||||
jsonPath,
|
|
||||||
matchMethod,
|
|
||||||
expectedValue,
|
|
||||||
extracted,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,38 +1,14 @@
|
|||||||
import type {
|
import type { Monitor, MonitorStatusResponse } from "@/types/index.js";
|
||||||
Monitor,
|
|
||||||
MonitorStatusResponse,
|
|
||||||
GrpcStatusPayload,
|
|
||||||
PageSpeedStatusPayload,
|
|
||||||
HttpStatusPayload,
|
|
||||||
HardwareStatusPayload,
|
|
||||||
PingStatusPayload,
|
|
||||||
DockerStatusPayload,
|
|
||||||
PortStatusPayload,
|
|
||||||
GameStatusPayload,
|
|
||||||
} from "@/types/index.js";
|
|
||||||
import type { AxiosStatic } from "axios";
|
import type { AxiosStatic } from "axios";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
|
import { NETWORK_ERROR } from "@/service/infrastructure/network/utils.js";
|
||||||
import { ILogger } from "@/utils/logger.js";
|
import { ILogger } from "@/utils/logger.js";
|
||||||
import { IStatusProvider } from "./network/IStatusProvider.js";
|
import { IStatusProvider } from "./network/IStatusProvider.js";
|
||||||
const SERVICE_NAME = "NetworkService";
|
const SERVICE_NAME = "NetworkService";
|
||||||
|
|
||||||
export interface INetworkService {
|
export interface INetworkService {
|
||||||
readonly serviceName: string;
|
readonly serviceName: string;
|
||||||
requestStatus(
|
requestStatus(monitor: Monitor): Promise<MonitorStatusResponse<unknown>>;
|
||||||
monitor: Monitor
|
|
||||||
): Promise<
|
|
||||||
MonitorStatusResponse<
|
|
||||||
| PingStatusPayload
|
|
||||||
| HttpStatusPayload
|
|
||||||
| PageSpeedStatusPayload
|
|
||||||
| HardwareStatusPayload
|
|
||||||
| DockerStatusPayload
|
|
||||||
| PortStatusPayload
|
|
||||||
| GameStatusPayload
|
|
||||||
| GrpcStatusPayload
|
|
||||||
>
|
|
||||||
>;
|
|
||||||
requestWebhook(
|
requestWebhook(
|
||||||
type: string,
|
type: string,
|
||||||
url: string,
|
url: string,
|
||||||
@@ -47,66 +23,19 @@ export interface INetworkService {
|
|||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkService implements INetworkService {
|
export class NetworkService implements INetworkService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private TYPE_PING: string;
|
|
||||||
private TYPE_HTTP: string;
|
|
||||||
private TYPE_PAGESPEED: string;
|
|
||||||
private TYPE_HARDWARE: string;
|
|
||||||
private TYPE_DOCKER: string;
|
|
||||||
private TYPE_PORT: string;
|
|
||||||
private TYPE_GAME: string;
|
|
||||||
private TYPE_GRPC: string;
|
|
||||||
private SERVICE_NAME: string;
|
|
||||||
private NETWORK_ERROR: number;
|
|
||||||
private PING_ERROR: number;
|
|
||||||
|
|
||||||
private axios: AxiosStatic;
|
private axios: AxiosStatic;
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
private pingProvider;
|
|
||||||
private httpProvider;
|
|
||||||
private pageSpeedProvider;
|
|
||||||
private hardwareProvider;
|
|
||||||
private dockerProvider;
|
|
||||||
private portProvider;
|
|
||||||
private gameProvider;
|
|
||||||
private grpcProvider;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
axios: AxiosStatic,
|
axios: AxiosStatic,
|
||||||
logger: ILogger,
|
logger: ILogger,
|
||||||
pingProvider: IStatusProvider<PingStatusPayload>,
|
private providers: IStatusProvider<unknown>[]
|
||||||
httpProvider: IStatusProvider<HttpStatusPayload>,
|
|
||||||
pagespeedProvider: IStatusProvider<PageSpeedStatusPayload>,
|
|
||||||
hardwareProvider: IStatusProvider<HardwareStatusPayload>,
|
|
||||||
dockerProvider: IStatusProvider<DockerStatusPayload>,
|
|
||||||
portProvider: IStatusProvider<PortStatusPayload>,
|
|
||||||
gameProvider: IStatusProvider<GameStatusPayload>,
|
|
||||||
grpcProvider: IStatusProvider<GrpcStatusPayload>
|
|
||||||
) {
|
) {
|
||||||
this.TYPE_PING = "ping";
|
|
||||||
this.TYPE_HTTP = "http";
|
|
||||||
this.TYPE_PAGESPEED = "pagespeed";
|
|
||||||
this.TYPE_HARDWARE = "hardware";
|
|
||||||
this.TYPE_DOCKER = "docker";
|
|
||||||
this.TYPE_PORT = "port";
|
|
||||||
this.TYPE_GAME = "game";
|
|
||||||
this.TYPE_GRPC = "grpc";
|
|
||||||
this.SERVICE_NAME = SERVICE_NAME;
|
|
||||||
this.NETWORK_ERROR = 5000;
|
|
||||||
this.PING_ERROR = 5001;
|
|
||||||
this.axios = axios;
|
this.axios = axios;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
this.pingProvider = pingProvider;
|
|
||||||
this.httpProvider = httpProvider;
|
|
||||||
this.pageSpeedProvider = pagespeedProvider;
|
|
||||||
this.hardwareProvider = hardwareProvider;
|
|
||||||
this.dockerProvider = dockerProvider;
|
|
||||||
this.portProvider = portProvider;
|
|
||||||
this.gameProvider = gameProvider;
|
|
||||||
this.grpcProvider = grpcProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get serviceName(): string {
|
get serviceName(): string {
|
||||||
@@ -114,41 +43,12 @@ class NetworkService implements INetworkService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Main entry point
|
// Main entry point
|
||||||
async requestStatus(
|
async requestStatus(monitor: Monitor) {
|
||||||
monitor: Monitor
|
const provider = this.providers.find((p) => p.supports(monitor.type));
|
||||||
): Promise<
|
if (!provider) {
|
||||||
MonitorStatusResponse<
|
return this.handleUnsupportedType(monitor.type);
|
||||||
| PingStatusPayload
|
|
||||||
| HttpStatusPayload
|
|
||||||
| PageSpeedStatusPayload
|
|
||||||
| HardwareStatusPayload
|
|
||||||
| DockerStatusPayload
|
|
||||||
| PortStatusPayload
|
|
||||||
| GameStatusPayload
|
|
||||||
| GrpcStatusPayload
|
|
||||||
>
|
|
||||||
> {
|
|
||||||
const type = monitor?.type || "unknown";
|
|
||||||
switch (type) {
|
|
||||||
case this.TYPE_PING:
|
|
||||||
return await this.pingProvider.handle(monitor);
|
|
||||||
case this.TYPE_HTTP:
|
|
||||||
return await this.httpProvider.handle(monitor);
|
|
||||||
case this.TYPE_PAGESPEED:
|
|
||||||
return await this.pageSpeedProvider.handle(monitor);
|
|
||||||
case this.TYPE_HARDWARE:
|
|
||||||
return await this.hardwareProvider.handle(monitor);
|
|
||||||
case this.TYPE_DOCKER:
|
|
||||||
return await this.dockerProvider.handle(monitor);
|
|
||||||
case this.TYPE_PORT:
|
|
||||||
return await this.portProvider.handle(monitor);
|
|
||||||
case this.TYPE_GAME:
|
|
||||||
return await this.gameProvider.handle(monitor);
|
|
||||||
case this.TYPE_GRPC:
|
|
||||||
return await this.grpcProvider.handle(monitor);
|
|
||||||
default:
|
|
||||||
return this.handleUnsupportedType(type);
|
|
||||||
}
|
}
|
||||||
|
return provider.handle(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleUnsupportedType(type: string): Promise<MonitorStatusResponse> {
|
private async handleUnsupportedType(type: string): Promise<MonitorStatusResponse> {
|
||||||
@@ -157,7 +57,7 @@ class NetworkService implements INetworkService {
|
|||||||
teamId: "unknown",
|
teamId: "unknown",
|
||||||
type: "unknown",
|
type: "unknown",
|
||||||
status: false,
|
status: false,
|
||||||
code: this.NETWORK_ERROR,
|
code: NETWORK_ERROR,
|
||||||
message: `Unsupported type: ${type}`,
|
message: `Unsupported type: ${type}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -181,7 +81,7 @@ class NetworkService implements INetworkService {
|
|||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: err instanceof Error ? err.message : String(err),
|
message: err instanceof Error ? err.message : String(err),
|
||||||
service: this.SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "requestWebhook",
|
method: "requestWebhook",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -190,7 +90,7 @@ class NetworkService implements INetworkService {
|
|||||||
return {
|
return {
|
||||||
type: "webhook",
|
type: "webhook",
|
||||||
status: false,
|
status: false,
|
||||||
code: axiosError.response?.status ?? this.NETWORK_ERROR,
|
code: axiosError.response?.status ?? NETWORK_ERROR,
|
||||||
message: `Failed to send ${type} notification`,
|
message: `Failed to send ${type} notification`,
|
||||||
payload: axiosError.response?.data,
|
payload: axiosError.response?.data,
|
||||||
};
|
};
|
||||||
@@ -199,7 +99,7 @@ class NetworkService implements INetworkService {
|
|||||||
return {
|
return {
|
||||||
type: "webhook",
|
type: "webhook",
|
||||||
status: false,
|
status: false,
|
||||||
code: this.NETWORK_ERROR,
|
code: NETWORK_ERROR,
|
||||||
message: `Failed to send ${type} notification`,
|
message: `Failed to send ${type} notification`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -225,7 +125,7 @@ class NetworkService implements INetworkService {
|
|||||||
|
|
||||||
throw new AppError({
|
throw new AppError({
|
||||||
message: originalMessage || "Error sending PagerDuty notification",
|
message: originalMessage || "Error sending PagerDuty notification",
|
||||||
service: this.SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "requestPagerDuty",
|
method: "requestPagerDuty",
|
||||||
details: {
|
details: {
|
||||||
responseData: err && typeof err === "object" && "response" in err ? (err as { response?: { data?: unknown } }).response?.data : undefined,
|
responseData: err && typeof err === "object" && "response" in err ? (err as { response?: { data?: unknown } }).response?.data : undefined,
|
||||||
@@ -268,7 +168,7 @@ class NetworkService implements INetworkService {
|
|||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: err.message,
|
message: err.message,
|
||||||
service: this.SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "requestMatrix",
|
method: "requestMatrix",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -276,7 +176,7 @@ class NetworkService implements INetworkService {
|
|||||||
const axiosError = err as { response?: { status?: number; data?: unknown } };
|
const axiosError = err as { response?: { status?: number; data?: unknown } };
|
||||||
return {
|
return {
|
||||||
status: false,
|
status: false,
|
||||||
code: axiosError.response?.status || this.NETWORK_ERROR,
|
code: axiosError.response?.status || NETWORK_ERROR,
|
||||||
message: "Failed to send Matrix notification",
|
message: "Failed to send Matrix notification",
|
||||||
payload: axiosError.response?.data,
|
payload: axiosError.response?.data,
|
||||||
};
|
};
|
||||||
@@ -285,17 +185,15 @@ class NetworkService implements INetworkService {
|
|||||||
|
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: String(err),
|
message: String(err),
|
||||||
service: this.SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "requestMatrix",
|
method: "requestMatrix",
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: false,
|
status: false,
|
||||||
code: this.NETWORK_ERROR,
|
code: NETWORK_ERROR,
|
||||||
message: "Failed to send Matrix notification",
|
message: "Failed to send Matrix notification",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NetworkService;
|
|
||||||
@@ -21,7 +21,7 @@ export interface ISettingsService {
|
|||||||
getDBSettings(): Promise<Settings>;
|
getDBSettings(): Promise<Settings>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsService implements ISettingsService {
|
export class SettingsService implements ISettingsService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
private settings: EnvConfig;
|
private settings: EnvConfig;
|
||||||
private settingsRepository: ISettingsRepository;
|
private settingsRepository: ISettingsRepository;
|
||||||
@@ -74,5 +74,3 @@ class SettingsService implements ISettingsService {
|
|||||||
return settings;
|
return settings;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SettingsService;
|
|
||||||
@@ -6,6 +6,9 @@ export type { GeoContinent } from "@/types/geoCheck.js";
|
|||||||
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "unknown"] as const;
|
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "unknown"] as const;
|
||||||
export type MonitorType = (typeof MonitorTypes)[number];
|
export type MonitorType = (typeof MonitorTypes)[number];
|
||||||
|
|
||||||
|
export const GeoCheckSupportedTypes: readonly MonitorType[] = ["http", "ping"] as const;
|
||||||
|
export const supportsGeoCheck = (type: MonitorType): boolean => GeoCheckSupportedTypes.includes(type);
|
||||||
|
|
||||||
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
export const MonitorStatuses = ["up", "down", "paused", "initializing", "maintenance", "breached"] as const;
|
||||||
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
export type MonitorStatus = (typeof MonitorStatuses)[number];
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|||||||
|
|
||||||
const envSchema = z.object({
|
const envSchema = z.object({
|
||||||
// Server Configuration
|
// Server Configuration
|
||||||
|
PORT: z.string().default("52345"),
|
||||||
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
||||||
LOG_LEVEL: z.enum(["error", "warn", "info", "debug"]).default("debug"),
|
LOG_LEVEL: z.enum(["error", "warn", "info", "debug"]).default("debug"),
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user