Update add log switch, apc

This commit is contained in:
nguyentrungthat 2025-12-11 09:00:58 +07:00
parent 2bc1338316
commit 117d982c4d
6 changed files with 61 additions and 13 deletions

View File

@ -9,6 +9,9 @@ interface APCOptions {
onData?: (data: string, status: string) => void onData?: (data: string, status: string) => void
number?: number number?: number
keep_connect?: boolean keep_connect?: boolean
stationId: number
stationName: string
stationIP: string
} }
interface PromptCallback { interface PromptCallback {
@ -29,8 +32,21 @@ class APCController {
private promptCallbacks: PromptCallback[] private promptCallbacks: PromptCallback[]
private onData: (data: string, status: string) => void private onData: (data: string, status: string) => void
private retryConnect: number private retryConnect: number
private stationId: number
private stationName: string
private stationIP: string
constructor({ host, port = 23, username, password, onData, number }: APCOptions) { constructor({
host,
port = 23,
username,
password,
onData,
number,
stationId,
stationName,
stationIP,
}: APCOptions) {
this.apc_number = number this.apc_number = number
this.apc_ip = host this.apc_ip = host
this.apc_port = port this.apc_port = port
@ -43,6 +59,9 @@ class APCController {
this.promptCallbacks = [] this.promptCallbacks = []
this.onData = onData || (() => {}) this.onData = onData || (() => {})
this.retryConnect = 0 this.retryConnect = 0
this.stationId = stationId
this.stationName = stationName
this.stationIP = stationIP
} }
private sleep(ms: number): Promise<void> { private sleep(ms: number): Promise<void> {
@ -101,7 +120,7 @@ class APCController {
this.buffer = '' this.buffer = ''
} }
} }
// appendLog(data, 0, 0, this.apc_number || 0) appendLog(data, this.stationId, this.stationName, this.stationIP, 'APC_' + this.apc_number)
} }
private _handleClose(): void { private _handleClose(): void {

View File

@ -592,6 +592,9 @@ export default class LineConnection {
port, port,
username, username,
password, password,
stationId: this.config.stationId,
stationName: this.config.stationName,
stationIP: this.config.stationIp,
number: this.config.lineNumber, number: this.config.lineNumber,
onData: (data: string, status: string) => { onData: (data: string, status: string) => {
this.config.output += data this.config.output += data

View File

@ -1,4 +1,5 @@
import net from 'node:net' import net from 'node:net'
import { appendLog } from '../ultils/helper.js'
type PromptCallback = { type PromptCallback = {
prompt: string prompt: string
@ -18,6 +19,9 @@ interface SwitchControllerOptions {
password: string password: string
onData?: (data?: PortInfo[][], status?: string) => void onData?: (data?: PortInfo[][], status?: string) => void
keep_connect?: boolean keep_connect?: boolean
stationId: number
stationName: string
stationIP: string
} }
export default class SwitchController { export default class SwitchController {
@ -34,8 +38,20 @@ export default class SwitchController {
public portGroups: PortInfo[][] public portGroups: PortInfo[][]
private isEnable: boolean private isEnable: boolean
private retryConnect: number private retryConnect: number
private stationId: number
private stationName: string
private stationIP: string
constructor({ host, port = 23, username, password, onData }: SwitchControllerOptions) { constructor({
host,
port = 23,
username,
password,
onData,
stationId,
stationName,
stationIP,
}: SwitchControllerOptions) {
this.host = host this.host = host
this.port = port this.port = port
this.username = username this.username = username
@ -49,6 +65,9 @@ export default class SwitchController {
this.portGroups = [] this.portGroups = []
this.isEnable = false this.isEnable = false
this.retryConnect = 0 this.retryConnect = 0
this.stationId = stationId
this.stationName = stationName
this.stationIP = stationIP
} }
private sleep(ms: number) { private sleep(ms: number) {
@ -65,6 +84,7 @@ export default class SwitchController {
this.buffer = '' this.buffer = ''
} }
} }
appendLog(data, this.stationId, this.stationName, this.stationIP, 'Switch')
} }
private async _handleClose(err: boolean) { private async _handleClose(err: boolean) {

View File

@ -59,7 +59,7 @@ export function appendLog(
stationId: number, stationId: number,
stationName: string, stationName: string,
stationIP: string, stationIP: string,
lineNumber: number lineNumber: number | string
) { ) {
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '') // YYYYMMDD const date = new Date().toISOString().slice(0, 10).replace(/-/g, '') // YYYYMMDD
const logDir = path.join('storage', 'system_logs') const logDir = path.join('storage', 'system_logs')

View File

@ -579,8 +579,8 @@ export class WebSocketIo {
await sendMessageToMail( await sendMessageToMail(
'andrew.ng@apactech.io', 'andrew.ng@apactech.io',
`[DPELP] - ${stationName} - ${dataFormat}`, `[DPELP] - ${stationName} - ${dataFormat}`,
tableHTML tableHTML,
// ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io'] ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
) )
await sendMessageToZulip( await sendMessageToZulip(
'stream', 'stream',
@ -759,6 +759,9 @@ export class WebSocketIo {
port, port,
username, username,
password, password,
stationId: station.id,
stationName: station.name,
stationIP: station.ip,
number: apcName === 'apc_1' ? 1 : 2, number: apcName === 'apc_1' ? 1 : 2,
onData: (data: string, status: string) => { onData: (data: string, status: string) => {
socket.emit('apc_output', { socket.emit('apc_output', {
@ -802,6 +805,9 @@ export class WebSocketIo {
port: port, port: port,
username: username, username: username,
password: password, password: password,
stationId: station.id,
stationName: station.name,
stationIP: station.ip,
onData: (ports?: any, status?: string) => { onData: (ports?: any, status?: string) => {
socket.emit('switch_output', { socket.emit('switch_output', {
stationId: station.id, stationId: station.id,

View File

@ -65,13 +65,13 @@ export const ButtonDPELP = ({
repeat: "1", repeat: "1",
note: "", note: "",
}, },
{ // {
expect: "", // expect: "",
send: " terminal length 0", // send: " terminal length 0",
delay: "3000", // delay: "3000",
repeat: "1", // repeat: "1",
note: "", // note: "",
}, // },
{ {
expect: "", expect: "",
send: "enable", send: "enable",