From 7528da2f000c62b2b04d275096fe8d2d0bb1bfdd Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Tue, 16 Dec 2025 15:37:16 +0700 Subject: [PATCH] Add scenarioName to run scenario actions and logs Pass scenarioName from frontend to backend when running scenarios, and include it in log titles, email subjects, and Zulip messages. Also, expand command matching in template utilities and update default '[ENTER]' handling in line_connection. Minor logging improvements included. --- BACKEND/app/services/line_connection.ts | 6 +++--- BACKEND/app/ultils/templates/index.ts | 4 ++++ BACKEND/providers/socket_io_provider.ts | 10 ++++++---- FRONTEND/src/components/ButtonAction.tsx | 1 + FRONTEND/src/components/Modal/ModalRunScenario.tsx | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 18cc89d..6747f0d 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -494,9 +494,9 @@ export default class LineConnection { } if (typeof step.send !== 'undefined') { - this.outputScenario += `\n---send-command---"${(step?.send ?? '').toString().replace(/\r/g, '\\r').replace(/\n/g, '\\n')}"---${now}---\n` + this.outputScenario += `\n---send-command---"${(step?.send ?? '[ENTER]').toString().replace(/\r/g, '\\r').replace(/\n/g, '\\n')}"---${now}---\n` appendLog( - `\n---send-command---"${(step?.send ?? '').toString().replace(/\r/g, '\\r').replace(/\n/g, '\\n')}"---${now}---\n`, + `\n---send-command---"${(step?.send ?? '[ENTER]').toString().replace(/\r/g, '\\r').replace(/\n/g, '\\n')}"---${now}---\n`, this.config.stationId, this.config.stationName, this.config.stationIp, @@ -578,7 +578,7 @@ export default class LineConnection { waitForExpect = async (expect: string, timeout = 60000) => { const start = Date.now() - console.log('[EXPECT]', expect, timeout) + // console.log('[EXPECT]', expect, timeout) while (Date.now() - start < timeout) { if (this.outputBuffer.includes(expect)) { this.outputBuffer = '' diff --git a/BACKEND/app/ultils/templates/index.ts b/BACKEND/app/ultils/templates/index.ts index ffc0920..efaa175 100644 --- a/BACKEND/app/ultils/templates/index.ts +++ b/BACKEND/app/ultils/templates/index.ts @@ -18,10 +18,14 @@ function getStructuredDataTextfsm(output: string, command: string) { case 'sh ver': return showVersion(output) case 'show license': + case 'show lic': case 'sh license': + case 'sh lic': return showLicense(output) case 'show logging': + case 'show log': case 'sh logging': + case 'sh log': return showLogging(output) default: return '' diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 1a7b670..767f4e0 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -558,9 +558,10 @@ export class WebSocketIo { const lineIds = data.lineIds const stationName = data.stationName || '' const stationId = data.stationId || '' + const scenarioName = data.scenarioName || '' const station = await Station.find(stationId) // Check station sendWiki flag - console.log('[DPELP] Received run all dpelp', station?.send_wiki) + console.log('[DPELP] Received run all dpelp', lineIds) if (!station || !station?.send_wiki) return const results = await this.waitUntilAllReady(lineIds) @@ -574,11 +575,11 @@ export class WebSocketIo { process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test' await axios.post(linkWiki, { data: tableHTML, - titleAuto: `[DPELP] - ${stationName} - ` + dataFormat, + titleAuto: `[${scenarioName || 'DPELP'}] - ${stationName} - ` + dataFormat, }) await sendMessageToMail( 'andrew.ng@apactech.io', - `[DPELP] - ${stationName} - ${dataFormat}`, + `[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}`, tableHTML, ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io'] ) @@ -586,7 +587,8 @@ export class WebSocketIo { 'stream', 'ATC_Report', station.name, - `\n\n---\n**[DPELP] - ${stationName} - ${dataFormat}**\n\n` + zulipMess + `\n\n---\n**[${scenarioName || 'DPELP'}] - ${stationName} - ${dataFormat}**\n\n` + + zulipMess ) } catch (error) { console.log(error) diff --git a/FRONTEND/src/components/ButtonAction.tsx b/FRONTEND/src/components/ButtonAction.tsx index 7e56fac..63d5158 100644 --- a/FRONTEND/src/components/ButtonAction.tsx +++ b/FRONTEND/src/components/ButtonAction.tsx @@ -233,6 +233,7 @@ export const ButtonScenario = ({ lineIds: selectedLines?.map((el) => el.id), stationName: station?.name, stationId: Number(station?.id), + scenarioName: scenario.title, }); selectedLines?.forEach((el) => { socket?.emit( diff --git a/FRONTEND/src/components/Modal/ModalRunScenario.tsx b/FRONTEND/src/components/Modal/ModalRunScenario.tsx index e5aed44..2d65add 100644 --- a/FRONTEND/src/components/Modal/ModalRunScenario.tsx +++ b/FRONTEND/src/components/Modal/ModalRunScenario.tsx @@ -496,6 +496,7 @@ const ModalRunScenario = ({ lineIds: selectedLines?.map((el) => el.id), stationName: station.name, stationId: Number(station.id), + scenarioName: scenario.title, }); selectedLines