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
|
||||
|
|
@ -12,3 +12,4 @@ WS-X68
|
|||
yellow
|
||||
SM-
|
||||
WS-X68
|
||||
fksdfk trace ak
|
||||
|
|
@ -13,7 +13,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
try {
|
||||
let fileList = Array();
|
||||
let fileList_old = Array();
|
||||
let listKeyValues = await KeyValue.all();
|
||||
|
||||
// console.log(listKeyValues.map(obj=>obj.$original.value))
|
||||
// Function to update the list of files
|
||||
async function updateFileList() {
|
||||
|
|
@ -41,20 +41,22 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
folderWatcher.on("add", async (filePath) => {
|
||||
//import log new file
|
||||
// console.log(filePath)
|
||||
if (
|
||||
//Sua \\ --> /
|
||||
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()
|
||||
) {
|
||||
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(
|
||||
// { 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;
|
||||
updateFileList();
|
||||
|
|
@ -77,7 +79,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
const filePath = `${folderPath}/${fileName}`;
|
||||
const scan = fs.watchFile(
|
||||
filePath,
|
||||
{ interval: 300000 },
|
||||
{ interval: 5000 },
|
||||
async (eventType) => {
|
||||
//check special item, extra RAM, error in log
|
||||
let lines = [];
|
||||
|
|
@ -85,11 +87,26 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
.readFileSync(filePath)
|
||||
.toString()
|
||||
?.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) => {
|
||||
listKeyValues
|
||||
.map((obj) => obj.$original.value)
|
||||
.map(async (value) => {
|
||||
if (line.search(value) !== -1) {
|
||||
if (
|
||||
line.search(value) !== -1 &&
|
||||
listExcludeErr.filter((err) => line.includes(err))
|
||||
.length === 0
|
||||
) {
|
||||
// let keyWord = "";
|
||||
// line.split(" ").map((word) => {
|
||||
// if (word.toLocaleLowerCase().includes(value)) {
|
||||
|
|
@ -118,10 +135,10 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
});
|
||||
lines.push(index + 1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
});
|
||||
});
|
||||
// }, 5000);
|
||||
//true: import log to log_report table, send report to Zulip
|
||||
setTimeout(async () => {
|
||||
if (lines.length === 0) {
|
||||
|
|
@ -141,7 +158,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
fileDetect?.id_ldf
|
||||
);
|
||||
|
||||
let listReport = await getListLineByItem(logsDetect[0])
|
||||
let listReport = await getListLineByItem(logsDetect[0]);
|
||||
let content =
|
||||
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---:|:---|:-----------:\n";
|
||||
let spoiler = "";
|
||||
|
|
@ -208,7 +225,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
"|**" +
|
||||
moment(log.created_at).format("HH:mm - DD/MM") +
|
||||
"**|" +
|
||||
log.detected_content+
|
||||
log.detected_content +
|
||||
"|" +
|
||||
log.line.sort((a, b) => a - b).join(", ") +
|
||||
// "|" +
|
||||
|
|
@ -231,17 +248,17 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
spoiler
|
||||
);
|
||||
|
||||
sendMessToZulip(
|
||||
"stream",
|
||||
"AUS_VN_Test",
|
||||
"Test Log Alerts",
|
||||
":warning: :warning: **" +
|
||||
fileName +
|
||||
"**\n\n" +
|
||||
content +
|
||||
"\n\n" +
|
||||
spoiler
|
||||
);
|
||||
// sendMessToZulip(
|
||||
// "stream",
|
||||
// "AUS_VN_Test",
|
||||
// "Test Log Alerts",
|
||||
// ":warning: :warning: **" +
|
||||
// fileName +
|
||||
// "**\n\n" +
|
||||
// content +
|
||||
// "\n\n" +
|
||||
// spoiler
|
||||
// );
|
||||
// }, 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 deleteValue = API + "/deleteValue";
|
||||
export const addKeyValue = API + "/addValue";
|
||||
|
|
@ -26,6 +26,7 @@ import Env from "@ioc:Adonis/Core/Env";
|
|||
import KeyValue from "App/Models/KeyValue";
|
||||
import ErpsController from "App/Controllers/Http/ErpsController";
|
||||
import LogReport from "App/Models/LogReport";
|
||||
import Database from "@ioc:Adonis/Lucid/Database";
|
||||
|
||||
runtimeCheckLogs(Env.get("FOLDER_LOGS"));
|
||||
|
||||
|
|
@ -50,6 +51,19 @@ Route.post("/api/account/checkLogin", "UsersController.checkLogin");
|
|||
//Log
|
||||
Route.get("/api/log/showLog/:name?", async ({ request, response }) => {
|
||||
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(
|
||||
"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-image: initial;\
|
||||
padding: 2px;'>" +
|
||||
data.join("\n") +
|
||||
"Detected lines in file: "+listLine.join(",")+"\n\n"+data.join("\n") +
|
||||
"</div>\
|
||||
</body>\
|
||||
</html>"
|
||||
|
|
|
|||
Loading…
Reference in New Issue