diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 5fc5819..cb91eb1 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -388,6 +388,7 @@ export default class LineConnection { ) this.config.runningScenario = script?.title this.config.data = [] + this.outputScenario = '' this.socketIO.emit('running_scenario', { stationId: this.config.stationId, lineId: this.config.id, diff --git a/BACKEND/app/ultils/templates/index.ts b/BACKEND/app/ultils/templates/index.ts index efaa175..6623e84 100644 --- a/BACKEND/app/ultils/templates/index.ts +++ b/BACKEND/app/ultils/templates/index.ts @@ -2,7 +2,7 @@ import showInventory from './show_inventory.js' import showVersion from './show_version.js' import showLicense from './show_license.js' import showLogging from './show_logging.js' -// const showPower = require("./show_power.js"); +import showEnv from './show_env.js' // Function to parse logs function getStructuredDataTextfsm(output: string, command: string) { @@ -27,6 +27,15 @@ function getStructuredDataTextfsm(output: string, command: string) { case 'sh logging': case 'sh log': return showLogging(output) + case 'show environment': + case 'show env': + case 'sh environment': + case 'sh env': + case 'show environment all': + case 'show env all': + case 'sh environment all': + case 'sh env all': + return showEnv(output) default: return '' } diff --git a/BACKEND/app/ultils/templates/show_env.ts b/BACKEND/app/ultils/templates/show_env.ts new file mode 100644 index 0000000..4f16811 --- /dev/null +++ b/BACKEND/app/ultils/templates/show_env.ts @@ -0,0 +1,51 @@ +import XRegExp from 'xregexp' + +const parseShowEnvironment = (data: string) => { + const patterns = [ + // 1. Dạng: FAN is OK / POWER is OK / RPS is NOT PRESENT + XRegExp('^(?[A-Z ]+?)\\s+is\\s+(?.+)$'), + + // 2. Dạng: FAN 1 is OK / POWER SUPPLY A is NOT PRESENT + XRegExp('^(?[A-Z ]+?)\\s+(?[A-Z0-9]+)\\s+is\\s+(?.+)$'), + + // 3. Dạng bảng: Temp: Inlet Front Normal + XRegExp( + '^(?Temp|Fan|Voltage|Power):?\\s*(?[^\\s]+)\\s+(?[^\\s]+)\\s+(?.+)$' + ), + + // 4. Dạng: Inlet Temperature Value: 27 Degree Celsius + XRegExp('^(?.*?Temperature).*?:\\s*(?.+)$'), + ] + + const lines = data.split('\n') + const records: any[] = [] + + for (let line of lines) { + line = line.trim() + if (!line) continue + + // Bỏ prompt + if (line.startsWith('Switch#')) continue + + for (const p of patterns) { + const m = XRegExp.exec(line, p) + if (m?.groups) { + const record: any = { + TYPE: m.groups.TYPE?.trim() || '', + NAME: m.groups.NAME?.trim() || '', + LOCATION: m.groups.LOCATION?.trim() || '', + STATE: m.groups.STATE?.trim() || '', + VALUE: m.groups.VALUE?.trim() || '', + RAW: line, + } + + records.push(record) + break + } + } + } + + return records +} + +export default parseShowEnvironment diff --git a/FRONTEND/src/components/Modal/ModalTerminal.tsx b/FRONTEND/src/components/Modal/ModalTerminal.tsx index 889d34d..62186af 100644 --- a/FRONTEND/src/components/Modal/ModalTerminal.tsx +++ b/FRONTEND/src/components/Modal/ModalTerminal.tsx @@ -23,6 +23,7 @@ import type { TCategories, TDataTicket, TextFSM, + TextTSMEnvironment, TextTSMLicense, THistoryTicket, TLine, @@ -466,16 +467,26 @@ const ModalTerminal = ({ const findDataShowLicense = () => { const showLicense = dataTextfsm?.find( (d) => - d.command?.trim() === "show license" || - d.command?.trim() === "sh license" || - d.command?.trim() === "show lic" || - d.command?.trim() === "sh lic" + d.command?.trim()?.includes("show lic") || + d.command?.trim()?.includes("sh lic") ); return showLicense?.textfsm && Array.isArray(showLicense?.textfsm) ? showLicense?.textfsm : null; }; + const findDataShowEnv = () => { + const showEnv = dataTextfsm?.find( + (d) => + d.command?.trim()?.includes("show env") || + d.command?.trim()?.includes("sh env") + ); + console.log("showEnv", showEnv); + return showEnv?.textfsm && Array.isArray(showEnv?.textfsm) + ? showEnv?.textfsm + : null; + }; + return ( - - - Sh env/module: - - {""} - + + + + Sh env/module: + + + + {findDataShowEnv() + ? findDataShowEnv()?.map((v: TextTSMEnvironment, i) => ( + + - {v.RAW} + + )) + : ""} + + Mem/Flash: diff --git a/FRONTEND/src/untils/types.ts b/FRONTEND/src/untils/types.ts index 265e5a1..59e88ed 100644 --- a/FRONTEND/src/untils/types.ts +++ b/FRONTEND/src/untils/types.ts @@ -255,6 +255,15 @@ export type TextTSMLicense = { LICENSE_PRIORITY: string; }; +export type TextTSMEnvironment = { + TYPE: string; + NAME: string; + LOCATION: string; + STATE: string; + VALUE: string; + RAW: string; +}; + export type TBrands = { id: number; name: string;