From 447ac39fc15e3a9de2b1c6b24471b8b393b4060f Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Tue, 9 Sep 2025 19:54:42 +0200 Subject: [PATCH] Fix jwt-token --- server/services/deviceHealthService.js | 32 +++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/server/services/deviceHealthService.js b/server/services/deviceHealthService.js index bb34ec0..ccbe0ee 100644 --- a/server/services/deviceHealthService.js +++ b/server/services/deviceHealthService.js @@ -124,30 +124,27 @@ class DeviceHealthService { async handleOfflineDevices(offlineDevices) { for (const device of offlineDevices) { try { - // Find all active alert rules that monitor device offline events + // Find all active alert rules that could apply to device offline events + // For now, we'll look for rules that monitor specific devices or all devices const deviceOfflineRules = await AlertRule.findAll({ where: { is_active: true, [Op.or]: [ - // Rules specifically for device offline monitoring - { conditions: { device_offline: true } }, - // Rules that include this specific device - { - [Op.and]: [ - { conditions: { device_ids: { [Op.contains]: [device.id] } } }, - { conditions: { device_offline: true } } - ] - } + // Rules that monitor all devices (device_ids is null) + { device_ids: null }, + // Rules that specifically include this device + { device_ids: { [Op.contains]: [device.id] } } ] } }); if (deviceOfflineRules.length === 0) { - console.log(`⚠️ No offline alert rules configured for device ${device.id} (${device.name})`); + console.log(`⚠️ No alert rules configured for device ${device.id} (${device.name})`); continue; } - // Trigger alerts for each matching rule + // For device offline events, we'll create a special alert + // since the current AlertRule model doesn't have specific device offline fields for (const rule of deviceOfflineRules) { await this.triggerDeviceOfflineAlert(rule, device); } @@ -171,13 +168,10 @@ class DeviceHealthService { where: { is_active: true, [Op.or]: [ - { conditions: { device_offline: true } }, - { - [Op.and]: [ - { conditions: { device_ids: { [Op.contains]: [device.id] } } }, - { conditions: { device_offline: true } } - ] - } + // Rules that monitor all devices (device_ids is null) + { device_ids: null }, + // Rules that specifically include this device + { device_ids: { [Op.contains]: [device.id] } } ] } });