Update add log switch, apc
This commit is contained in:
parent
2bc1338316
commit
117d982c4d
|
|
@ -9,6 +9,9 @@ interface APCOptions {
|
|||
onData?: (data: string, status: string) => void
|
||||
number?: number
|
||||
keep_connect?: boolean
|
||||
stationId: number
|
||||
stationName: string
|
||||
stationIP: string
|
||||
}
|
||||
|
||||
interface PromptCallback {
|
||||
|
|
@ -29,8 +32,21 @@ class APCController {
|
|||
private promptCallbacks: PromptCallback[]
|
||||
private onData: (data: string, status: string) => void
|
||||
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_ip = host
|
||||
this.apc_port = port
|
||||
|
|
@ -43,6 +59,9 @@ class APCController {
|
|||
this.promptCallbacks = []
|
||||
this.onData = onData || (() => {})
|
||||
this.retryConnect = 0
|
||||
this.stationId = stationId
|
||||
this.stationName = stationName
|
||||
this.stationIP = stationIP
|
||||
}
|
||||
|
||||
private sleep(ms: number): Promise<void> {
|
||||
|
|
@ -101,7 +120,7 @@ class APCController {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -592,6 +592,9 @@ export default class LineConnection {
|
|||
port,
|
||||
username,
|
||||
password,
|
||||
stationId: this.config.stationId,
|
||||
stationName: this.config.stationName,
|
||||
stationIP: this.config.stationIp,
|
||||
number: this.config.lineNumber,
|
||||
onData: (data: string, status: string) => {
|
||||
this.config.output += data
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import net from 'node:net'
|
||||
import { appendLog } from '../ultils/helper.js'
|
||||
|
||||
type PromptCallback = {
|
||||
prompt: string
|
||||
|
|
@ -18,6 +19,9 @@ interface SwitchControllerOptions {
|
|||
password: string
|
||||
onData?: (data?: PortInfo[][], status?: string) => void
|
||||
keep_connect?: boolean
|
||||
stationId: number
|
||||
stationName: string
|
||||
stationIP: string
|
||||
}
|
||||
|
||||
export default class SwitchController {
|
||||
|
|
@ -34,8 +38,20 @@ export default class SwitchController {
|
|||
public portGroups: PortInfo[][]
|
||||
private isEnable: boolean
|
||||
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.port = port
|
||||
this.username = username
|
||||
|
|
@ -49,6 +65,9 @@ export default class SwitchController {
|
|||
this.portGroups = []
|
||||
this.isEnable = false
|
||||
this.retryConnect = 0
|
||||
this.stationId = stationId
|
||||
this.stationName = stationName
|
||||
this.stationIP = stationIP
|
||||
}
|
||||
|
||||
private sleep(ms: number) {
|
||||
|
|
@ -65,6 +84,7 @@ export default class SwitchController {
|
|||
this.buffer = ''
|
||||
}
|
||||
}
|
||||
appendLog(data, this.stationId, this.stationName, this.stationIP, 'Switch')
|
||||
}
|
||||
|
||||
private async _handleClose(err: boolean) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export function appendLog(
|
|||
stationId: number,
|
||||
stationName: string,
|
||||
stationIP: string,
|
||||
lineNumber: number
|
||||
lineNumber: number | string
|
||||
) {
|
||||
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '') // YYYYMMDD
|
||||
const logDir = path.join('storage', 'system_logs')
|
||||
|
|
|
|||
|
|
@ -579,8 +579,8 @@ export class WebSocketIo {
|
|||
await sendMessageToMail(
|
||||
'andrew.ng@apactech.io',
|
||||
`[DPELP] - ${stationName} - ${dataFormat}`,
|
||||
tableHTML
|
||||
// ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
|
||||
tableHTML,
|
||||
['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
|
||||
)
|
||||
await sendMessageToZulip(
|
||||
'stream',
|
||||
|
|
@ -759,6 +759,9 @@ export class WebSocketIo {
|
|||
port,
|
||||
username,
|
||||
password,
|
||||
stationId: station.id,
|
||||
stationName: station.name,
|
||||
stationIP: station.ip,
|
||||
number: apcName === 'apc_1' ? 1 : 2,
|
||||
onData: (data: string, status: string) => {
|
||||
socket.emit('apc_output', {
|
||||
|
|
@ -802,6 +805,9 @@ export class WebSocketIo {
|
|||
port: port,
|
||||
username: username,
|
||||
password: password,
|
||||
stationId: station.id,
|
||||
stationName: station.name,
|
||||
stationIP: station.ip,
|
||||
onData: (ports?: any, status?: string) => {
|
||||
socket.emit('switch_output', {
|
||||
stationId: station.id,
|
||||
|
|
|
|||
|
|
@ -65,13 +65,13 @@ export const ButtonDPELP = ({
|
|||
repeat: "1",
|
||||
note: "",
|
||||
},
|
||||
{
|
||||
expect: "",
|
||||
send: " terminal length 0",
|
||||
delay: "3000",
|
||||
repeat: "1",
|
||||
note: "",
|
||||
},
|
||||
// {
|
||||
// expect: "",
|
||||
// send: " terminal length 0",
|
||||
// delay: "3000",
|
||||
// repeat: "1",
|
||||
// note: "",
|
||||
// },
|
||||
{
|
||||
expect: "",
|
||||
send: "enable",
|
||||
|
|
|
|||
Loading…
Reference in New Issue