update interval time, create regex version special
This commit is contained in:
parent
d8efb4487f
commit
97a270777d
|
|
@ -1,3 +1,4 @@
|
||||||
|
import Env from "@ioc:Adonis/Core/Env";
|
||||||
// const axios = require("axios");
|
// const axios = require("axios");
|
||||||
// import fs from "fs";
|
// import fs from "fs";
|
||||||
|
|
||||||
|
|
@ -23,7 +24,8 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
||||||
?.split(":")[1]
|
?.split(":")[1]
|
||||||
?.replace("\r", "")
|
?.replace("\r", "")
|
||||||
.trim() !== "" &&
|
.trim() !== "" &&
|
||||||
SN !== "N/A" && SN.length>4 &&
|
SN !== "N/A" &&
|
||||||
|
SN.length > 4 &&
|
||||||
i >= beginLine
|
i >= beginLine
|
||||||
) {
|
) {
|
||||||
if (output.some((u) => u.SN === SN)) {
|
if (output.some((u) => u.SN === SN)) {
|
||||||
|
|
@ -170,10 +172,10 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
||||||
if (output.filter((i) => i.PID !== "").length > 0) {
|
if (output.filter((i) => i.PID !== "").length > 0) {
|
||||||
let token =
|
let token =
|
||||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5uc3d0ZWFtLm5ldC9hcGkvbG9naW4iLCJpYXQiOjE2ODkzOTEyMDMsImV4cCI6MTcyMDkyNzIwMywibmJmIjoxNjg5MzkxMjAzLCJqdGkiOiJreFA1MW9jck5rdEYzSzY3Iiwic3ViIjozNjkwLCJwcnYiOiJjOGVlMWZjODllNzc1ZWM0YzczODY2N2U1YmUxN2E1OTBiNmQ0MGZjIn0.p-aE0oWkKmdrcKWD94oSmMd_CMbY_4MoqADIwYIhIKw";
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwaS5uc3d0ZWFtLm5ldC9hcGkvbG9naW4iLCJpYXQiOjE2ODkzOTEyMDMsImV4cCI6MTcyMDkyNzIwMywibmJmIjoxNjg5MzkxMjAzLCJqdGkiOiJreFA1MW9jck5rdEYzSzY3Iiwic3ViIjozNjkwLCJwcnYiOiJjOGVlMWZjODllNzc1ZWM0YzczODY2N2U1YmUxN2E1OTBiNmQ0MGZjIn0.p-aE0oWkKmdrcKWD94oSmMd_CMbY_4MoqADIwYIhIKw";
|
||||||
|
|
||||||
let token_int =
|
let token_int =
|
||||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2ludC5pcHN1cHBseS5jb20uYXUvYXBpL2xvZ2luIiwiaWF0IjoxNjg5ODYyNjAxLCJleHAiOjE3MjEzOTg2MDEsIm5iZiI6MTY4OTg2MjYwMSwianRpIjoiUElZVjNBM3ZPQVlMQ081SyIsInN1YiI6MSwicHJ2IjoiYzhlZTFmYzg5ZTc3NWVjNGM3Mzg2NjdlNWJlMTdhNTkwYjZkNDBmYyJ9.UcybIKMBjTAY9i0PfIDQMtqHyN72Ul0jC03ZDGLGpMI";
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2ludC5pcHN1cHBseS5jb20uYXUvYXBpL2xvZ2luIiwiaWF0IjoxNjg5ODYyNjAxLCJleHAiOjE3MjEzOTg2MDEsIm5iZiI6MTY4OTg2MjYwMSwianRpIjoiUElZVjNBM3ZPQVlMQ081SyIsInN1YiI6MSwicHJ2IjoiYzhlZTFmYzg5ZTc3NWVjNGM3Mzg2NjdlNWJlMTdhNTkwYjZkNDBmYyJ9.UcybIKMBjTAY9i0PfIDQMtqHyN72Ul0jC03ZDGLGpMI";
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
data: output.filter((i) => i.PID !== ""),
|
data: output.filter((i) => i.PID !== ""),
|
||||||
urlAPI: "/api/test-log-serial-number/save-data",
|
urlAPI: "/api/test-log-serial-number/save-data",
|
||||||
|
|
@ -185,13 +187,15 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
||||||
{ headers: { Authorization: "Bearer " + token } }
|
{ headers: { Authorization: "Bearer " + token } }
|
||||||
);
|
);
|
||||||
|
|
||||||
const response_int = await axios.post(
|
if (Env.get("RUN_ENV") !== "prod") {
|
||||||
|
const response_int = await axios.post(
|
||||||
"https://int.ipsupply.com.au/api/transferPostData",
|
"https://int.ipsupply.com.au/api/transferPostData",
|
||||||
data,
|
data,
|
||||||
{ headers: { Authorization: "Bearer " + token_int } }
|
{ headers: { Authorization: "Bearer " + token_int } }
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(nameF + " response\n", response_int.data);
|
console.log(nameF + " response\n", response_int.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -29,38 +29,47 @@ const zulip = require("zulip-js");
|
||||||
// In ra nội dung của trang mới
|
// In ra nội dung của trang mới
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const tableData = await page.evaluate(() => {
|
const tableData = await page.evaluate(() => {
|
||||||
const tbody = document.querySelector('tbody'); // Lựa chọn thẻ <tbody> cần trích xuất
|
const tbody = document.querySelector("tbody"); // Lựa chọn thẻ <tbody> cần trích xuất
|
||||||
const rows = tbody.querySelectorAll('tr'); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
|
const rows = tbody.querySelectorAll("tr"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
|
||||||
|
|
||||||
// Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
|
// Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
|
||||||
const data = [];
|
const data = [];
|
||||||
rows.forEach((row) => {
|
rows.forEach((row) => {
|
||||||
const columns = Array.from(row.querySelectorAll('td')); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
|
const columns = Array.from(row.querySelectorAll("td")); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
|
||||||
const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
|
const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
|
||||||
data.push(rowData); // Thêm dữ liệu của hàng vào mảng data
|
data.push(rowData); // Thêm dữ liệu của hàng vào mảng data
|
||||||
});
|
});
|
||||||
|
|
||||||
return data.map(u=>u.join('\n\n'));
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Table data:', tableData);
|
|
||||||
|
|
||||||
await browser.close();
|
|
||||||
|
|
||||||
|
return data.map((u) => u.join("\n\n"));
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Table data:", tableData);
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
let params = {
|
||||||
|
type: "stream",
|
||||||
|
to: "networkToolBot",
|
||||||
|
topic: "powerSchedule",
|
||||||
|
content:
|
||||||
|
":warning: :date: :warning:\n\n" + tableData.join("\n\n") + "\n-------",
|
||||||
|
};
|
||||||
|
client.messages.send(params);
|
||||||
if (
|
if (
|
||||||
tableData.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B")).length > 0
|
tableData.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))
|
||||||
|
.length > 0
|
||||||
) {
|
) {
|
||||||
let params = {
|
let params = {
|
||||||
type: "stream",
|
type: "stream",
|
||||||
to: "Result test - auto.nswteam.net",
|
to: "Result test - auto.nswteam.net",
|
||||||
topic: "Lịch cúp điện",
|
topic: "Lịch cúp điện",
|
||||||
content:
|
content:
|
||||||
":warning: :date: :warning:\n\n" +
|
":warning: :date: :warning:\n\n" +
|
||||||
tableData.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0].replace(/KDC 91B/g,"**KDC 91B**") +
|
tableData
|
||||||
"\n-------",
|
.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0]
|
||||||
};
|
.replace(/KDC 91B/g, "**KDC 91B**") +
|
||||||
|
"\n-------",
|
||||||
|
};
|
||||||
client.messages.send(params);
|
client.messages.send(params);
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
})();
|
||||||
})();
|
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,26 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
const checkSpecialVersion = (paragraph) => {
|
const checkSpecialVersion = (paragraph) => {
|
||||||
try {
|
try {
|
||||||
const regex = /\(CAT3K_CAA-UNIVERSALK9-M\), Version 16\.9\.[2-9]/;
|
const regex = /\(CAT3K_CAA-UNIVERSALK9-M\), Version 16\.9\.[2-9]/;
|
||||||
const regex1 = /Version (\d+\.\d+\.\d+)/;
|
const regex1 =
|
||||||
|
/\(CAT3K_CAA-UNIVERSALK9-M\), Version 1[7-9]\.[0-9]\.[2-9]/;
|
||||||
|
const regex2 =
|
||||||
|
/\(CAT3K_CAA-UNIVERSALK9-M\), Version [2-9][0-9]\.[0-9]\.[2-9]/;
|
||||||
// Use the regular expression to find the match
|
// Use the regular expression to find the match
|
||||||
const match = paragraph.match(regex);
|
const match = paragraph.match(regex);
|
||||||
if (match) {
|
const match1 = paragraph.match(regex1);
|
||||||
const desiredSubstring = match[0];
|
const match2 = paragraph.match(regex2);
|
||||||
const match2 = desiredSubstring.match(regex1);
|
if (match || match1 || match2) {
|
||||||
return match2[0];
|
if (match) {
|
||||||
|
return match[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match1) {
|
||||||
|
return match1[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match2) {
|
||||||
|
return match2[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -60,8 +73,8 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
if (
|
if (
|
||||||
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] ===
|
||||||
//localhost
|
//localhost
|
||||||
// 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()
|
||||||
) {
|
) {
|
||||||
//add information file to database
|
//add information file to database
|
||||||
|
|
@ -92,6 +105,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
.map((file) => folderPath + "/" + file);
|
.map((file) => folderPath + "/" + file);
|
||||||
const watcher = chokidar.watch(listFileWatch, {
|
const watcher = chokidar.watch(listFileWatch, {
|
||||||
persistent: true,
|
persistent: true,
|
||||||
|
usePolling: true,
|
||||||
interval: 300000,
|
interval: 300000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -160,7 +174,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
for (let i = 0; i < contentFile.length; i += 1000) {
|
for (let i = 0; i < contentFile.length; i += 1000) {
|
||||||
const chunk = contentFile.slice(i, i + 1000);
|
const chunk = contentFile.slice(i, i + 1000);
|
||||||
|
|
||||||
chunk.map((line, index) => {
|
chunk.map(async (line, index) => {
|
||||||
//check line the line with errors and exclude errors
|
//check line the line with errors and exclude errors
|
||||||
listKeyValues
|
listKeyValues
|
||||||
.map((obj) => obj.$original.value)
|
.map((obj) => obj.$original.value)
|
||||||
|
|
@ -193,10 +207,36 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
// if(checkSpecialVersion())
|
// if(checkSpecialVersion())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
checkSpecialVersion(line) !== "" &&
|
||||||
|
listExcludeErr.filter((err) => line.includes(err)).length === 0
|
||||||
|
) {
|
||||||
|
let checkVersion = checkSpecialVersion(line);
|
||||||
|
let log = allFile?.filter(
|
||||||
|
(i) => i.$original.file_name === fileName
|
||||||
|
)[0];
|
||||||
|
|
||||||
|
let checkLog = allReport?.filter(
|
||||||
|
(report) =>
|
||||||
|
report.$original.id_file === log?.id_ldf &&
|
||||||
|
report.$original.line === index + 1 &&
|
||||||
|
report.$original.detected_content === checkVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
if (checkLog?.length === 0) {
|
||||||
|
await LogReport.create({
|
||||||
|
detected_content: checkVersion,
|
||||||
|
line: index + 1,
|
||||||
|
id_file: log?.id_ldf,
|
||||||
|
});
|
||||||
|
lines.push(index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
contentFile.map((line, index) => {
|
contentFile.map(async (line, index) => {
|
||||||
//check line the line with errors and exclude errors
|
//check line the line with errors and exclude errors
|
||||||
listKeyValues
|
listKeyValues
|
||||||
.map((obj) => obj.$original.value)
|
.map((obj) => obj.$original.value)
|
||||||
|
|
@ -217,7 +257,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
report.$original.line === index + 1 &&
|
report.$original.line === index + 1 &&
|
||||||
report.$original.detected_content === value
|
report.$original.detected_content === value
|
||||||
);
|
);
|
||||||
|
|
||||||
if (checkLog?.length === 0) {
|
if (checkLog?.length === 0) {
|
||||||
await LogReport.create({
|
await LogReport.create({
|
||||||
detected_content: value,
|
detected_content: value,
|
||||||
|
|
@ -230,6 +270,32 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
// if(checkSpecialVersion())
|
// if(checkSpecialVersion())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
checkSpecialVersion(line) !== "" &&
|
||||||
|
listExcludeErr.filter((err) => line.includes(err)).length === 0
|
||||||
|
) {
|
||||||
|
let checkVersion = checkSpecialVersion(line);
|
||||||
|
let log = allFile?.filter(
|
||||||
|
(i) => i.$original.file_name === fileName
|
||||||
|
)[0];
|
||||||
|
|
||||||
|
let checkLog = allReport?.filter(
|
||||||
|
(report) =>
|
||||||
|
report.$original.id_file === log?.id_ldf &&
|
||||||
|
report.$original.line === index + 1 &&
|
||||||
|
report.$original.detected_content === checkVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
if (checkLog?.length === 0) {
|
||||||
|
await LogReport.create({
|
||||||
|
detected_content: checkVersion,
|
||||||
|
line: index + 1,
|
||||||
|
id_file: log?.id_ldf,
|
||||||
|
});
|
||||||
|
lines.push(index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,7 +344,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
let important = [
|
let important = [
|
||||||
"Vxx",
|
"Vxx",
|
||||||
"V00",
|
"V00",
|
||||||
"(CAT3K_CAA-UNIVERSALK9-M), Version 16.9.",
|
"(CAT3K_CAA-UNIVERSALK9-M), Version",
|
||||||
];
|
];
|
||||||
listReport.map((log, index) => {
|
listReport.map((log, index) => {
|
||||||
let item = listExtraItem.includes(log.detected_content)
|
let item = listExtraItem.includes(log.detected_content)
|
||||||
|
|
@ -321,7 +387,9 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
let icon =
|
let icon =
|
||||||
important.filter((i) => content.includes(i)).length > 0
|
important.filter((i) => content.includes(i)).length > 0
|
||||||
? "------------\n\n:no_entry: :no_entry:**" + fileName + "**:no_entry: :no_entry:"
|
? "------------\n\n:no_entry: :no_entry:**" +
|
||||||
|
fileName +
|
||||||
|
"**:no_entry: :no_entry:"
|
||||||
: "------------\n\n:warning: :warning: **" + fileName + "**";
|
: "------------\n\n:warning: :warning: **" + fileName + "**";
|
||||||
sendMessToZulip(
|
sendMessToZulip(
|
||||||
"stream",
|
"stream",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,40 @@
|
||||||
let a = [1,2,3]
|
// let a = [1,2,3]
|
||||||
|
|
||||||
console.log(a.slice(0,4))
|
// console.log(a.slice(0,4))
|
||||||
|
|
||||||
|
const checkSpecialVersion = (paragraph) => {
|
||||||
|
try {
|
||||||
|
const regex = /\(CAT3K_CAA-UNIVERSALK9-M\), Version 16\.9\.[2-9]/;
|
||||||
|
const regex1 = /\(CAT3K_CAA-UNIVERSALK9-M\), Version 1[7-9]\.[0-9]\.[2-9]/;
|
||||||
|
const regex2 =
|
||||||
|
/\(CAT3K_CAA-UNIVERSALK9-M\), Version [2-9][0-9]\.[0-9]\.[2-9]/;
|
||||||
|
// Use the regular expression to find the match
|
||||||
|
const match = paragraph.match(regex);
|
||||||
|
const match1 = paragraph.match(regex1);
|
||||||
|
const match2 = paragraph.match(regex2);
|
||||||
|
if (match || match1 || match2) {
|
||||||
|
if (match) {
|
||||||
|
console.log(match[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match1) {
|
||||||
|
console.log(match1[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match2) {
|
||||||
|
console.log(match2[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
checkSpecialVersion(
|
||||||
|
"Cisco IOS Software [Fuji], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.9.1, RELEASE SOFTWARE (fc2)"
|
||||||
|
);
|
||||||
|
|
||||||
// const puppeteer = require("puppeteer");
|
// const puppeteer = require("puppeteer");
|
||||||
// const zulip = require("zulip-js");
|
// const zulip = require("zulip-js");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue