mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Implemented Probe registration endpoint to handle global probes. - Created Server Monitor ingestion API with endpoints for secret key verification and response ingestion. - Developed job processing functions for incoming request and probe ingestion. - Added middleware for probe authorization and request type definitions. - Enhanced monitor utility functions to populate secrets in monitor steps. - Introduced queue stats and failed jobs endpoints for server monitor.
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { ProbeExpressRequest } from "../Types/Request";
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
import { JSONObject } from "Common/Types/JSON";
|
|
import ObjectID from "Common/Types/ObjectID";
|
|
import ProbeService from "Common/Server/Services/ProbeService";
|
|
import { ExpressResponse, NextFunction } from "Common/Server/Utils/Express";
|
|
import Response from "Common/Server/Utils/Response";
|
|
import Probe from "Common/Models/DatabaseModels/Probe";
|
|
|
|
export default class ProbeAuthorization {
|
|
public static async isAuthorizedServiceMiddleware(
|
|
req: ProbeExpressRequest,
|
|
res: ExpressResponse,
|
|
next: NextFunction,
|
|
): Promise<void> {
|
|
const data: JSONObject = req.body;
|
|
|
|
if (!data["probeId"] || !data["probeKey"]) {
|
|
return Response.sendErrorResponse(
|
|
req,
|
|
res,
|
|
new BadDataException("ProbeId or ProbeKey is missing"),
|
|
);
|
|
}
|
|
|
|
const probeId: ObjectID = new ObjectID(data["probeId"] as string);
|
|
|
|
const probeKey: string = data["probeKey"] as string;
|
|
|
|
const probe: Probe | null = await ProbeService.findOneBy({
|
|
query: {
|
|
_id: probeId.toString(),
|
|
key: probeKey,
|
|
},
|
|
select: {
|
|
_id: true,
|
|
},
|
|
props: {
|
|
isRoot: true,
|
|
},
|
|
});
|
|
|
|
if (!probe) {
|
|
return Response.sendErrorResponse(
|
|
req,
|
|
res,
|
|
new BadDataException("Invalid Probe ID or Probe Key"),
|
|
);
|
|
}
|
|
|
|
await ProbeService.updateLastAlive(probeId);
|
|
|
|
req.probe = probe;
|
|
|
|
return next();
|
|
}
|
|
}
|