From 48a50b562827c1f99adf1fcf6b00b7159bf24308 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 23 Dec 2025 09:36:46 +0700 Subject: [PATCH] Improve log handling and email reporting Refactored log buffer management to use 'allBuffer' for complete log storage and updated email content to include raw logs. Enhanced log table formatting and removed status from email header. Commented out interface up/down rules in helper.ts to adjust log rule detection. --- BACKEND/app/services/line_connection.ts | 45 ++++++++++++------------- BACKEND/app/ultils/helper.ts | 36 ++++++++++---------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 0a07cf6..e2a5521 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -169,15 +169,15 @@ export default class LineConnection { lineNumber, status: 'connected', }) - // this.checkLog() + this.checkLog() resolve() }, 1000) }) this.client.on('data', (data) => { let message = this.connecting ? cleanData(data.toString()) : data.toString() - // const lines = this.bufferLog.push(data) - // lines.forEach(this.handleLogLine) + const lines = this.bufferLog.push(data) + lines.forEach(this.handleLogLine) let rawData = '' if (this.isRunningScript) { this.waitingScenario = true @@ -806,31 +806,31 @@ export default class LineConnection { try { if (this.config.status !== 'connected') { clearInterval(interval) + this.session.clear() + this.bufferLog.clear() return } const result = this.session.finalize() - if (result.errors.length === 0) return + if (result.errors.length === 0) { + this.session.clear() + this.bufferLog.clear() + return + } - // console.log('===== TEST RESULT =====') - // console.log('STATUS:', result.status) - // console.log('SUMMARY:', result.summary) - - // result.errors.forEach((err, idx) => { - // console.log(`\n[${idx + 1}] ${err.level} - ${err.ruleId}`) - // console.log('Message:', err.message) - // console.log('Log:', err.evidence.raw) - // }) - - const detectLog = await this.detectLogWithAI(this.bufferLog.buffer) + const detectLog = await this.detectLogWithAI(this.bufferLog.allBuffer) // console.log(detectLog) const tableHTML = this.buildEmailContent(result, detectLog) await sendMessageToMail( 'andrew.ng@apactech.io', - `[${result.status}] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Cisco Device Log Result`, - tableHTML - // , - // ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io'] + `[ATC] - [${this.config.stationName} - Line: ${this.config.lineNumber}] - Raw log issue`, + tableHTML + + `${` +
Logs:
+| Summary | Issues | @@ -902,7 +902,6 @@ export default class LineConnection { return `
|---|