Fix jwt-token
This commit is contained in:
@@ -273,7 +273,7 @@ class AlertService {
|
|||||||
console.log(`✅ Rule "${rule.name}": No device filter (applies to all devices)`);
|
console.log(`✅ Rule "${rule.name}": No device filter (applies to all devices)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIORITY 2: Cooldown period check (applies even to critical threats for the same device)
|
// PRIORITY 2: Cooldown period check (applies even to critical threats for the same device+drone combination)
|
||||||
if (rule.cooldown_period > 0) {
|
if (rule.cooldown_period > 0) {
|
||||||
const cooldownStart = new Date(Date.now() - rule.cooldown_period * 1000);
|
const cooldownStart = new Date(Date.now() - rule.cooldown_period * 1000);
|
||||||
|
|
||||||
@@ -289,29 +289,32 @@ class AlertService {
|
|||||||
include: [{
|
include: [{
|
||||||
model: DroneDetection,
|
model: DroneDetection,
|
||||||
as: 'detection',
|
as: 'detection',
|
||||||
attributes: ['device_id'],
|
attributes: ['device_id', 'drone_id'],
|
||||||
required: false // Allow alerts without detection_id (like device offline alerts)
|
required: false // Allow alerts without detection_id (like device offline alerts)
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if any recent alert was for the same device
|
// Check if any recent alert was for the same device AND same drone
|
||||||
const deviceAlert = recentAlerts.find(alert => {
|
const deviceDroneAlert = recentAlerts.find(alert => {
|
||||||
// For alerts with detection, check device_id match
|
// For alerts with detection, check both device_id AND drone_id match
|
||||||
if (alert.detection && alert.detection.device_id === detection.device_id) {
|
if (alert.detection &&
|
||||||
|
alert.detection.device_id === detection.device_id &&
|
||||||
|
alert.detection.drone_id === detection.drone_id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// For alerts without detection (like device offline), check device_id field directly
|
// For alerts without detection (like device offline), check device_id field directly
|
||||||
|
// These don't have drone_id so they follow device-level cooldown
|
||||||
if (!alert.detection && alert.device_id === detection.device_id) {
|
if (!alert.detection && alert.device_id === detection.device_id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (deviceAlert) {
|
if (deviceDroneAlert) {
|
||||||
console.log(`❌ Rule "${rule.name}": Still in cooldown period for device ${detection.device_id} (last alert: ${deviceAlert.sent_at})`);
|
console.log(`❌ Rule "${rule.name}": Still in cooldown period for device ${detection.device_id} + drone ${detection.drone_id} (last alert: ${deviceDroneAlert.sent_at})`);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
console.log(`✅ Rule "${rule.name}": Cooldown period expired or no recent alerts for device ${detection.device_id}`);
|
console.log(`✅ Rule "${rule.name}": Cooldown period expired or no recent alerts for device ${detection.device_id} + drone ${detection.drone_id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user