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");
|
||||
// import fs from "fs";
|
||||
|
||||
|
|
@ -23,7 +24,8 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
|||
?.split(":")[1]
|
||||
?.replace("\r", "")
|
||||
.trim() !== "" &&
|
||||
SN !== "N/A" && SN.length>4 &&
|
||||
SN !== "N/A" &&
|
||||
SN.length > 4 &&
|
||||
i >= beginLine
|
||||
) {
|
||||
if (output.some((u) => u.SN === SN)) {
|
||||
|
|
@ -185,6 +187,7 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
|||
{ headers: { Authorization: "Bearer " + token } }
|
||||
);
|
||||
|
||||
if (Env.get("RUN_ENV") !== "prod") {
|
||||
const response_int = await axios.post(
|
||||
"https://int.ipsupply.com.au/api/transferPostData",
|
||||
data,
|
||||
|
|
@ -194,6 +197,7 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
|||
console.log(nameF + " response\n", response_int.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Can't connect to log server", error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,26 +29,34 @@ const zulip = require("zulip-js");
|
|||
// In ra nội dung của trang mới
|
||||
setTimeout(async () => {
|
||||
const tableData = await page.evaluate(() => {
|
||||
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 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>
|
||||
|
||||
// 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 = [];
|
||||
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
|
||||
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'));
|
||||
return data.map((u) => u.join("\n\n"));
|
||||
});
|
||||
|
||||
console.log('Table data:', tableData);
|
||||
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 (
|
||||
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 = {
|
||||
type: "stream",
|
||||
|
|
@ -56,11 +64,12 @@ const zulip = require("zulip-js");
|
|||
topic: "Lịch cúp điện",
|
||||
content:
|
||||
":warning: :date: :warning:\n\n" +
|
||||
tableData.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0].replace(/KDC 91B/g,"**KDC 91B**") +
|
||||
tableData
|
||||
.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0]
|
||||
.replace(/KDC 91B/g, "**KDC 91B**") +
|
||||
"\n-------",
|
||||
};
|
||||
client.messages.send(params);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
})();
|
||||
|
|
@ -37,13 +37,26 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
const checkSpecialVersion = (paragraph) => {
|
||||
try {
|
||||
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
|
||||
const match = paragraph.match(regex);
|
||||
const match1 = paragraph.match(regex1);
|
||||
const match2 = paragraph.match(regex2);
|
||||
if (match || match1 || match2) {
|
||||
if (match) {
|
||||
const desiredSubstring = match[0];
|
||||
const match2 = desiredSubstring.match(regex1);
|
||||
return match[0];
|
||||
}
|
||||
|
||||
if (match1) {
|
||||
return match1[0];
|
||||
}
|
||||
|
||||
if (match2) {
|
||||
return match2[0];
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -92,6 +105,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
.map((file) => folderPath + "/" + file);
|
||||
const watcher = chokidar.watch(listFileWatch, {
|
||||
persistent: true,
|
||||
usePolling: true,
|
||||
interval: 300000,
|
||||
});
|
||||
|
||||
|
|
@ -160,7 +174,7 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
for (let i = 0; i < contentFile.length; 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
|
||||
listKeyValues
|
||||
.map((obj) => obj.$original.value)
|
||||
|
|
@ -193,10 +207,36 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
// 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 {
|
||||
contentFile.map((line, index) => {
|
||||
contentFile.map(async (line, index) => {
|
||||
//check line the line with errors and exclude errors
|
||||
listKeyValues
|
||||
.map((obj) => obj.$original.value)
|
||||
|
|
@ -230,6 +270,32 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
// 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 = [
|
||||
"Vxx",
|
||||
"V00",
|
||||
"(CAT3K_CAA-UNIVERSALK9-M), Version 16.9.",
|
||||
"(CAT3K_CAA-UNIVERSALK9-M), Version",
|
||||
];
|
||||
listReport.map((log, index) => {
|
||||
let item = listExtraItem.includes(log.detected_content)
|
||||
|
|
@ -321,7 +387,9 @@ export async function runtimeCheckLogs(folderPath) {
|
|||
|
||||
let icon =
|
||||
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 + "**";
|
||||
sendMessToZulip(
|
||||
"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 zulip = require("zulip-js");
|
||||
|
|
|
|||
Loading…
Reference in New Issue