From f03f4c67eb9fed5eb0cc086d2e480b908c70c6a5 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 11 Mar 2024 12:29:00 +0000 Subject: [PATCH] Refactor ProbeMonitorResponse and TelemetryIngest middleware --- .../Utils/Probe/ProbeMonitorResponse.ts | 22 ++++++++++++++++--- Ingestor/Middleware/TelemetryIngest.ts | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts b/CommonServer/Utils/Probe/ProbeMonitorResponse.ts index 7a20769ba4..663412f487 100644 --- a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts +++ b/CommonServer/Utils/Probe/ProbeMonitorResponse.ts @@ -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.'; diff --git a/Ingestor/Middleware/TelemetryIngest.ts b/Ingestor/Middleware/TelemetryIngest.ts index bb2d2610d7..2ecf3830c0 100644 --- a/Ingestor/Middleware/TelemetryIngest.ts +++ b/Ingestor/Middleware/TelemetryIngest.ts @@ -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