2856 lines
128 KiB
JavaScript
2856 lines
128 KiB
JavaScript
const { stdout } = require("process");
|
|
const Device = require("../models/DeviceModel");
|
|
const spawn = require("child_process").spawn;
|
|
const fs = require("fs");
|
|
const { io } = require("socket.io-client");
|
|
|
|
const callPythonUnsync = async (infoStation, listLine, action, created_by) => {
|
|
let socket = io(process.env.SOCKET_SERVER);
|
|
socket?.emit("newUser", "api");
|
|
const result = [];
|
|
const time = "./public/filesTest/" + Date.now().toString();
|
|
let commands = [];
|
|
try {
|
|
// spawn(process.env.PYTHON_FORMAT, ["./utils/netmiko_test.py",
|
|
// "clear line " + listLine.line_clear,
|
|
// infoStation.sta_ip,
|
|
// infoStation.sta_port_telnet,
|
|
// "clear"], { timeout: 14000 });
|
|
// spawn(
|
|
// process.env.PYTHON_FORMAT, ["./utils/checkPassword.py", "\n", infoStation.sta_ip, listLine.line_port,],
|
|
// { timeout: 30000 }
|
|
// );
|
|
// spawn(process.env.PYTHON_FORMAT, ["./utils/netmiko_test.py",
|
|
// "clear line " + listLine.line_clear,
|
|
// infoStation.sta_ip,
|
|
// infoStation.sta_port_telnet,
|
|
// "clear"], { timeout: 14000 });
|
|
|
|
const clearLine = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear",
|
|
],
|
|
{ timeout: 14000 }
|
|
);
|
|
//clear output
|
|
clearLine.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
//output error
|
|
if (data.search("not available for clearing") !== -1) {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
} else {
|
|
//output clear good
|
|
console.log("OK: ", data);
|
|
console.log("start check password");
|
|
//check password
|
|
let checkPass = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
//check password output
|
|
checkPass.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
console.log("data_checkpass", data);
|
|
//no password
|
|
if (data.search("Pass") !== -1) {
|
|
console.log("passed1!!");
|
|
//check inventory model
|
|
const checkModel = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"show inv",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
//check inventory model fail
|
|
checkModel.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
}
|
|
});
|
|
|
|
//check inventory model output
|
|
checkModel.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
//output error
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
} else {
|
|
if (data !== "") {
|
|
//device OK
|
|
let PID = "";
|
|
let SN = "";
|
|
//get commands
|
|
if (data.split(",")[1] !== undefined) {
|
|
const findModel = data.indexOf("PID:");
|
|
const findSN = data.indexOf("SN:");
|
|
PID = data
|
|
.substr(findModel + 5, 30)
|
|
.split(",")[0]
|
|
.trim();
|
|
SN = data
|
|
.substr(findSN + 4, 17)
|
|
.split("\n")[0]
|
|
.trim();
|
|
let model = ""
|
|
if (PID.split("-")[1] !== undefined) {
|
|
model = model + PID.split("-")[0] + "-" + PID.split("-")[1];
|
|
} else {
|
|
model = model + PID
|
|
}
|
|
console.log("*********SN: ", SN);
|
|
console.log("*********PID: ", PID);
|
|
//get all commands of model if model single
|
|
const cmdModel = await Device.getAllCmdOfModel(model);
|
|
if (cmdModel.pData.length > 0) {
|
|
cmdModel.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
} else {
|
|
//get all groups of model if model have group
|
|
const res = await Device.getAllGroupOfModel(model);
|
|
if (res.pData.length > 0) {
|
|
//
|
|
console.log("-------MODEL exist--------");
|
|
//get command group
|
|
const group_info = res.pData.filter(
|
|
(item) =>
|
|
item.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
console.log(res);
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
group_info[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log("--------MODEL not exist----------");
|
|
const res0 = await Device.getAllGroupOfModel(PID);
|
|
console.log(res0.pData);
|
|
if (res0.pData.length > 0) {
|
|
console.log(
|
|
"--------PID exist and have a group----------"
|
|
);
|
|
//get command group default with action
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get command of group default with "action"
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
res0.pData[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------PID exist and have not a group----------"
|
|
);
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get group default with "action"
|
|
const groupDefault = res.pData.filter(
|
|
(i) =>
|
|
i.group_name.split("_")[0].toLocaleLowerCase() ===
|
|
"default" &&
|
|
i.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
//get command of group default with "action"
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
groupDefault[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
|
|
if (
|
|
res_1.pData.filter((i) => i.id_model === PID)
|
|
.length > 0
|
|
) {
|
|
console.log("--------Add group for PID----------");
|
|
await Device.addModelForGroup(
|
|
groupDefault[0].id_group,
|
|
PID
|
|
);
|
|
} else {
|
|
console.log(
|
|
"--------PID not exist - add PID----------"
|
|
);
|
|
await Device.addModel(
|
|
PID,
|
|
groupDefault[0].id_group,
|
|
"Group",
|
|
Date.now()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//test
|
|
const output = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
commands,
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 40000 }
|
|
);
|
|
socket?.emit("sendChildProcess", {
|
|
id: listLine.id_line,
|
|
pid: output.pid,
|
|
name: "test",
|
|
});
|
|
//test error
|
|
output.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
//test have output
|
|
output.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
let faulty = [
|
|
"err",
|
|
"fail",
|
|
"fault",
|
|
"trace",
|
|
"error",
|
|
"crit",
|
|
"invalid",
|
|
];
|
|
|
|
let modelSpecial = [
|
|
"AIM-",
|
|
"PWR-4",
|
|
"EHWIC-",
|
|
"NIM-",
|
|
"ISM-",
|
|
"PVDM2-",
|
|
"PVDM3-",
|
|
"PVDM4-",
|
|
"DFC4-",
|
|
"WS-X68",
|
|
"3CXL",
|
|
"ISR",
|
|
"800G2-POE-2",
|
|
];
|
|
|
|
let RAMspecial = [
|
|
"29929471K",
|
|
"7213055K",
|
|
"7081983K",
|
|
"6598655K",
|
|
"7057407K",
|
|
"7341807K",
|
|
"7393215K",
|
|
"8388608K",
|
|
"14888959K",
|
|
"14659583K",
|
|
"16777216K",
|
|
"33554432K",
|
|
];
|
|
|
|
let arrayLine = data.toLocaleLowerCase().split("\n");
|
|
let arrayFilter = arrayLine
|
|
.filter((i) => i !== "")
|
|
.filter((i) => i.search("#") === -1);
|
|
let listExcludeErrForAll = [];
|
|
let listExcludeErrForModel = [];
|
|
let listErrorFinal = [];
|
|
let excludeError = [];
|
|
let modelCheck = "";
|
|
let RAMcheck = "";
|
|
let fail = "Faulty: \n";
|
|
|
|
modelSpecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
modelCheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
RAMspecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
console.log(
|
|
data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
)
|
|
);
|
|
RAMcheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
|
|
const excludeErr = await Device.getAllExcludeError();
|
|
excludeErr.pData.map((u) => {
|
|
if (u.err_model.toLocaleLowerCase() === "all") {
|
|
listExcludeErrForAll.push(
|
|
u.err_message.replace(/\~\"\~/g, "'")
|
|
);
|
|
} else {
|
|
listExcludeErrForModel.push(u);
|
|
}
|
|
});
|
|
for (let i = 0; i < faulty.length; i++) {
|
|
for (let j = 0; j < arrayFilter.length; j++) {
|
|
if (arrayFilter[j].search(faulty[i]) !== -1) {
|
|
listErrorFinal.push(arrayFilter[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < listErrorFinal.length; i++) {
|
|
if (listExcludeErrForAll.length > 0) {
|
|
for (
|
|
let j = 0;
|
|
j < listExcludeErrForAll.length;
|
|
j++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForAll[j]
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i].replace("'^'", "''").search(
|
|
listExcludeErrForModel[k].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k].err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i].replace("'^'", "''").search(
|
|
listExcludeErrForModel[k].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k].err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let uniqueArr = listErrorFinal.filter((value) => {
|
|
return !excludeError.includes(value);
|
|
});
|
|
uniqueArr.map((u) => (fail = fail + u + "\n\n"));
|
|
let report =
|
|
fail +
|
|
"======================================================================\n" +
|
|
data;
|
|
if (fail !== "Faulty: \n") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: report,
|
|
status: "Faulty",
|
|
});
|
|
fs.writeFile(time, report, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Faulty",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
} else {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: data,
|
|
status: "Good",
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Good",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
//password
|
|
if (data.search("Enable secret password exist") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
}
|
|
|
|
if (data.search("NetmikoAuthenticationException") !== -1) {
|
|
spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear",
|
|
],
|
|
{ timeout: 14000 }
|
|
);
|
|
spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
|
|
setTimeout(() => {
|
|
const clearLine = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear",
|
|
],
|
|
{ timeout: 14000 }
|
|
);
|
|
//clear success
|
|
clearLine.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data.search("not available for clearing") !== -1) {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
console.log("OK: ", data);
|
|
console.log("start check password");
|
|
let checkPass = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
|
|
checkPass.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
console.log("data_checkpass", data);
|
|
//no password
|
|
if (data.search("Pass") !== -1) {
|
|
console.log("passed1!!");
|
|
//check inventory model
|
|
const checkModel = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"show inv",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
//check inventory model fail
|
|
checkModel.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
|
|
//check model success
|
|
checkModel.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
if (data !== "") {
|
|
//device OK
|
|
let PID = "";
|
|
let SN = "";
|
|
//get commands
|
|
if (data.split(",")[1] !== undefined) {
|
|
const findModel = data.indexOf("PID:");
|
|
const findSN = data.indexOf("SN:");
|
|
PID = data
|
|
.substr(findModel + 5, 30)
|
|
.split(",")[0]
|
|
.trim();
|
|
SN = data
|
|
.substr(findSN + 4, 17)
|
|
.split("\n")[0]
|
|
.trim();
|
|
let model = ""
|
|
if (PID.split("-")[1] !== undefined) {
|
|
model = model + PID.split("-")[0] + "-" + PID.split("-")[1];
|
|
} else {
|
|
model = model + PID
|
|
}
|
|
console.log("*********SN: ", SN);
|
|
console.log("*********model: ", model);
|
|
const cmdModel = await Device.getAllCmdOfModel(
|
|
model
|
|
);
|
|
if (cmdModel.pData.length > 0) {
|
|
cmdModel.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
} else {
|
|
const res = await Device.getAllGroupOfModel(
|
|
model
|
|
);
|
|
if (res.pData.length > 0) {
|
|
console.log("-------MODEL exist--------");
|
|
//get command group
|
|
const group_info = res.pData.filter(
|
|
(item) =>
|
|
item.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
console.log(res);
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
group_info[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------MODEL not exist----------"
|
|
);
|
|
const res0 =
|
|
await Device.getAllGroupOfModel(PID);
|
|
console.log(res0.pData);
|
|
if (res0.pData.length > 0) {
|
|
console.log(
|
|
"--------PID exist and have a group----------"
|
|
);
|
|
//get command group default with action
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get command of group default with "action"
|
|
const res1 =
|
|
await Device.getAllCmdOfGroup(
|
|
res0.pData[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------PID exist and have not a group----------"
|
|
);
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get group default with "action"
|
|
const groupDefault = res.pData.filter(
|
|
(i) =>
|
|
i.group_name
|
|
.split("_")[0]
|
|
.toLocaleLowerCase() ===
|
|
"default" &&
|
|
i.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
//get command of group default with "action"
|
|
const res1 =
|
|
await Device.getAllCmdOfGroup(
|
|
groupDefault[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
|
|
if (
|
|
res_1.pData.filter(
|
|
(i) => i.id_model === PID
|
|
).length > 0
|
|
) {
|
|
console.log(
|
|
"--------Add group for PID----------"
|
|
);
|
|
await Device.addModelForGroup(
|
|
groupDefault[0].id_group,
|
|
PID
|
|
);
|
|
} else {
|
|
console.log(
|
|
"--------PID not exist - add PID----------"
|
|
);
|
|
await Device.addModel(
|
|
PID,
|
|
groupDefault[0].id_group,
|
|
"Group",
|
|
Date.now()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//test
|
|
const output = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
commands,
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 40000 }
|
|
);
|
|
|
|
//test error
|
|
output.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
//test have output
|
|
output.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
let faulty = [
|
|
"err",
|
|
"fail",
|
|
"fault",
|
|
"trace",
|
|
"error",
|
|
"crit",
|
|
"invalid",
|
|
];
|
|
|
|
let modelSpecial = [
|
|
"AIM-",
|
|
"PWR-4",
|
|
"EHWIC-",
|
|
"NIM-",
|
|
"ISM-",
|
|
"PVDM2-",
|
|
"PVDM3-",
|
|
"PVDM4-",
|
|
"DFC4-",
|
|
"WS-X68",
|
|
"3CXL",
|
|
"ISR",
|
|
"800G2-POE-2",
|
|
];
|
|
|
|
let RAMspecial = [
|
|
"29929471K",
|
|
"7213055K",
|
|
"7081983K",
|
|
"6598655K",
|
|
"7057407K",
|
|
"7341807K",
|
|
"7393215K",
|
|
"8388608K",
|
|
"14888959K",
|
|
"14659583K",
|
|
"16777216K",
|
|
"33554432K",
|
|
];
|
|
|
|
let arrayLine = data
|
|
.toLocaleLowerCase()
|
|
.split("\n");
|
|
let arrayFilter = arrayLine
|
|
.filter((i) => i !== "")
|
|
.filter((i) => i.search("#") === -1);
|
|
let listExcludeErrForAll = [];
|
|
let listExcludeErrForModel = [];
|
|
let listErrorFinal = [];
|
|
let excludeError = [];
|
|
let modelCheck = "";
|
|
let RAMcheck = "";
|
|
let fail = "Faulty: \n";
|
|
|
|
modelSpecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
modelCheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
RAMspecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
console.log(
|
|
data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
)
|
|
);
|
|
RAMcheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
|
|
const excludeErr =
|
|
await Device.getAllExcludeError();
|
|
excludeErr.pData.map((u) => {
|
|
if (
|
|
u.err_model.toLocaleLowerCase() === "all"
|
|
) {
|
|
listExcludeErrForAll.push(
|
|
u.err_message.replace(/\~\"\~/g, "'")
|
|
);
|
|
} else {
|
|
listExcludeErrForModel.push(u);
|
|
}
|
|
});
|
|
for (let i = 0; i < faulty.length; i++) {
|
|
for (
|
|
let j = 0;
|
|
j < arrayFilter.length;
|
|
j++
|
|
) {
|
|
if (
|
|
arrayFilter[j].search(faulty[i]) !== -1
|
|
) {
|
|
listErrorFinal.push(arrayFilter[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (
|
|
let i = 0;
|
|
i < listErrorFinal.length;
|
|
i++
|
|
) {
|
|
if (listExcludeErrForAll.length > 0) {
|
|
for (
|
|
let j = 0;
|
|
j < listExcludeErrForAll.length;
|
|
j++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForAll[j]
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[
|
|
k
|
|
].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k]
|
|
.err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(
|
|
listErrorFinal[i]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[
|
|
k
|
|
].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k].err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let uniqueArr = listErrorFinal.filter(
|
|
(value) => {
|
|
return !excludeError.includes(value);
|
|
}
|
|
);
|
|
uniqueArr.map(
|
|
(u) => (fail = fail + u + "\n\n")
|
|
);
|
|
let report =
|
|
fail +
|
|
"======================================================================\n" +
|
|
data;
|
|
if (fail !== "Faulty: \n") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: report,
|
|
status: "Faulty",
|
|
});
|
|
fs.writeFile(time, report, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Faulty",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
} else {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: data,
|
|
status: "Good",
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Good",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
console.log("Error lan 1");
|
|
//password
|
|
if (
|
|
data.search("NetmikoAuthenticationException") !== -1
|
|
) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output:
|
|
"Line console password exist or device is not exist",
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(
|
|
time,
|
|
"Line console password exist or device is not exist",
|
|
function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
}
|
|
);
|
|
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
//clear fail
|
|
clearLine.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
}, 3000);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
//clear fail
|
|
clearLine.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
}
|
|
});
|
|
|
|
setTimeout(() => {
|
|
console.log("Time out 70s");
|
|
if (result.length === 0) {
|
|
spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear",
|
|
],
|
|
{ timeout: 14000 }
|
|
);
|
|
spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
const clearLine = spawn(process.env.PYTHON_FORMAT, ["./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear"], { timeout: 14000 });
|
|
|
|
|
|
|
|
//clear success
|
|
clearLine.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data.search("not available for clearing") !== -1) {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
} else {
|
|
console.log("OK: ", data);
|
|
console.log("start check password");
|
|
let checkPass = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
|
|
checkPass.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
console.log("data_checkpass", data);
|
|
//no password
|
|
if (data.search("Pass") !== -1) {
|
|
console.log("passed1!!");
|
|
//check inventory model
|
|
const checkModel = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"show inv",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
//check inventory model fail
|
|
checkModel.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
|
|
//check model success
|
|
checkModel.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
if (data !== "") {
|
|
//device OK
|
|
let PID = "";
|
|
let SN = "";
|
|
//get commands
|
|
if (data.split(",")[1] !== undefined) {
|
|
const findModel = data.indexOf("PID:");
|
|
const findSN = data.indexOf("SN:");
|
|
PID = data
|
|
.substr(findModel + 5, 30)
|
|
.split(",")[0]
|
|
.trim();
|
|
SN = data
|
|
.substr(findSN + 4, 17)
|
|
.split("\n")[0]
|
|
.trim();
|
|
let model = ""
|
|
if (PID.split("-")[1] !== undefined) {
|
|
model = model + PID.split("-")[0] + "-" + PID.split("-")[1];
|
|
} else {
|
|
model = model + PID
|
|
}
|
|
console.log("*********SN: ", SN);
|
|
console.log("*********model: ", model);
|
|
const cmdModel = await Device.getAllCmdOfModel(model);
|
|
if (cmdModel.pData.length > 0) {
|
|
cmdModel.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
} else {
|
|
const res = await Device.getAllGroupOfModel(model);
|
|
if (res.pData.length > 0) {
|
|
console.log("-------MODEL exist--------");
|
|
//get command group
|
|
const group_info = res.pData.filter(
|
|
(item) =>
|
|
item.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
console.log(res);
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
group_info[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log("--------MODEL not exist----------");
|
|
const res0 = await Device.getAllGroupOfModel(PID);
|
|
console.log(res0.pData);
|
|
if (res0.pData.length > 0) {
|
|
console.log(
|
|
"--------PID exist and have a group----------"
|
|
);
|
|
//get command group default with action
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get command of group default with "action"
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
res0.pData[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------PID exist and have not a group----------"
|
|
);
|
|
const res = await Device.getAllGroup();
|
|
const res_1 = await Device.getAllModel();
|
|
//get group default with "action"
|
|
const groupDefault = res.pData.filter(
|
|
(i) =>
|
|
i.group_name
|
|
.split("_")[0]
|
|
.toLocaleLowerCase() === "default" &&
|
|
i.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
//get command of group default with "action"
|
|
const res1 = await Device.getAllCmdOfGroup(
|
|
groupDefault[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
|
|
if (
|
|
res_1.pData.filter((i) => i.id_model === PID)
|
|
.length > 0
|
|
) {
|
|
console.log(
|
|
"--------Add group for PID----------"
|
|
);
|
|
await Device.addModelForGroup(
|
|
groupDefault[0].id_group,
|
|
PID
|
|
);
|
|
} else {
|
|
console.log(
|
|
"--------PID not exist - add PID----------"
|
|
);
|
|
await Device.addModel(
|
|
PID,
|
|
groupDefault[0].id_group,
|
|
"Group",
|
|
Date.now()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//test
|
|
const output = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
commands,
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 40000 }
|
|
);
|
|
|
|
//test error
|
|
output.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
//test have output
|
|
output.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
let faulty = [
|
|
"err",
|
|
"fail",
|
|
"fault",
|
|
"trace",
|
|
"error",
|
|
"crit",
|
|
"invalid",
|
|
];
|
|
|
|
let modelSpecial = [
|
|
"AIM-",
|
|
"PWR-4",
|
|
"EHWIC-",
|
|
"NIM-",
|
|
"ISM-",
|
|
"PVDM2-",
|
|
"PVDM3-",
|
|
"PVDM4-",
|
|
"DFC4-",
|
|
"WS-X68",
|
|
"3CXL",
|
|
"ISR",
|
|
"800G2-POE-2",
|
|
];
|
|
|
|
let RAMspecial = [
|
|
"29929471K",
|
|
"7213055K",
|
|
"7081983K",
|
|
"6598655K",
|
|
"7057407K",
|
|
"7341807K",
|
|
"7393215K",
|
|
"8388608K",
|
|
"14888959K",
|
|
"14659583K",
|
|
"16777216K",
|
|
"33554432K",
|
|
];
|
|
|
|
let arrayLine = data
|
|
.toLocaleLowerCase()
|
|
.split("\n");
|
|
let arrayFilter = arrayLine
|
|
.filter((i) => i !== "")
|
|
.filter((i) => i.search("#") === -1);
|
|
let listExcludeErrForAll = [];
|
|
let listExcludeErrForModel = [];
|
|
let listErrorFinal = [];
|
|
let excludeError = [];
|
|
let modelCheck = "";
|
|
let RAMcheck = "";
|
|
let fail = "Faulty: \n";
|
|
|
|
modelSpecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
modelCheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
RAMspecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
console.log(
|
|
data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
)
|
|
);
|
|
RAMcheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
|
|
const excludeErr =
|
|
await Device.getAllExcludeError();
|
|
excludeErr.pData.map((u) => {
|
|
if (u.err_model.toLocaleLowerCase() === "all") {
|
|
listExcludeErrForAll.push(
|
|
u.err_message.replace(/\~\"\~/g, "'")
|
|
);
|
|
} else {
|
|
listExcludeErrForModel.push(u);
|
|
}
|
|
});
|
|
for (let i = 0; i < faulty.length; i++) {
|
|
for (let j = 0; j < arrayFilter.length; j++) {
|
|
if (arrayFilter[j].search(faulty[i]) !== -1) {
|
|
listErrorFinal.push(arrayFilter[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < listErrorFinal.length; i++) {
|
|
if (listExcludeErrForAll.length > 0) {
|
|
for (
|
|
let j = 0;
|
|
j < listExcludeErrForAll.length;
|
|
j++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForAll[j]
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[
|
|
k
|
|
].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k].err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[k].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k].err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(listErrorFinal[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let uniqueArr = listErrorFinal.filter((value) => {
|
|
return !excludeError.includes(value);
|
|
});
|
|
uniqueArr.map((u) => (fail = fail + u + "\n\n"));
|
|
let report =
|
|
fail +
|
|
"======================================================================\n" +
|
|
data;
|
|
if (fail !== "Faulty: \n") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: report,
|
|
status: "Faulty",
|
|
});
|
|
fs.writeFile(time, report, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Faulty",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
} else {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: data,
|
|
status: "Good",
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Good",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
console.log("Error lan 1");
|
|
//password
|
|
if (data.search("NetmikoAuthenticationException") !== -1) {
|
|
const clearLine = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"clear line " + listLine.line_clear,
|
|
infoStation.sta_ip,
|
|
infoStation.sta_port_telnet,
|
|
"clear",
|
|
],
|
|
{ timeout: 14000 }
|
|
);
|
|
|
|
//clear success
|
|
clearLine.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data.search("not available for clearing") !== -1) {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
console.log("OK: ", data);
|
|
console.log("start check password");
|
|
let checkPass = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/checkPassword.py",
|
|
"\n",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
|
|
checkPass.stdout.on("data", (data) => {
|
|
data = data.toString();
|
|
console.log("data_checkpass", data);
|
|
//no password
|
|
if (data.search("Pass") !== -1) {
|
|
console.log("passed1!!");
|
|
//check inventory model
|
|
const checkModel = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
"show inv",
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 30000 }
|
|
);
|
|
//check inventory model fail
|
|
checkModel.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
|
|
//check model success
|
|
checkModel.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
if (data !== "") {
|
|
//device OK
|
|
let PID = "";
|
|
let SN = "";
|
|
//get commands
|
|
if (data.split(",")[1] !== undefined) {
|
|
const findModel = data.indexOf("PID:");
|
|
const findSN = data.indexOf("SN:");
|
|
PID = data
|
|
.substr(findModel + 5, 30)
|
|
.split(",")[0]
|
|
.trim();
|
|
SN = data
|
|
.substr(findSN + 4, 17)
|
|
.split("\n")[0]
|
|
.trim();
|
|
let model = ""
|
|
if (PID.split("-")[1] !== undefined) {
|
|
model = model + PID.split("-")[0] + "-" + PID.split("-")[1];
|
|
} else {
|
|
model = model + PID
|
|
}
|
|
console.log("*********SN: ", SN);
|
|
console.log("*********model: ", model);
|
|
const cmdModel =
|
|
await Device.getAllCmdOfModel(model);
|
|
if (cmdModel.pData.length > 0) {
|
|
cmdModel.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
} else {
|
|
const res =
|
|
await Device.getAllGroupOfModel(model);
|
|
if (res.pData.length > 0) {
|
|
console.log(
|
|
"-------MODEL exist--------"
|
|
);
|
|
//get command group
|
|
const group_info = res.pData.filter(
|
|
(item) =>
|
|
item.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
console.log(res);
|
|
const res1 =
|
|
await Device.getAllCmdOfGroup(
|
|
group_info[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------MODEL not exist----------"
|
|
);
|
|
const res0 =
|
|
await Device.getAllGroupOfModel(PID);
|
|
console.log(res0.pData);
|
|
if (res0.pData.length > 0) {
|
|
console.log(
|
|
"--------PID exist and have a group----------"
|
|
);
|
|
//get command group default with action
|
|
const res =
|
|
await Device.getAllGroup();
|
|
const res_1 =
|
|
await Device.getAllModel();
|
|
//get command of group default with "action"
|
|
const res1 =
|
|
await Device.getAllCmdOfGroup(
|
|
res0.pData[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
} else {
|
|
console.log(
|
|
"--------PID exist and have not a group----------"
|
|
);
|
|
const res =
|
|
await Device.getAllGroup();
|
|
const res_1 =
|
|
await Device.getAllModel();
|
|
//get group default with "action"
|
|
const groupDefault = res.pData.filter(
|
|
(i) =>
|
|
i.group_name
|
|
.split("_")[0]
|
|
.toLocaleLowerCase() ===
|
|
"default" &&
|
|
i.group_action.toLocaleLowerCase() ===
|
|
action.toLocaleLowerCase()
|
|
);
|
|
//get command of group default with "action"
|
|
const res1 =
|
|
await Device.getAllCmdOfGroup(
|
|
groupDefault[0].id_group
|
|
);
|
|
res1.pData.map((u) => {
|
|
commands.push(u.cmd_message);
|
|
});
|
|
console.log(commands);
|
|
|
|
if (
|
|
res_1.pData.filter(
|
|
(i) => i.id_model === PID
|
|
).length > 0
|
|
) {
|
|
console.log(
|
|
"--------Add group for PID----------"
|
|
);
|
|
await Device.addModelForGroup(
|
|
groupDefault[0].id_group,
|
|
PID
|
|
);
|
|
} else {
|
|
console.log(
|
|
"--------PID not exist - add PID----------"
|
|
);
|
|
await Device.addModel(
|
|
PID,
|
|
groupDefault[0].id_group,
|
|
"Group",
|
|
Date.now()
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//test
|
|
const output = spawn(
|
|
process.env.PYTHON_FORMAT,
|
|
[
|
|
"./utils/netmiko_test.py",
|
|
commands,
|
|
infoStation.sta_ip,
|
|
listLine.line_port,
|
|
"check",
|
|
],
|
|
{ timeout: 40000 });
|
|
|
|
|
|
//test error
|
|
output.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " +
|
|
listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
//test have output
|
|
output.stdout.on("data", async (data) => {
|
|
data = data.toString();
|
|
if (data.search("xxError") !== -1) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " +
|
|
listLine.line_number
|
|
);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
} else {
|
|
let faulty = [
|
|
"err",
|
|
"fail",
|
|
"fault",
|
|
"trace",
|
|
"error",
|
|
"crit",
|
|
"invalid",
|
|
];
|
|
|
|
let modelSpecial = [
|
|
"AIM-",
|
|
"PWR-4",
|
|
"EHWIC-",
|
|
"NIM-",
|
|
"ISM-",
|
|
"PVDM2-",
|
|
"PVDM3-",
|
|
"PVDM4-",
|
|
"DFC4-",
|
|
"WS-X68",
|
|
"3CXL",
|
|
"ISR",
|
|
"800G2-POE-2",
|
|
];
|
|
|
|
let RAMspecial = [
|
|
"29929471K",
|
|
"7213055K",
|
|
"7081983K",
|
|
"6598655K",
|
|
"7057407K",
|
|
"7341807K",
|
|
"7393215K",
|
|
"8388608K",
|
|
"14888959K",
|
|
"14659583K",
|
|
"16777216K",
|
|
"33554432K",
|
|
];
|
|
|
|
let arrayLine = data
|
|
.toLocaleLowerCase()
|
|
.split("\n");
|
|
let arrayFilter = arrayLine
|
|
.filter((i) => i !== "")
|
|
.filter((i) => i.search("#") === -1);
|
|
let listExcludeErrForAll = [];
|
|
let listExcludeErrForModel = [];
|
|
let listErrorFinal = [];
|
|
let excludeError = [];
|
|
let modelCheck = "";
|
|
let RAMcheck = "";
|
|
let fail = "Faulty: \n";
|
|
|
|
modelSpecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
modelCheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
RAMspecial.map((u) => {
|
|
if (data.search(u) !== -1) {
|
|
console.log(
|
|
data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
)
|
|
);
|
|
RAMcheck = data.slice(
|
|
data.search(u),
|
|
data.search(u) + u.length
|
|
);
|
|
}
|
|
});
|
|
|
|
const excludeErr =
|
|
await Device.getAllExcludeError();
|
|
excludeErr.pData.map((u) => {
|
|
if (
|
|
u.err_model.toLocaleLowerCase() ===
|
|
"all"
|
|
) {
|
|
listExcludeErrForAll.push(
|
|
u.err_message.replace(
|
|
/\~\"\~/g,
|
|
"'"
|
|
)
|
|
);
|
|
} else {
|
|
listExcludeErrForModel.push(u);
|
|
}
|
|
});
|
|
for (let i = 0; i < faulty.length; i++) {
|
|
for (
|
|
let j = 0;
|
|
j < arrayFilter.length;
|
|
j++
|
|
) {
|
|
if (
|
|
arrayFilter[j].search(faulty[i]) !==
|
|
-1
|
|
) {
|
|
listErrorFinal.push(arrayFilter[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (
|
|
let i = 0;
|
|
i < listErrorFinal.length;
|
|
i++
|
|
) {
|
|
if (listExcludeErrForAll.length > 0) {
|
|
for (
|
|
let j = 0;
|
|
j < listExcludeErrForAll.length;
|
|
j++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForAll[j]
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1
|
|
) {
|
|
excludeError.push(
|
|
listErrorFinal[i]
|
|
);
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k <
|
|
listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[
|
|
k
|
|
].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k]
|
|
.err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(
|
|
listErrorFinal[i]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for (
|
|
let k = 0;
|
|
k < listExcludeErrForModel.length;
|
|
k++
|
|
) {
|
|
if (
|
|
listErrorFinal[i]
|
|
.replace("'^'", "''")
|
|
.search(
|
|
listExcludeErrForModel[
|
|
k
|
|
].err_message
|
|
.replace(/\~\"\~/g, "'")
|
|
.replace("'^'", "''")
|
|
.toLocaleLowerCase()
|
|
) !== -1 &&
|
|
PID.search(
|
|
listExcludeErrForModel[k]
|
|
.err_model
|
|
) !== -1
|
|
) {
|
|
excludeError.push(
|
|
listErrorFinal[i]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let uniqueArr = listErrorFinal.filter(
|
|
(value) => {
|
|
return !excludeError.includes(value);
|
|
}
|
|
);
|
|
uniqueArr.map(
|
|
(u) => (fail = fail + u + "\n\n")
|
|
);
|
|
let report =
|
|
fail +
|
|
"======================================================================\n" +
|
|
data;
|
|
if (fail !== "Faulty: \n") {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: report,
|
|
status: "Faulty",
|
|
});
|
|
fs.writeFile(
|
|
time,
|
|
report,
|
|
function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " +
|
|
listLine.line_number
|
|
);
|
|
}
|
|
);
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Faulty",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
} else {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
PID: PID,
|
|
SN: SN,
|
|
modelCheck: modelCheck,
|
|
RAMcheck: RAMcheck,
|
|
output: data,
|
|
status: "Good",
|
|
});
|
|
fs.writeFile(
|
|
time,
|
|
data,
|
|
function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " +
|
|
listLine.line_number
|
|
);
|
|
}
|
|
);
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Good",
|
|
Date.now(),
|
|
created_by,
|
|
PID,
|
|
SN
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
infoStation,
|
|
listLine
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
console.log("Error lan 1");
|
|
//password
|
|
if (
|
|
data.search("NetmikoAuthenticationException") !==
|
|
-1
|
|
) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output:
|
|
"Line console password exist or device is not exist",
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(
|
|
time,
|
|
"Line console password exist or device is not exist",
|
|
function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log(
|
|
"Write log line " + listLine.line_number
|
|
);
|
|
}
|
|
);
|
|
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
//clear fail
|
|
clearLine.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", {
|
|
id: listLine.id_line,
|
|
result,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
//clear fail
|
|
clearLine.stderr.on("data", (data) => {
|
|
data = data.toString();
|
|
if (data !== "") {
|
|
console.log("Loi: ", data);
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: data,
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, data, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
}
|
|
});
|
|
}, 5000);
|
|
|
|
setTimeout(() => {
|
|
if (result.length === 0) {
|
|
result.push({
|
|
id_line: listLine.id_line,
|
|
line: listLine.line_number,
|
|
line_ip: listLine.line_ip,
|
|
port: listLine.line_port,
|
|
output: "Time out",
|
|
status: "Error",
|
|
sta_name: infoStation.sta_name,
|
|
});
|
|
fs.writeFile(time, "Time out", function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
console.log("Write log line " + listLine.line_number);
|
|
});
|
|
Device.addLog(
|
|
listLine.id_line,
|
|
time,
|
|
"Error",
|
|
Date.now(),
|
|
created_by,
|
|
"",
|
|
""
|
|
);
|
|
socket?.emit("send-process", { id: listLine.id_line, result });
|
|
}
|
|
}, 90000);
|
|
console.log(result);
|
|
return result;
|
|
}
|
|
}, 120000);
|
|
console.log(result);
|
|
return result;
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
};
|
|
|
|
module.exports = callPythonUnsync;
|