update config database

This commit is contained in:
joseph le 2023-09-21 11:01:00 +07:00
parent fa4d620db6
commit aa7f1c2cd8
1 changed files with 159 additions and 159 deletions

View File

@ -10,7 +10,7 @@ import { getListLineByItem } from "./getListLineByItem";
export async function runtimeCheckLogs(folderPath) {
try {
const { connection } = Database.manager.get('mysql')
const connection = Database.connection('mysql');
let fileList = Array();
let fileList_old = Array();
// Function to update the list of files
@ -99,185 +99,184 @@ export async function runtimeCheckLogs(folderPath) {
let lines = [];
//get information file
let fileDetect = await LogDetectFile.findBy(
"file_name",
fileName
);
// let fileDetect = await LogDetectFile.findBy(
// "file_name",
// fileName
// );
//get all log of file
let logsDetect = await Database.rawQuery(
"select * from log_reports where id_file = " +
fileDetect?.id_ldf
);
// //get all log of file
// let logsDetect = await Database.rawQuery(
// "select * from log_reports where id_file = " +
// fileDetect?.id_ldf
// );
//get the last line detected
let lastLine = Math.max(...logsDetect[0].map((obj) => obj.line));
// //get the last line detected
// let lastLine = Math.max(...logsDetect[0].map((obj) => obj.line));
//get content file in local
let contentFile = await fs
.readFileSync(filePath)
.toString()
?.split("\n");
// //get content file in local
// let contentFile = await fs
// .readFileSync(filePath)
// .toString()
// ?.split("\n");
//get all values to check
let allValue = await KeyValue.all();
// //get all values to check
// let allValue = await KeyValue.all();
//get list item to check
let listKeyValues = allValue.filter(
(i) =>
i.$original.key === "MODEL_SPECIAL" ||
i.$original.key === "CATCH_FAULTY"
);
// //get list item to check
// let listKeyValues = allValue.filter(
// (i) =>
// i.$original.key === "MODEL_SPECIAL" ||
// i.$original.key === "CATCH_FAULTY"
// );
//get list exclude error
let listExcludeErr = allValue
.filter((i) => i.$original.key === "EXCLUDE_ERR")
.map((obj) => obj.$original.value);
// //get list exclude error
// let listExcludeErr = allValue
// .filter((i) => i.$original.key === "EXCLUDE_ERR")
// .map((obj) => obj.$original.value);
//get list item special
let listExtraItem = allValue
.filter((i) => i.$original.key === "MODEL_SPECIAL")
.map((obj) => obj.$original.value);
// //get list item special
// let listExtraItem = allValue
// .filter((i) => i.$original.key === "MODEL_SPECIAL")
// .map((obj) => obj.$original.value);
//Process file content
contentFile.map((line, index) => {
// //Process file content
// contentFile.map((line, index) => {
//check line the line with errors and exclude errors
listKeyValues
.map((obj) => obj.$original.value)
.map(async (value) => {
if (
line.search(value) !== -1 &&
listExcludeErr.filter((err) => line.includes(err))
.length === 0
) {
const log = await LogDetectFile.findBy(
"file_name",
fileName
);
//check report of line not exist
let checkLog = await Database.rawQuery(
"select * from log_reports where id_file = " +
log?.id_ldf +
" and line = " +
(index + 1) +
" and detected_content='" +
value +
"'"
);
// //check line the line with errors and exclude errors
// listKeyValues
// .map((obj) => obj.$original.value)
// .map(async (value) => {
// if (
// line.search(value) !== -1 &&
// listExcludeErr.filter((err) => line.includes(err))
// .length === 0
// ) {
// const log = await LogDetectFile.findBy(
// "file_name",
// fileName
// );
// //check report of line not exist
// let checkLog = await Database.rawQuery(
// "select * from log_reports where id_file = " +
// log?.id_ldf +
// " and line = " +
// (index + 1) +
// " and detected_content='" +
// value +
// "'"
// );
if (checkLog[0].length === 0) {
await LogReport.create({
detected_content: value,
line: index + 1,
id_file: log?.id_ldf,
});
lines.push(index + 1);
}
}
// if (checkLog[0].length === 0) {
// await LogReport.create({
// detected_content: value,
// line: index + 1,
// id_file: log?.id_ldf,
// });
// lines.push(index + 1);
// }
// }
// if(checkSpecialVersion())
});
});
// // if(checkSpecialVersion())
// });
// });
//true: import log to log_report table, send report to Zulip
setTimeout(async () => {
if (lines.length === 0) {
console.log(`${fileName} has changed (${eventType})---Good`);
} else {
console.log(
`${fileName} has changed (${eventType})---SOS---${lines.length}`
);
// setTimeout(async () => {
// if (lines.length === 0) {
// console.log(`${fileName} has changed (${eventType})---Good`);
// } else {
// console.log(
// `${fileName} has changed (${eventType})---SOS---${lines.length}`
// );
let fileDetect = await LogDetectFile.findBy(
"file_name",
fileName
);
// let fileDetect = await LogDetectFile.findBy(
// "file_name",
// fileName
// );
let logsDetect = await Database.rawQuery(
"select * from log_reports where id_file = " +
fileDetect?.id_ldf
);
// let logsDetect = await Database.rawQuery(
// "select * from log_reports where id_file = " +
// fileDetect?.id_ldf
// );
//Get all report newest
let listReport = await getListLineByItem(
logsDetect[0].filter((l) => l.line > lastLine)
);
// //Get all report newest
// let listReport = await getListLineByItem(
// logsDetect[0].filter((l) => l.line > lastLine)
// );
let content =
"| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
let spoiler = "";
let issueFound = "";
// let content =
// "| |Last updated at | Item/error | Line | Report \n|---|:---:|:---|:---|:-----------:\n";
// let spoiler = "";
// let issueFound = "";
listReport.map((log, index) => {
let item = listExtraItem.includes(log.detected_content)
? ":medal: **" + log.detected_content + "**"
: ":small_orange_diamond: " + log.detected_content;
// listReport.map((log, index) => {
// let item = listExtraItem.includes(log.detected_content)
// ? ":medal: **" + log.detected_content + "**"
// : ":small_orange_diamond: " + log.detected_content;
log.line?.map((line) => {
issueFound =
issueFound +
"\n`" +
line +
"` " +
contentFile[line - 1]?.replace(
log.detected_content,
"[" +
log.detected_content +
"](https://logs.danielvu.com/logs/" +
fileName +
"#" +
line +
")"
);
});
content =
content +
"|" +
(index + 1) +
"|**" +
moment(log.created_at).format("HH:mm - DD/MM") +
"**|" +
item +
"|" +
log.line +
"|[View](https://logs.danielvu.com/logs/" +
fileName +
"#" +
log.line +
")\n";
});
// log.line?.map((line) => {
// issueFound =
// issueFound +
// "\n`" +
// line +
// "` " +
// contentFile[line - 1]?.replace(
// log.detected_content,
// "[" +
// log.detected_content +
// "](https://logs.danielvu.com/logs/" +
// fileName +
// "#" +
// line +
// ")"
// );
// });
// content =
// content +
// "|" +
// (index + 1) +
// "|**" +
// moment(log.created_at).format("HH:mm - DD/MM") +
// "**|" +
// item +
// "|" +
// log.line +
// "|[View](https://logs.danielvu.com/logs/" +
// fileName +
// "#" +
// log.line +
// ")\n";
// });
sendMessToZulip(
"stream",
"Result test - auto.nswteam.net",
"Log Alert",
"------------\n\n:warning: :warning: **" +
fileName +
"**\n\n" +
content +
"\n\n" +
spoiler +
"\n\n***Issue found:***\n" +
issueFound
);
// sendMessToZulip(
// "stream",
// "Result test - auto.nswteam.net",
// "Log Alert",
// "------------\n\n:warning: :warning: **" +
// fileName +
// "**\n\n" +
// content +
// "\n\n" +
// spoiler +
// "\n\n***Issue found:***\n" +
// issueFound
// );
sendMessToZulip(
"stream",
"AUS_VN_Test",
"Test Log Alerts",
"------------\n\n:warning: :warning: **" +
fileName +
"**\n\n" +
content +
"\n\n" +
spoiler +
"\n\n*Issue found:*\n" +
issueFound
);
}
await connection.disconnect()
}, 3000);
// sendMessToZulip(
// "stream",
// "AUS_VN_Test",
// "Test Log Alerts",
// "------------\n\n:warning: :warning: **" +
// fileName +
// "**\n\n" +
// content +
// "\n\n" +
// spoiler +
// "\n\n*Issue found:*\n" +
// issueFound
// );
// }
// }, 3000);
//false: next
}
);
@ -286,6 +285,7 @@ export async function runtimeCheckLogs(folderPath) {
scan.setMaxListeners(0);
});
}
} catch (error) {
console.log(error);
}