Refactor ProbeMonitorResponse and TelemetryIngest middleware

This commit is contained in:
Simon Larsen 2024-03-11 12:29:00 +00:00
parent 15f5cd540c
commit f03f4c67eb
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
2 changed files with 20 additions and 3 deletions

View File

@ -913,20 +913,36 @@ export default class ProbeMonitorResponseService {
return null; // if true then return null.
}
if (input.monitor.monitorType === MonitorType.Server) {
if (input.monitor.monitorType === MonitorType.Server && (input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt) {
const lastCheckTime: Date = (
input.dataToProcess as ServerMonitorResponse
).requestReceivedAt;
const differenceInMinutes: number =
OneUptimeDate.getDifferenceInMinutes(
lastCheckTime,
OneUptimeDate.getCurrentDate()
);
const offlineIfNotCheckedInMinutes: number = 2;
if (
input.criteriaFilter.checkOn === CheckOn.IsOnline &&
input.criteriaFilter.filterType === FilterType.True
input.criteriaFilter.filterType === FilterType.True && differenceInMinutes <= offlineIfNotCheckedInMinutes
) {
if ((input.dataToProcess as ProbeMonitorResponse).isOnline) {
return 'Monitor is online.';
}
return null;
}
if (
input.criteriaFilter.checkOn === CheckOn.IsOnline &&
input.criteriaFilter.filterType === FilterType.False
input.criteriaFilter.filterType === FilterType.False && differenceInMinutes > offlineIfNotCheckedInMinutes
) {
if (!(input.dataToProcess as ProbeMonitorResponse).isOnline) {
return 'Monitor is offline.';

View File

@ -50,6 +50,7 @@ export default class TelemetryIngest {
'service-token',
serviceTokenInHeader as string
);
const serviceProjectId: string | null = await GlobalCache.getString(
'service-project-id',
serviceTokenInHeader as string