Update template show env

This commit is contained in:
nguyentrungthat 2026-01-21 09:16:15 +07:00
parent e1f8e42112
commit 2222b79258
5 changed files with 102 additions and 11 deletions

View File

@ -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,

View File

@ -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 ''
}

View File

@ -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('^(?<NAME>[A-Z ]+?)\\s+is\\s+(?<STATE>.+)$'),
// 2. Dạng: FAN 1 is OK / POWER SUPPLY A is NOT PRESENT
XRegExp('^(?<TYPE>[A-Z ]+?)\\s+(?<NAME>[A-Z0-9]+)\\s+is\\s+(?<STATE>.+)$'),
// 3. Dạng bảng: Temp: Inlet Front Normal
XRegExp(
'^(?<TYPE>Temp|Fan|Voltage|Power):?\\s*(?<NAME>[^\\s]+)\\s+(?<LOCATION>[^\\s]+)\\s+(?<STATE>.+)$'
),
// 4. Dạng: Inlet Temperature Value: 27 Degree Celsius
XRegExp('^(?<TYPE>.*?Temperature).*?:\\s*(?<VALUE>.+)$'),
]
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

View File

@ -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 (
<Box>
<Modal
@ -804,12 +815,22 @@ const ModalTerminal = ({
: ""}
</Text>
</Flex>
<Flex>
<Box>
<Box>
<Text size="md" mr={"sm"} fw={"bold"}>
Sh env/module:
</Text>
<Text size="md">{""}</Text>
</Flex>
</Box>
<Box>
{findDataShowEnv()
? findDataShowEnv()?.map((v: TextTSMEnvironment, i) => (
<Text fz={"14.5px"} key={i}>
- {v.RAW}
</Text>
))
: ""}
</Box>
</Box>
<Flex>
<Text size="md" mr={"sm"} fw={"bold"}>
Mem/Flash:

View File

@ -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;