mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 14:49:07 +00:00
Add secret keys for server and incoming request monitors
This commit is contained in:
parent
6fbb5948fb
commit
75f22b4bee
@ -0,0 +1,6 @@
|
||||
import ObjectID from '../../ObjectID';
|
||||
|
||||
export default interface ServerMonitorRequest {
|
||||
monitorId: ObjectID;
|
||||
secretKey: ObjectID;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import BasicInfrastructureMetrics from "../../Infrastrucutre/BasicMetrics";
|
||||
import ObjectID from "../../ObjectID";
|
||||
|
||||
export interface ServerMonitorResponse {
|
||||
monitorId: ObjectID;
|
||||
secretKey: ObjectID;
|
||||
basicInfrastructureMetrics: BasicInfrastructureMetrics
|
||||
}
|
@ -91,10 +91,20 @@ export class Service extends DatabaseService<Model> {
|
||||
);
|
||||
}
|
||||
|
||||
if(createBy.data.monitorType === MonitorType.Server) {
|
||||
createBy.data.serverMonitorSecretKey = ObjectID.generate();
|
||||
}
|
||||
|
||||
if(createBy.data.monitorType === MonitorType.IncomingRequest) {
|
||||
createBy.data.incomingRequestSecretKey = ObjectID.generate();
|
||||
}
|
||||
|
||||
if (!createBy.props.tenantId) {
|
||||
throw new BadDataException('ProjectId required to create monitor.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
const monitorStatus: MonitorStatus | null =
|
||||
await MonitorStatusService.findOneBy({
|
||||
query: {
|
||||
|
78
Ingestor/API/ServerMonitor.ts
Normal file
78
Ingestor/API/ServerMonitor.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import Express, {
|
||||
ExpressRequest,
|
||||
ExpressResponse,
|
||||
ExpressRouter,
|
||||
NextFunction,
|
||||
RequestHandler,
|
||||
} from 'CommonServer/Utils/Express';
|
||||
import Response from 'CommonServer/Utils/Response';
|
||||
import BadDataException from 'Common/Types/Exception/BadDataException';
|
||||
import ProbeMonitorResponseService from 'CommonServer/Utils/Probe/ProbeMonitorResponse';
|
||||
import Dictionary from 'Common/Types/Dictionary';
|
||||
import { JSONObject } from 'Common/Types/JSON';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import IncomingMonitorRequest from 'Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest';
|
||||
import OneUptimeDate from 'Common/Types/Date';
|
||||
|
||||
const router: ExpressRouter = Express.getRouter();
|
||||
|
||||
const processServerMonitor: RequestHandler = async (
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
next: NextFunction
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const requestHeaders: Dictionary<string> =
|
||||
req.headers as Dictionary<string>;
|
||||
const requestBody: string | JSONObject = req.body as
|
||||
| string
|
||||
| JSONObject;
|
||||
|
||||
const monitorSecretKeyAsString: string | undefined = req.params['secretkey'];
|
||||
|
||||
if (!monitorSecretKeyAsString) {
|
||||
throw new BadDataException('Monitor Secret Key is required');
|
||||
}
|
||||
|
||||
const monitorId: ObjectID = ObjectID.fromString(monitorSecretKeyAsString);
|
||||
|
||||
const serverMonitorRequest: ServerMonitorRequest = {
|
||||
monitorId: monitorId,
|
||||
requestHeaders: requestHeaders,
|
||||
requestBody: requestBody,
|
||||
incomingRequestReceivedAt: OneUptimeDate.getCurrentDate(),
|
||||
onlyCheckForIncomingRequestReceivedAt: false,
|
||||
};
|
||||
|
||||
// process probe response here.
|
||||
await ProbeMonitorResponseService.processProbeResponse(incomingRequest);
|
||||
|
||||
return Response.sendEmptyResponse(req, res);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
};
|
||||
|
||||
router.get(
|
||||
'/server-monitor/:secretkey',
|
||||
async (
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
next: NextFunction
|
||||
): Promise<void> => {
|
||||
processServerMonitor(req, res, next);
|
||||
}
|
||||
);
|
||||
|
||||
router.post(
|
||||
'/server-monitor/response/ingest',
|
||||
async (
|
||||
req: ExpressRequest,
|
||||
res: ExpressResponse,
|
||||
next: NextFunction
|
||||
): Promise<void> => {
|
||||
processServerMonitor(req, res, next);
|
||||
}
|
||||
);
|
||||
|
||||
export default router;
|
@ -761,4 +761,115 @@ export default class Monitor extends BaseModel {
|
||||
default: false,
|
||||
})
|
||||
public disableActiveMonitoringBecauseOfManualIncident?: boolean = undefined;
|
||||
|
||||
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanReadProjectMonitor,
|
||||
],
|
||||
update: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
})
|
||||
@Index()
|
||||
@TableColumn({
|
||||
type: TableColumnType.Date,
|
||||
required: false,
|
||||
isDefaultValueColumn: false,
|
||||
title: 'Server Monitor Request Received At',
|
||||
description:
|
||||
'This field is for Server Monitor only. When was the last time we received a request?',
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.Date,
|
||||
nullable: true,
|
||||
})
|
||||
public serverMonitorRequestReceivedAt?: Date = undefined;
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanReadProjectMonitor,
|
||||
],
|
||||
update: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
})
|
||||
@Index()
|
||||
@TableColumn({
|
||||
type: TableColumnType.ObjectID,
|
||||
required: false,
|
||||
isDefaultValueColumn: false,
|
||||
title: 'Server Monitor Secret Key',
|
||||
description:
|
||||
'This field is for Server Monitor only. Secret Key to authenticate the request.',
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
transformer: ObjectID.getDatabaseTransformer(),
|
||||
})
|
||||
public serverMonitorSecretKey?: ObjectID = undefined;
|
||||
|
||||
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanReadProjectMonitor,
|
||||
],
|
||||
update: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanCreateProjectMonitor,
|
||||
],
|
||||
})
|
||||
@Index()
|
||||
@TableColumn({
|
||||
type: TableColumnType.ObjectID,
|
||||
required: false,
|
||||
isDefaultValueColumn: false,
|
||||
title: 'Incoming Request Secret Key',
|
||||
description:
|
||||
'This field is for Incoming Request Monitor only. Secret Key to authenticate the request.',
|
||||
})
|
||||
@Column({
|
||||
type: ColumnType.ObjectID,
|
||||
nullable: true,
|
||||
transformer: ObjectID.getDatabaseTransformer(),
|
||||
})
|
||||
public incomingRequestSecretKey?: ObjectID = undefined;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user