Fix jwt-token
This commit is contained in:
@@ -124,30 +124,27 @@ class DeviceHealthService {
|
|||||||
async handleOfflineDevices(offlineDevices) {
|
async handleOfflineDevices(offlineDevices) {
|
||||||
for (const device of offlineDevices) {
|
for (const device of offlineDevices) {
|
||||||
try {
|
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({
|
const deviceOfflineRules = await AlertRule.findAll({
|
||||||
where: {
|
where: {
|
||||||
is_active: true,
|
is_active: true,
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
// Rules specifically for device offline monitoring
|
// Rules that monitor all devices (device_ids is null)
|
||||||
{ conditions: { device_offline: true } },
|
{ device_ids: null },
|
||||||
// Rules that include this specific device
|
// Rules that specifically include this device
|
||||||
{
|
{ device_ids: { [Op.contains]: [device.id] } }
|
||||||
[Op.and]: [
|
|
||||||
{ conditions: { device_ids: { [Op.contains]: [device.id] } } },
|
|
||||||
{ conditions: { device_offline: true } }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (deviceOfflineRules.length === 0) {
|
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;
|
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) {
|
for (const rule of deviceOfflineRules) {
|
||||||
await this.triggerDeviceOfflineAlert(rule, device);
|
await this.triggerDeviceOfflineAlert(rule, device);
|
||||||
}
|
}
|
||||||
@@ -171,13 +168,10 @@ class DeviceHealthService {
|
|||||||
where: {
|
where: {
|
||||||
is_active: true,
|
is_active: true,
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
{ conditions: { device_offline: true } },
|
// Rules that monitor all devices (device_ids is null)
|
||||||
{
|
{ device_ids: null },
|
||||||
[Op.and]: [
|
// Rules that specifically include this device
|
||||||
{ conditions: { device_ids: { [Op.contains]: [device.id] } } },
|
{ device_ids: { [Op.contains]: [device.id] } }
|
||||||
{ conditions: { device_offline: true } }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user