catch exclude error, format message
This commit is contained in:
parent
011a001331
commit
2a08583c03
|
|
@ -0,0 +1,21 @@
|
||||||
|
fdgdfg
|
||||||
|
fksdfk trace ak
|
||||||
|
Power Failure
|
||||||
|
ERROR: % Incomplete command
|
||||||
|
ERROR: % Incomplete command
|
||||||
|
sdfhskd ERROR PVDM3- invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
sdfhskd ERROR PVDM3- invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
sdfhskd ERROR PVDM3- invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shjkg
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shj
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shj
|
||||||
|
invalid |IOSXE_RP_NV-3-NV_ACCESS_FAIL|IOSXE_RP_NV-3- shj pak_debug_init sdh
|
||||||
|
abc
|
||||||
|
123
|
||||||
|
|
@ -11,4 +11,5 @@ WS-X68
|
||||||
WS-X68
|
WS-X68
|
||||||
yellow
|
yellow
|
||||||
SM-
|
SM-
|
||||||
WS-X68
|
WS-X68
|
||||||
|
fksdfk trace ak
|
||||||
|
|
@ -13,7 +13,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
try {
|
try {
|
||||||
let fileList = Array();
|
let fileList = Array();
|
||||||
let fileList_old = Array();
|
let fileList_old = Array();
|
||||||
let listKeyValues = await KeyValue.all();
|
|
||||||
// console.log(listKeyValues.map(obj=>obj.$original.value))
|
// console.log(listKeyValues.map(obj=>obj.$original.value))
|
||||||
// Function to update the list of files
|
// Function to update the list of files
|
||||||
async function updateFileList() {
|
async function updateFileList() {
|
||||||
|
|
@ -41,20 +41,22 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
folderWatcher.on("add", async (filePath) => {
|
folderWatcher.on("add", async (filePath) => {
|
||||||
//import log new file
|
//import log new file
|
||||||
|
// console.log(filePath)
|
||||||
if (
|
if (
|
||||||
|
//Sua \\ --> /
|
||||||
filePath?.split(".")[filePath.split(".").length - 1] === "log" &&
|
filePath?.split(".")[filePath.split(".").length - 1] === "log" &&
|
||||||
filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] ===
|
filePath.split("\\")[filePath.split("\\").length - 1]?.split("-")[0] ===
|
||||||
moment(Date.now()).format("YYYYMMDD").toString()
|
moment(Date.now()).format("YYYYMMDD").toString()
|
||||||
) {
|
) {
|
||||||
console.log("New file added: ", filePath);
|
console.log("New file added: ", filePath);
|
||||||
await LogDetectFile.firstOrCreate(
|
|
||||||
{ file_name: filePath.split("/")[filePath.split("/").length - 1] },
|
|
||||||
{ file_name: filePath.split("/")[filePath.split("/").length - 1] }
|
|
||||||
);
|
|
||||||
// await LogDetectFile.firstOrCreate(
|
// await LogDetectFile.firstOrCreate(
|
||||||
// { file_name: filePath.split("\\")[filePath.split("\\").length - 1] },
|
// { file_name: filePath.split("/")[filePath.split("/").length - 1] },
|
||||||
// { file_name: filePath.split("\\")[filePath.split("\\").length - 1] }
|
// { file_name: filePath.split("/")[filePath.split("/").length - 1] }
|
||||||
// );
|
// );
|
||||||
|
await LogDetectFile.firstOrCreate(
|
||||||
|
{ file_name: filePath.split("\\")[filePath.split("\\").length - 1] },
|
||||||
|
{ file_name: filePath.split("\\")[filePath.split("\\").length - 1] }
|
||||||
|
);
|
||||||
|
|
||||||
fileList_old = fileList;
|
fileList_old = fileList;
|
||||||
updateFileList();
|
updateFileList();
|
||||||
|
|
@ -77,7 +79,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
const filePath = `${folderPath}/${fileName}`;
|
const filePath = `${folderPath}/${fileName}`;
|
||||||
const scan = fs.watchFile(
|
const scan = fs.watchFile(
|
||||||
filePath,
|
filePath,
|
||||||
{ interval: 300000 },
|
{ interval: 5000 },
|
||||||
async (eventType) => {
|
async (eventType) => {
|
||||||
//check special item, extra RAM, error in log
|
//check special item, extra RAM, error in log
|
||||||
let lines = [];
|
let lines = [];
|
||||||
|
|
@ -85,11 +87,26 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
.readFileSync(filePath)
|
.readFileSync(filePath)
|
||||||
.toString()
|
.toString()
|
||||||
?.split("\n");
|
?.split("\n");
|
||||||
|
let allValue = await KeyValue.all();
|
||||||
|
let listKeyValues = allValue.filter(
|
||||||
|
(i) =>
|
||||||
|
i.$original.key === "MODEL_SPECIAL" ||
|
||||||
|
i.$original.key === "CATCH_FAULTY"
|
||||||
|
);
|
||||||
|
|
||||||
|
let listExcludeErr = allValue
|
||||||
|
.filter((i) => i.$original.key === "EXCLUDE_ERR")
|
||||||
|
.map((obj) => obj.$original.value);
|
||||||
|
|
||||||
content.map((line, index) => {
|
content.map((line, index) => {
|
||||||
listKeyValues
|
listKeyValues
|
||||||
.map((obj) => obj.$original.value)
|
.map((obj) => obj.$original.value)
|
||||||
.map(async (value) => {
|
.map(async (value) => {
|
||||||
if (line.search(value) !== -1) {
|
if (
|
||||||
|
line.search(value) !== -1 &&
|
||||||
|
listExcludeErr.filter((err) => line.includes(err))
|
||||||
|
.length === 0
|
||||||
|
) {
|
||||||
// let keyWord = "";
|
// let keyWord = "";
|
||||||
// line.split(" ").map((word) => {
|
// line.split(" ").map((word) => {
|
||||||
// if (word.toLocaleLowerCase().includes(value)) {
|
// if (word.toLocaleLowerCase().includes(value)) {
|
||||||
|
|
@ -118,10 +135,10 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
});
|
});
|
||||||
lines.push(index + 1);
|
lines.push(index + 1);
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// }, 5000);
|
||||||
//true: import log to log_report table, send report to Zulip
|
//true: import log to log_report table, send report to Zulip
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
if (lines.length === 0) {
|
if (lines.length === 0) {
|
||||||
|
|
@ -141,7 +158,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
fileDetect?.id_ldf
|
fileDetect?.id_ldf
|
||||||
);
|
);
|
||||||
|
|
||||||
let listReport = await getListLineByItem(logsDetect[0])
|
let listReport = await getListLineByItem(logsDetect[0]);
|
||||||
let content =
|
let content =
|
||||||
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---:|:---|:-----------:\n";
|
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---:|:---|:-----------:\n";
|
||||||
let spoiler = "";
|
let spoiler = "";
|
||||||
|
|
@ -200,23 +217,23 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
// spoiler = spoiler + "\n```\n\n";
|
// spoiler = spoiler + "\n```\n\n";
|
||||||
// } else {
|
// } else {
|
||||||
listReport.map((log, index) => {
|
listReport.map((log, index) => {
|
||||||
content =
|
content =
|
||||||
content +
|
content +
|
||||||
"|" +
|
"|" +
|
||||||
(index + 1) +
|
(index + 1) +
|
||||||
"|**" +
|
"|**" +
|
||||||
moment(log.created_at).format("HH:mm - DD/MM") +
|
moment(log.created_at).format("HH:mm - DD/MM") +
|
||||||
"**|" +
|
"**|" +
|
||||||
log.detected_content+
|
log.detected_content +
|
||||||
"|" +
|
"|" +
|
||||||
log.line.sort((a, b) => a - b).join(", ") +
|
log.line.sort((a, b) => a - b).join(", ") +
|
||||||
// "|" +
|
// "|" +
|
||||||
// file[log.line - 1] +
|
// file[log.line - 1] +
|
||||||
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
"|[View](https://logs.danielvu.com/api/log/showLog/" +
|
||||||
fileName +
|
fileName +
|
||||||
")\n";
|
")\n";
|
||||||
});
|
});
|
||||||
// }
|
// }
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
sendMessToZulip(
|
sendMessToZulip(
|
||||||
|
|
@ -231,17 +248,17 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
spoiler
|
spoiler
|
||||||
);
|
);
|
||||||
|
|
||||||
sendMessToZulip(
|
// sendMessToZulip(
|
||||||
"stream",
|
// "stream",
|
||||||
"AUS_VN_Test",
|
// "AUS_VN_Test",
|
||||||
"Test Log Alerts",
|
// "Test Log Alerts",
|
||||||
":warning: :warning: **" +
|
// ":warning: :warning: **" +
|
||||||
fileName +
|
// fileName +
|
||||||
"**\n\n" +
|
// "**\n\n" +
|
||||||
content +
|
// content +
|
||||||
"\n\n" +
|
// "\n\n" +
|
||||||
spoiler
|
// spoiler
|
||||||
);
|
// );
|
||||||
// }, 3000);
|
// }, 3000);
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const API = "https://logs.danielvu.com/api";
|
// const API = "https://logs.danielvu.com/api";
|
||||||
|
const API = "http://localhost:3333/api";
|
||||||
export const getKeyValues = API + "/getKeyValue";
|
export const getKeyValues = API + "/getKeyValue";
|
||||||
export const deleteValue = API + "/deleteValue";
|
export const deleteValue = API + "/deleteValue";
|
||||||
export const addKeyValue = API + "/addValue";
|
export const addKeyValue = API + "/addValue";
|
||||||
|
|
@ -26,6 +26,7 @@ import Env from "@ioc:Adonis/Core/Env";
|
||||||
import KeyValue from "App/Models/KeyValue";
|
import KeyValue from "App/Models/KeyValue";
|
||||||
import ErpsController from "App/Controllers/Http/ErpsController";
|
import ErpsController from "App/Controllers/Http/ErpsController";
|
||||||
import LogReport from "App/Models/LogReport";
|
import LogReport from "App/Models/LogReport";
|
||||||
|
import Database from "@ioc:Adonis/Lucid/Database";
|
||||||
|
|
||||||
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
||||||
|
|
||||||
|
|
@ -50,6 +51,19 @@ Route.post("/api/account/checkLogin", "UsersController.checkLogin");
|
||||||
//Log
|
//Log
|
||||||
Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
|
Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
|
||||||
try {
|
try {
|
||||||
|
let fileDetect = await LogDetectFile.findBy(
|
||||||
|
"file_name",
|
||||||
|
request.params().name
|
||||||
|
);
|
||||||
|
let logsDetect = await Database.rawQuery(
|
||||||
|
"select * from log_reports where id_file = " +
|
||||||
|
fileDetect?.id_ldf
|
||||||
|
);
|
||||||
|
|
||||||
|
let listLine = logsDetect[0].map(obj=>obj.line).filter((value, index, self) => {
|
||||||
|
return self.indexOf(value) === index;
|
||||||
|
})
|
||||||
|
|
||||||
const content = await axios.get(
|
const content = await axios.get(
|
||||||
"http://192.168.5.7:8080/" + request.params().name
|
"http://192.168.5.7:8080/" + request.params().name
|
||||||
);
|
);
|
||||||
|
|
@ -103,7 +117,7 @@ Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
|
||||||
border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));\
|
border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));\
|
||||||
border-image: initial;\
|
border-image: initial;\
|
||||||
padding: 2px;'>" +
|
padding: 2px;'>" +
|
||||||
data.join("\n") +
|
"Detected lines in file: "+listLine.join(",")+"\n\n"+data.join("\n") +
|
||||||
"</div>\
|
"</div>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>"
|
</html>"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue