Merge pull request #3429 from bluewave-labs/fix/monitor-service-lint
fix/monitor service lint
This commit is contained in:
4 files changed
+81
-75
No files matched your search
@@ -17,7 +17,6 @@ import {
|
|||||||
} from "@/validation/monitorValidation.js";
|
} from "@/validation/monitorValidation.js";
|
||||||
import sslChecker from "ssl-checker";
|
import sslChecker from "ssl-checker";
|
||||||
import { fetchMonitorCertificate, requireTeamId, requireUserId } from "./controllerUtils.js";
|
import { fetchMonitorCertificate, requireTeamId, requireUserId } from "./controllerUtils.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
|
||||||
import { IMonitorService } from "@/service/index.js";
|
import { IMonitorService } from "@/service/index.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "monitorController";
|
const SERVICE_NAME = "monitorController";
|
||||||
@@ -60,7 +59,6 @@ class MonitorController {
|
|||||||
|
|
||||||
const monitorId = validatedParams.monitorId;
|
const monitorId = validatedParams.monitorId;
|
||||||
const dateRange = validatedQuery.dateRange;
|
const dateRange = validatedQuery.dateRange;
|
||||||
const normalize = validatedQuery.normalize;
|
|
||||||
|
|
||||||
const teamId = requireTeamId(req.user?.teamId);
|
const teamId = requireTeamId(req.user?.teamId);
|
||||||
|
|
||||||
@@ -68,7 +66,6 @@ class MonitorController {
|
|||||||
teamId,
|
teamId,
|
||||||
monitorId,
|
monitorId,
|
||||||
dateRange,
|
dateRange,
|
||||||
normalize,
|
|
||||||
});
|
});
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -324,7 +321,6 @@ class MonitorController {
|
|||||||
try {
|
try {
|
||||||
const validatedQuery = getMonitorsWithChecksQueryValidation.parse(req.query);
|
const validatedQuery = getMonitorsWithChecksQueryValidation.parse(req.query);
|
||||||
|
|
||||||
const explain = validatedQuery.explain;
|
|
||||||
const limit = validatedQuery.limit;
|
const limit = validatedQuery.limit;
|
||||||
const page = validatedQuery.page;
|
const page = validatedQuery.page;
|
||||||
const rowsPerPage = validatedQuery.rowsPerPage;
|
const rowsPerPage = validatedQuery.rowsPerPage;
|
||||||
@@ -343,7 +339,6 @@ class MonitorController {
|
|||||||
filter,
|
filter,
|
||||||
field,
|
field,
|
||||||
order,
|
order,
|
||||||
explain,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import type {
|
|||||||
HardwareDetailsResult,
|
HardwareDetailsResult,
|
||||||
PageSpeedDetailsResult,
|
PageSpeedDetailsResult,
|
||||||
GamesMap,
|
GamesMap,
|
||||||
|
GroupedGeoCheckResult,
|
||||||
} from "@/types/monitor.js";
|
} from "@/types/monitor.js";
|
||||||
import { supportsGeoCheck } from "@/types/monitor.js";
|
import { supportsGeoCheck } from "@/types/monitor.js";
|
||||||
import type { GeoContinent } from "@/types/geoCheck.js";
|
import type { GeoContinent } from "@/types/geoCheck.js";
|
||||||
@@ -20,7 +21,10 @@ import type {
|
|||||||
} from "@/repositories/index.js";
|
} from "@/repositories/index.js";
|
||||||
import demoMonitorsData from "@/utils/demoMonitors.json" with { type: "json" };
|
import demoMonitorsData from "@/utils/demoMonitors.json" with { type: "json" };
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
|
import type { ImportedMonitor } from "@/validation/monitorValidation.js";
|
||||||
import { ISuperSimpleQueue } from "../infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
import { ISuperSimpleQueue } from "../infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
||||||
|
import { IEmailService } from "../infrastructure/emailService.js";
|
||||||
|
import { ILogger } from "@/utils/logger.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "MonitorService";
|
const SERVICE_NAME = "MonitorService";
|
||||||
type DateRangeKey = "recent" | "day" | "week" | "month" | "all";
|
type DateRangeKey = "recent" | "day" | "week" | "month" | "all";
|
||||||
@@ -30,14 +34,19 @@ export interface IMonitorService {
|
|||||||
|
|
||||||
// create
|
// create
|
||||||
createMonitor(teamId: string, userId: string, body: Partial<Monitor>): Promise<void>;
|
createMonitor(teamId: string, userId: string, body: Partial<Monitor>): Promise<void>;
|
||||||
createMonitors(monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null>;
|
createMonitors(monitors: Array<Monitor>): Promise<Monitor[] | null>;
|
||||||
addDemoMonitors(args: { userId: string; teamId: string }): Promise<Monitor[]>;
|
addDemoMonitors(args: { userId: string; teamId: string }): Promise<Monitor[]>;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: string; normalize?: boolean }): Promise<UptimeDetailsResult>;
|
getUptimeDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<UptimeDetailsResult>;
|
||||||
getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<HardwareDetailsResult>;
|
getHardwareDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<HardwareDetailsResult>;
|
||||||
getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<PageSpeedDetailsResult>;
|
getPageSpeedDetailsById(args: { teamId: string; monitorId: string; dateRange: string }): Promise<PageSpeedDetailsResult>;
|
||||||
getGeoChecksByMonitorId(args: { teamId: string; monitorId: string; dateRange: string; continents?: GeoContinent[] }): Promise<any>;
|
getGeoChecksByMonitorId(args: {
|
||||||
|
teamId: string;
|
||||||
|
monitorId: string;
|
||||||
|
dateRange: string;
|
||||||
|
continents?: GeoContinent[];
|
||||||
|
}): Promise<GroupedGeoCheckResult>;
|
||||||
getMonitorById(args: { teamId: string; monitorId: string }): Promise<Monitor>;
|
getMonitorById(args: { teamId: string; monitorId: string }): Promise<Monitor>;
|
||||||
getMonitorsByTeamId(args: {
|
getMonitorsByTeamId(args: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
@@ -58,7 +67,6 @@ export interface IMonitorService {
|
|||||||
filter?: string;
|
filter?: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
order?: "asc" | "desc";
|
order?: "asc" | "desc";
|
||||||
explain?: boolean;
|
|
||||||
}): Promise<MonitorsWithChecksByTeamIdResult>;
|
}): Promise<MonitorsWithChecksByTeamIdResult>;
|
||||||
getAllGames(): GamesMap;
|
getAllGames(): GamesMap;
|
||||||
getGroupsByTeamId(args: { teamId: string }): Promise<string[]>;
|
getGroupsByTeamId(args: { teamId: string }): Promise<string[]>;
|
||||||
@@ -73,16 +81,16 @@ export interface IMonitorService {
|
|||||||
|
|
||||||
// other
|
// other
|
||||||
exportMonitorsToJSON(args: { teamId: string }): Promise<Monitor[]>;
|
exportMonitorsToJSON(args: { teamId: string }): Promise<Monitor[]>;
|
||||||
importMonitorsFromJSON(args: { teamId: string; userId: string; monitors: any[] }): Promise<{ imported: number; errors: string[] }>;
|
importMonitorsFromJSON(args: { teamId: string; userId: string; monitors: ImportedMonitor[] }): Promise<{ imported: number; errors: string[] }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MonitorService implements IMonitorService {
|
export class MonitorService implements IMonitorService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
private jobQueue: ISuperSimpleQueue;
|
private jobQueue: ISuperSimpleQueue;
|
||||||
private emailService: any;
|
private emailService: IEmailService;
|
||||||
private logger: any;
|
private logger: ILogger;
|
||||||
private games: any;
|
private games: GamesMap;
|
||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
private checksRepository: IChecksRepository;
|
private checksRepository: IChecksRepository;
|
||||||
private geoChecksRepository: IGeoChecksRepository;
|
private geoChecksRepository: IGeoChecksRepository;
|
||||||
@@ -103,9 +111,9 @@ export class MonitorService implements IMonitorService {
|
|||||||
incidentsRepository,
|
incidentsRepository,
|
||||||
}: {
|
}: {
|
||||||
jobQueue: ISuperSimpleQueue;
|
jobQueue: ISuperSimpleQueue;
|
||||||
emailService: any;
|
emailService: IEmailService;
|
||||||
logger: any;
|
logger: ILogger;
|
||||||
games: any;
|
games: GamesMap;
|
||||||
monitorsRepository: IMonitorsRepository;
|
monitorsRepository: IMonitorsRepository;
|
||||||
checksRepository: IChecksRepository;
|
checksRepository: IChecksRepository;
|
||||||
geoChecksRepository: IGeoChecksRepository;
|
geoChecksRepository: IGeoChecksRepository;
|
||||||
@@ -163,7 +171,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
this.jobQueue.addJob(monitor.id, monitor);
|
this.jobQueue.addJob(monitor.id, monitor);
|
||||||
};
|
};
|
||||||
|
|
||||||
createMonitors = async (monitors: Array<Monitor>, userId: string, teamId: string): Promise<Monitor[] | null> => {
|
createMonitors = async (monitors: Array<Monitor>): Promise<Monitor[] | null> => {
|
||||||
const createdMonitors = await this.monitorsRepository.createMonitors(monitors);
|
const createdMonitors = await this.monitorsRepository.createMonitors(monitors);
|
||||||
if (!monitors || monitors.length === 0) {
|
if (!monitors || monitors.length === 0) {
|
||||||
throw new AppError({ message: "Failed to create monitors", status: 500, service: SERVICE_NAME, method: "createMonitors" });
|
throw new AppError({ message: "Failed to create monitors", status: 500, service: SERVICE_NAME, method: "createMonitors" });
|
||||||
@@ -173,7 +181,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
return createdMonitors;
|
return createdMonitors;
|
||||||
};
|
};
|
||||||
|
|
||||||
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<any[]> => {
|
addDemoMonitors = async ({ userId, teamId }: { userId: string; teamId: string }): Promise<Monitor[]> => {
|
||||||
const demoData = demoMonitorsData;
|
const demoData = demoMonitorsData;
|
||||||
const monitors = demoData.map((monitor) => ({
|
const monitors = demoData.map((monitor) => ({
|
||||||
userId,
|
userId,
|
||||||
@@ -194,12 +202,10 @@ export class MonitorService implements IMonitorService {
|
|||||||
teamId,
|
teamId,
|
||||||
monitorId,
|
monitorId,
|
||||||
dateRange,
|
dateRange,
|
||||||
normalize,
|
|
||||||
}: {
|
}: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
monitorId: string;
|
monitorId: string;
|
||||||
dateRange: string;
|
dateRange: string;
|
||||||
normalize?: boolean;
|
|
||||||
}): Promise<UptimeDetailsResult> => {
|
}): Promise<UptimeDetailsResult> => {
|
||||||
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
@@ -327,7 +333,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
monitorId: string;
|
monitorId: string;
|
||||||
dateRange: string;
|
dateRange: string;
|
||||||
continents?: GeoContinent[];
|
continents?: GeoContinent[];
|
||||||
}): Promise<any> => {
|
}): Promise<GroupedGeoCheckResult> => {
|
||||||
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
throw new AppError({ message: `Monitor with ID ${monitorId} not found.`, status: 404 });
|
||||||
@@ -380,7 +386,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
filter,
|
filter,
|
||||||
field,
|
field,
|
||||||
order,
|
order,
|
||||||
explain,
|
|
||||||
}: {
|
}: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
@@ -390,7 +395,6 @@ export class MonitorService implements IMonitorService {
|
|||||||
filter?: string;
|
filter?: string;
|
||||||
field?: string;
|
field?: string;
|
||||||
order?: "asc" | "desc";
|
order?: "asc" | "desc";
|
||||||
explain?: boolean;
|
|
||||||
}): Promise<MonitorsWithChecksByTeamIdResult> => {
|
}): Promise<MonitorsWithChecksByTeamIdResult> => {
|
||||||
const summary = await this.monitorsRepository.findMonitorsSummaryByTeamId(teamId, { type });
|
const summary = await this.monitorsRepository.findMonitorsSummaryByTeamId(teamId, { type });
|
||||||
const count = await this.monitorsRepository.findMonitorCountByTeamIdAndType(teamId, { type, filter });
|
const count = await this.monitorsRepository.findMonitorCountByTeamIdAndType(teamId, { type, filter });
|
||||||
@@ -437,47 +441,51 @@ export class MonitorService implements IMonitorService {
|
|||||||
|
|
||||||
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
|
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
|
||||||
const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId);
|
||||||
monitor.isActive === true ? await this.jobQueue.resumeJob(monitor) : await this.jobQueue.pauseJob(monitor);
|
if (monitor.isActive) {
|
||||||
|
await this.jobQueue.resumeJob(monitor);
|
||||||
|
} else {
|
||||||
|
await this.jobQueue.pauseJob(monitor);
|
||||||
|
}
|
||||||
return monitor;
|
return monitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
|
deleteMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
|
||||||
const monitor = await this.monitorsRepository.deleteById(monitorId, teamId);
|
const monitor = await this.monitorsRepository.deleteById(monitorId, teamId);
|
||||||
await this.monitorStatsRepository.deleteByMonitorId(monitor.id).catch((err: any) => {
|
await this.monitorStatsRepository.deleteByMonitorId(monitor.id).catch((err: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error deleting monitor stats for monitor ${monitor.id} with name ${monitor.name}`,
|
message: `Error deleting monitor stats for monitor ${monitor.id} with name ${monitor.name}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
stack: err instanceof Error ? err.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await this.checksRepository.deleteByMonitorId(monitor.id).catch((err: any) => {
|
await this.checksRepository.deleteByMonitorId(monitor.id).catch((err: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error deleting checks for monitor ${monitor.id} with name ${monitor.name}`,
|
message: `Error deleting checks for monitor ${monitor.id} with name ${monitor.name}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
stack: err instanceof Error ? err.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await this.statusPagesRepository.removeMonitorFromStatusPages(monitor.id).catch((err: any) => {
|
await this.statusPagesRepository.removeMonitorFromStatusPages(monitor.id).catch((err: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error removing monitor ${monitor.id} with name ${monitor.name} from status pages`,
|
message: `Error removing monitor ${monitor.id} with name ${monitor.name} from status pages`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
stack: err instanceof Error ? err.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.incidentsRepository.deleteByMonitorId(monitor.id, teamId).catch((err: any) => {
|
await this.incidentsRepository.deleteByMonitorId(monitor.id, teamId).catch((err: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error deleting incidents for monitor ${monitor.id} with name ${monitor.name}`,
|
message: `Error deleting incidents for monitor ${monitor.id} with name ${monitor.name}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
stack: err instanceof Error ? err.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.geoChecksRepository.deleteByMonitorId(monitor.id).catch((err: any) => {
|
await this.geoChecksRepository.deleteByMonitorId(monitor.id).catch((err: unknown) => {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error deleting geo checks for monitor ${monitor.id} with name ${monitor.name}`,
|
message: `Error deleting geo checks for monitor ${monitor.id} with name ${monitor.name}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
stack: err.stack,
|
stack: err instanceof Error ? err.stack : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -495,12 +503,12 @@ export class MonitorService implements IMonitorService {
|
|||||||
await this.geoChecksRepository.deleteByMonitorId(monitor.id);
|
await this.geoChecksRepository.deleteByMonitorId(monitor.id);
|
||||||
await this.statusPagesRepository.removeMonitorFromStatusPages(monitor.id);
|
await this.statusPagesRepository.removeMonitorFromStatusPages(monitor.id);
|
||||||
await this.monitorStatsRepository.deleteByMonitorId(monitor.id);
|
await this.monitorStatsRepository.deleteByMonitorId(monitor.id);
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: `Error deleting associated records for monitor ${monitor.id} with name ${monitor.name}`,
|
message: `Error deleting associated records for monitor ${monitor.id} with name ${monitor.name}`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "deleteAllMonitors",
|
method: "deleteAllMonitors",
|
||||||
stack: error.stack,
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -508,7 +516,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
return deletedCount;
|
return deletedCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
exportMonitorsToJSON = async ({ teamId }: { teamId: string }): Promise<any[]> => {
|
exportMonitorsToJSON = async ({ teamId }: { teamId: string }): Promise<Monitor[]> => {
|
||||||
const monitors = await this.monitorsRepository.findByTeamId(teamId, {});
|
const monitors = await this.monitorsRepository.findByTeamId(teamId, {});
|
||||||
|
|
||||||
if (!monitors || monitors.length === 0) {
|
if (!monitors || monitors.length === 0) {
|
||||||
@@ -525,23 +533,21 @@ export class MonitorService implements IMonitorService {
|
|||||||
}: {
|
}: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
monitors: any[];
|
monitors: ImportedMonitor[];
|
||||||
}): Promise<{ imported: number; errors: string[] }> => {
|
}): Promise<{ imported: number; errors: string[] }> => {
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
const cleanedMonitors = monitors.map((monitor) => {
|
const cleanedMonitors: Monitor[] = monitors.map((monitor) => ({
|
||||||
const cleanData = { ...monitor };
|
...monitor,
|
||||||
delete cleanData.id;
|
id: "",
|
||||||
delete cleanData._id;
|
teamId,
|
||||||
delete cleanData.createdAt;
|
userId,
|
||||||
delete cleanData.updatedAt;
|
recentChecks: [],
|
||||||
delete cleanData.recentChecks;
|
createdAt: "",
|
||||||
// Monitors must belong to current team
|
updatedAt: "",
|
||||||
cleanData.teamId = teamId;
|
}));
|
||||||
return cleanData;
|
|
||||||
});
|
|
||||||
|
|
||||||
const createdMonitors = await this.createMonitors(cleanedMonitors, userId, teamId);
|
const createdMonitors = await this.createMonitors(cleanedMonitors);
|
||||||
|
|
||||||
if (!createdMonitors || createdMonitors.length === 0) {
|
if (!createdMonitors || createdMonitors.length === 0) {
|
||||||
throw new AppError({
|
throw new AppError({
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { CheckSnapshot } from "@/types/check.js";
|
import type { CheckSnapshot } from "@/types/check.js";
|
||||||
export type { CheckSnapshot } from "@/types/check.js";
|
export type { CheckSnapshot } from "@/types/check.js";
|
||||||
import type { GeoContinent } from "@/types/geoCheck.js";
|
import type { GeoContinent, GroupedGeoCheck } from "@/types/geoCheck.js";
|
||||||
export type { GeoContinent } from "@/types/geoCheck.js";
|
export type { GeoContinent } from "@/types/geoCheck.js";
|
||||||
|
|
||||||
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "websocket", "unknown"] as const;
|
export const MonitorTypes = ["http", "ping", "pagespeed", "hardware", "docker", "port", "game", "grpc", "websocket", "unknown"] as const;
|
||||||
@@ -74,6 +74,10 @@ export interface MonitorsWithChecksByTeamIdResult {
|
|||||||
monitors: Monitor[];
|
monitors: Monitor[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GroupedGeoCheckResult {
|
||||||
|
groupedGeoChecks: GroupedGeoCheck[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface UptimeDetailsResult {
|
export interface UptimeDetailsResult {
|
||||||
monitorData: {
|
monitorData: {
|
||||||
monitor: Monitor;
|
monitor: Monitor;
|
||||||
|
|||||||
@@ -128,39 +128,38 @@ const importedMonitorSchema = z.object({
|
|||||||
teamId: z.string().optional(),
|
teamId: z.string().optional(),
|
||||||
name: z.string().min(1, "Name is required"),
|
name: z.string().min(1, "Name is required"),
|
||||||
description: z.union([z.string(), z.literal("")]).optional(),
|
description: z.union([z.string(), z.literal("")]).optional(),
|
||||||
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).optional(),
|
status: z.enum(["up", "down", "paused", "initializing", "maintenance", "breached"]).default("initializing"),
|
||||||
statusWindow: z.array(z.boolean()).optional(),
|
statusWindow: z.array(z.boolean()).default([]),
|
||||||
statusWindowSize: z.number().optional(),
|
statusWindowSize: z.number().min(1).max(20).default(5),
|
||||||
statusWindowThreshold: z.number().optional(),
|
statusWindowThreshold: z.number().min(1).max(100).default(60),
|
||||||
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
type: z.enum(MonitorTypes, "Invalid monitor type"),
|
||||||
ignoreTlsErrors: z.boolean().optional(),
|
ignoreTlsErrors: z.boolean().default(false),
|
||||||
useAdvancedMatching: z.boolean().optional(),
|
useAdvancedMatching: z.boolean().default(false),
|
||||||
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
jsonPath: z.union([z.string(), z.literal("")]).optional(),
|
||||||
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
expectedValue: z.union([z.string(), z.literal("")]).optional(),
|
||||||
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
matchMethod: z.union([z.enum(MonitorMatchMethods), z.literal("")]).optional(),
|
||||||
url: z.string().min(1, "URL is required"),
|
url: z.string().min(1, "URL is required"),
|
||||||
port: z.number().optional(),
|
port: z.number().optional(),
|
||||||
isActive: z.boolean().optional(),
|
isActive: z.boolean().default(true),
|
||||||
interval: z.number().optional(),
|
interval: z.number().default(60000),
|
||||||
uptimePercentage: z.number().optional(),
|
uptimePercentage: z.number().optional(),
|
||||||
notifications: z.array(z.string()).optional(),
|
notifications: z.array(z.string()).default([]),
|
||||||
secret: z.string().optional(),
|
secret: z.string().optional(),
|
||||||
cpuAlertThreshold: z.number().optional(),
|
cpuAlertThreshold: z.number().default(100),
|
||||||
cpuAlertCounter: z.number().optional(),
|
cpuAlertCounter: z.number().default(5),
|
||||||
memoryAlertThreshold: z.number().optional(),
|
memoryAlertThreshold: z.number().default(100),
|
||||||
memoryAlertCounter: z.number().optional(),
|
memoryAlertCounter: z.number().default(5),
|
||||||
diskAlertThreshold: z.number().optional(),
|
diskAlertThreshold: z.number().default(100),
|
||||||
diskAlertCounter: z.number().optional(),
|
diskAlertCounter: z.number().default(5),
|
||||||
tempAlertThreshold: z.number().optional(),
|
tempAlertThreshold: z.number().default(100),
|
||||||
tempAlertCounter: z.number().optional(),
|
tempAlertCounter: z.number().default(5),
|
||||||
selectedDisks: z.array(z.string()).optional(),
|
selectedDisks: z.array(z.string()).default([]),
|
||||||
gameId: z.union([z.string(), z.literal("")]).optional(),
|
gameId: z.union([z.string(), z.literal("")]).optional(),
|
||||||
grpcServiceName: z.union([z.string(), z.literal("")]).optional(),
|
grpcServiceName: z.union([z.string(), z.literal("")]).default(""),
|
||||||
group: z.union([z.string(), z.null()]).optional(),
|
group: z.union([z.string().max(50).trim(), z.null()]).default(null),
|
||||||
geoCheckEnabled: z.boolean().optional(),
|
geoCheckEnabled: z.boolean().default(false),
|
||||||
geoCheckLocations: z.array(z.enum(GeoContinents)).optional(),
|
geoCheckLocations: z.array(z.enum(GeoContinents)).default([]),
|
||||||
geoCheckInterval: z.number().optional(),
|
geoCheckInterval: z.number().min(300000).default(300000),
|
||||||
recentChecks: z.array(z.unknown()).optional(),
|
|
||||||
createdAt: z.string().optional(),
|
createdAt: z.string().optional(),
|
||||||
updatedAt: z.string().optional(),
|
updatedAt: z.string().optional(),
|
||||||
});
|
});
|
||||||
@@ -169,6 +168,8 @@ export const importMonitorsBodyValidation = z.object({
|
|||||||
monitors: z.array(importedMonitorSchema).min(1, "At least one monitor is required"),
|
monitors: z.array(importedMonitorSchema).min(1, "At least one monitor is required"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type ImportedMonitor = z.output<typeof importedMonitorSchema>;
|
||||||
|
|
||||||
export const getHardwareDetailsByIdParamValidation = z.object({
|
export const getHardwareDetailsByIdParamValidation = z.object({
|
||||||
monitorId: z.string().min(1, "Monitor ID is required"),
|
monitorId: z.string().min(1, "Monitor ID is required"),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user