From ffad475c2b3e486c4aeea6dd7cc71985157afd2e Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:19:24 +0700 Subject: [PATCH] =?UTF-8?q?Update=20format=20data=20g=E1=BB=ADi=20wiki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/app/services/line_connection.ts | 17 +++++-- BACKEND/app/ultils/helper.ts | 68 ++++++++++++++----------- BACKEND/providers/socket_io_provider.ts | 57 +++++++++++++++++++-- 3 files changed, 105 insertions(+), 37 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 13b8de3..00573a2 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -83,6 +83,17 @@ interface User { userName: string } +interface DataDPELP { + line: number + pid: any + vid: any + sn: any + mode: string + mac: string + license: any + issues: string[] +} + export default class LineConnection { public client: net.Socket public config: LineConfig @@ -94,7 +105,7 @@ export default class LineConnection { private outputInventory: string private outputScenario: string private bufferCommand: string - public dataDPELP: string + public dataDPELP: DataDPELP | string constructor(config: LineConfig, socketIO: any) { this.config = config @@ -696,12 +707,12 @@ export default class LineConnection { (Tóm tắt trạng thái tổng thể của hệ thống trong 2–4 ý) issue: - (Tóm tắt cực ngắn gọn các lỗi/dấu hiệu bất thường, mỗi vấn đề 1 dòng, bỏ qua các vấn đề không quan trọng như về port up/down hay Invalid input, Incomplete command) + (Tóm tắt cực ngắn gọn các lỗi/dấu hiệu bất thường, mỗi vấn đề 1 dòng, bỏ qua các vấn đề không quan trọng như về port changed state to up/down hay Invalid input, Incomplete command) Quy tắc: Không giải thích dài dòng. Chỉ tập trung vào lỗi, cảnh báo, thay đổi trạng thái up/down bất thường. - Nếu log không có lỗi → ghi rõ “Không phát hiện vấn đề”. + Nếu log không có lỗi → ghi rõ "No issues detected.". Ngắn gọn, dễ đọc, đúng format Return only json format with English`, diff --git a/BACKEND/app/ultils/helper.ts b/BACKEND/app/ultils/helper.ts index 9aa43b7..9646da5 100644 --- a/BACKEND/app/ultils/helper.ts +++ b/BACKEND/app/ultils/helper.ts @@ -137,53 +137,59 @@ export function isValidJson(string: string) { } } -export function mapToLineFormat(input: InputData): string { +export function mapToLineFormat(input: InputData) { const line = input.lineNumber - // Inventory info const pid = input.inventory?.pid || '' const vid = input.inventory?.vid || '' const sn = input.inventory?.sn || '' - if (!pid || !sn) return `Line ${line}: No data` + if (!pid || !sn) { + return { + line, + pid: '', + vid: '', + sn: '', + mode: '', + mac: '', + license: [], + issues: ['No data'], + } + } - // Find MAC address from "show version" or other sources + // MAC let mac = '' const showVersion = input.data?.find((d) => d.command === 'show version') if (showVersion?.textfsm?.[0]?.MAC_ADDRESS) { mac = showVersion.textfsm[0].MAC_ADDRESS } - // Get data license - const dataLicense = input.data?.find((comm: any) => comm.command?.trim() === 'show license') - const listLicense = - dataLicense?.textfsm && Array.isArray(dataLicense?.textfsm) - ? dataLicense?.textfsm?.map((val: any) => val.FEATURE).join(', ') + // License + const dataLicense = input.data?.find((comm) => comm.command?.trim() === 'show license') + const license = + dataLicense?.textfsm && Array.isArray(dataLicense.textfsm) + ? dataLicense.textfsm.map((v: any) => v.FEATURE) : '' + + // Mode (DPEL / DPELP) const dataPlatform = input.data?.find((el) => el.command?.trim() === 'show platform') - const DPELP = dataPlatform && !dataPlatform?.output?.includes('Incomplete') ? true : false + const mode = dataPlatform && !dataPlatform.output?.includes('Incomplete') ? 'DPELP' : 'DPEL' - // Detect AI issues - const issues = input.latestScenario?.detectAI?.issue || [] + // Issues + const issues = Array.isArray(input.latestScenario?.detectAI?.issue) + ? input.latestScenario.detectAI.issue + : input.latestScenario?.detectAI?.issue + ? [input.latestScenario.detectAI.issue] + : [] - // Build output - let output = `Line ${line}: ` - output += `PID: ${pid}, ` - output += `VID: ${vid}, ` - output += `SN: ${sn}, ` - output += `Tested mode: ${DPELP ? 'DPELP' : 'DPEL'}, ` - output += `${mac ? 'MAC Address:' + mac + `, ` : ''} ` - - output += `${listLicense ? 'License: ' + listLicense : ''}` - - if (Array.isArray(issues) && issues.length > 0) { - output += `\n Issues:\n` - for (const issue of issues) { - output += ` - ${issue}\n` - } - } else if (typeof issues === 'string') { - output += `\n Issues: ${issues}` + return { + line, + pid, + vid, + sn, + mode, + mac, + license, + issues, } - - return output.trim() } diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 7b16984..47c210b 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -538,6 +538,7 @@ export class WebSocketIo { console.log('[DPELP] Received run all dpelp') const results = await this.waitUntilAllReady(lineIds) + const tableHTML = this.generateTable(results) const d = new Date(Date.now()) const pad = (n: number) => String(n).padStart(2, '0') @@ -548,7 +549,7 @@ export class WebSocketIo { const linkWiki = process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' await axios.post(linkWiki, { - data: `
${results.join('\n\n')}\n`,
+ data: tableHTML,
titleAuto: 'AUTO - ' + dataFormat,
})
})
@@ -1026,10 +1027,10 @@ export class WebSocketIo {
}
async waitUntilAllReady(lineIds: number[]) {
- return new Promise| Line | +PID | +SN | +MAC | +Mode | +License | +Issues | +
|---|---|---|---|---|---|---|
| ${item.line} | +${item.pid} | ${item.vid} |
+ ${item.sn} | +${item.mac} | +${item.mode} | +${licenseHTML} | +${item.issues?.length ? `- ` + item.issues.join(` - `) : ''} |
+