mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
- Implemented MonitorUtil for managing monitor secrets and populating them in monitor steps and tests. - Created StackTraceParser to parse and structure stack traces from various programming languages. - Developed SyslogParser to handle and parse syslog messages in both RFC 5424 and RFC 3164 formats.
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import { IncomingRequestIngestJobData } from "../../Services/Queue/TelemetryQueueService";
|
|
import logger from "Common/Server/Utils/Logger";
|
|
import HTTPMethod from "Common/Types/API/HTTPMethod";
|
|
import OneUptimeDate from "Common/Types/Date";
|
|
import Dictionary from "Common/Types/Dictionary";
|
|
import BadDataException from "Common/Types/Exception/BadDataException";
|
|
import ExceptionMessages from "Common/Types/Exception/ExceptionMessages";
|
|
import { JSONObject } from "Common/Types/JSON";
|
|
import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest";
|
|
import MonitorType from "Common/Types/Monitor/MonitorType";
|
|
import ObjectID from "Common/Types/ObjectID";
|
|
import MonitorService from "Common/Server/Services/MonitorService";
|
|
import MonitorResourceUtil from "Common/Server/Utils/Monitor/MonitorResource";
|
|
import Monitor from "Common/Models/DatabaseModels/Monitor";
|
|
|
|
export async function processIncomingRequestFromQueue(
|
|
jobData: IncomingRequestIngestJobData,
|
|
): Promise<void> {
|
|
const requestHeaders: Dictionary<string> = jobData.requestHeaders;
|
|
const requestBody: string | JSONObject = jobData.requestBody;
|
|
const monitorSecretKeyAsString: string = jobData.secretKey;
|
|
|
|
if (!monitorSecretKeyAsString) {
|
|
throw new BadDataException("Invalid Secret Key");
|
|
}
|
|
|
|
const isGetRequest: boolean = jobData.requestMethod === "GET";
|
|
const isPostRequest: boolean = jobData.requestMethod === "POST";
|
|
|
|
let httpMethod: HTTPMethod = HTTPMethod.GET;
|
|
|
|
if (isGetRequest) {
|
|
httpMethod = HTTPMethod.GET;
|
|
}
|
|
|
|
if (isPostRequest) {
|
|
httpMethod = HTTPMethod.POST;
|
|
}
|
|
|
|
const monitor: Monitor | null = await MonitorService.findOneBy({
|
|
query: {
|
|
incomingRequestSecretKey: new ObjectID(monitorSecretKeyAsString),
|
|
monitorType: MonitorType.IncomingRequest,
|
|
},
|
|
select: {
|
|
_id: true,
|
|
projectId: true,
|
|
},
|
|
props: {
|
|
isRoot: true,
|
|
},
|
|
});
|
|
|
|
if (!monitor || !monitor._id) {
|
|
throw new BadDataException(ExceptionMessages.MonitorNotFound);
|
|
}
|
|
|
|
if (!monitor.projectId) {
|
|
throw new BadDataException("Project not found");
|
|
}
|
|
|
|
const now: Date = OneUptimeDate.getCurrentDate();
|
|
|
|
const incomingRequest: IncomingMonitorRequest = {
|
|
projectId: monitor.projectId,
|
|
monitorId: new ObjectID(monitor._id.toString()),
|
|
requestHeaders: requestHeaders,
|
|
requestBody: requestBody,
|
|
incomingRequestReceivedAt: now,
|
|
onlyCheckForIncomingRequestReceivedAt: false,
|
|
requestMethod: httpMethod,
|
|
checkedAt: now,
|
|
};
|
|
|
|
// process probe response here.
|
|
await MonitorResourceUtil.monitorResource(incomingRequest);
|
|
}
|
|
|
|
logger.debug("Incoming request ingest processing functions loaded");
|