Fix jwt-token
This commit is contained in:
@@ -826,7 +826,7 @@ class AlertService {
|
|||||||
|
|
||||||
return await AlertLog.create({
|
return await AlertLog.create({
|
||||||
alert_rule_id: rule.id,
|
alert_rule_id: rule.id,
|
||||||
detection_id: detection.id,
|
detection_id: detection ? detection.id : null,
|
||||||
alert_type: 'webhook',
|
alert_type: 'webhook',
|
||||||
recipient: webhookUrl,
|
recipient: webhookUrl,
|
||||||
message: JSON.stringify(payload),
|
message: JSON.stringify(payload),
|
||||||
|
|||||||
@@ -246,11 +246,53 @@ class DeviceHealthService {
|
|||||||
}
|
}
|
||||||
} catch (channelError) {
|
} catch (channelError) {
|
||||||
console.error(`❌ Failed to send ${channel} alert for offline device ${device.id}:`, channelError);
|
console.error(`❌ Failed to send ${channel} alert for offline device ${device.id}:`, channelError);
|
||||||
|
|
||||||
|
// Log the failed alert attempt to alert logs for audit purposes
|
||||||
|
try {
|
||||||
|
const AlertLog = require('../models/AlertLog');
|
||||||
|
await AlertLog.create({
|
||||||
|
alert_rule_id: rule ? rule.id : null,
|
||||||
|
detection_id: null,
|
||||||
|
alert_type: channel,
|
||||||
|
recipient: channel === 'sms' ? rule?.sms_phone_number :
|
||||||
|
channel === 'email' ? (rule?.email || rule?.user?.email) :
|
||||||
|
channel === 'webhook' ? rule?.webhook_url : 'unknown',
|
||||||
|
message: `Device offline alert failed for ${device.name}`,
|
||||||
|
status: 'failed',
|
||||||
|
sent_at: new Date(),
|
||||||
|
external_id: null,
|
||||||
|
priority: rule?.priority || 'medium',
|
||||||
|
error_message: `Device health service error: ${channelError.message}`,
|
||||||
|
alert_event_id: null
|
||||||
|
});
|
||||||
|
} catch (logError) {
|
||||||
|
console.error(`❌ Failed to log alert failure:`, logError.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Error triggering offline alert for device ${device.id}:`, error);
|
console.error(`❌ Error triggering offline alert for device ${device.id}:`, error);
|
||||||
|
|
||||||
|
// Log the general failure to alert logs for audit purposes
|
||||||
|
try {
|
||||||
|
const AlertLog = require('../models/AlertLog');
|
||||||
|
await AlertLog.create({
|
||||||
|
alert_rule_id: rule ? rule.id : null,
|
||||||
|
detection_id: null,
|
||||||
|
alert_type: 'system',
|
||||||
|
recipient: 'system',
|
||||||
|
message: `Failed to process device offline alert for ${device.name}`,
|
||||||
|
status: 'failed',
|
||||||
|
sent_at: new Date(),
|
||||||
|
external_id: null,
|
||||||
|
priority: 'high',
|
||||||
|
error_message: `Device health service error: ${error.message}`,
|
||||||
|
alert_event_id: null
|
||||||
|
});
|
||||||
|
} catch (logError) {
|
||||||
|
console.error(`❌ Failed to log system alert failure:`, logError.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,11 +348,53 @@ class DeviceHealthService {
|
|||||||
}
|
}
|
||||||
} catch (channelError) {
|
} catch (channelError) {
|
||||||
console.error(`❌ Failed to send ${channel} recovery alert for device ${device.id}:`, channelError);
|
console.error(`❌ Failed to send ${channel} recovery alert for device ${device.id}:`, channelError);
|
||||||
|
|
||||||
|
// Log the failed alert attempt to alert logs for audit purposes
|
||||||
|
try {
|
||||||
|
const AlertLog = require('../models/AlertLog');
|
||||||
|
await AlertLog.create({
|
||||||
|
alert_rule_id: rule ? rule.id : null,
|
||||||
|
detection_id: null,
|
||||||
|
alert_type: channel,
|
||||||
|
recipient: channel === 'sms' ? rule?.sms_phone_number :
|
||||||
|
channel === 'email' ? (rule?.email || rule?.user?.email) :
|
||||||
|
channel === 'webhook' ? rule?.webhook_url : 'unknown',
|
||||||
|
message: `Device recovery alert failed for ${device.name}`,
|
||||||
|
status: 'failed',
|
||||||
|
sent_at: new Date(),
|
||||||
|
external_id: null,
|
||||||
|
priority: rule?.priority || 'medium',
|
||||||
|
error_message: `Device health service recovery error: ${channelError.message}`,
|
||||||
|
alert_event_id: null
|
||||||
|
});
|
||||||
|
} catch (logError) {
|
||||||
|
console.error(`❌ Failed to log recovery alert failure:`, logError.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`❌ Error triggering recovery alert for device ${device.id}:`, error);
|
console.error(`❌ Error triggering recovery alert for device ${device.id}:`, error);
|
||||||
|
|
||||||
|
// Log the general failure to alert logs for audit purposes
|
||||||
|
try {
|
||||||
|
const AlertLog = require('../models/AlertLog');
|
||||||
|
await AlertLog.create({
|
||||||
|
alert_rule_id: rule ? rule.id : null,
|
||||||
|
detection_id: null,
|
||||||
|
alert_type: 'system',
|
||||||
|
recipient: 'system',
|
||||||
|
message: `Failed to process device recovery alert for ${device.name}`,
|
||||||
|
status: 'failed',
|
||||||
|
sent_at: new Date(),
|
||||||
|
external_id: null,
|
||||||
|
priority: 'high',
|
||||||
|
error_message: `Device health service recovery error: ${error.message}`,
|
||||||
|
alert_event_id: null
|
||||||
|
});
|
||||||
|
} catch (logError) {
|
||||||
|
console.error(`❌ Failed to log system recovery alert failure:`, logError.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user