change runtimeCheckLog
This commit is contained in:
parent
b67c3a3580
commit
97c5c1285f
|
|
@ -1,4 +1,4 @@
|
||||||
import Env from '@ioc:Adonis/Core/Env';
|
import Env from "@ioc:Adonis/Core/Env";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import chokidar from "chokidar";
|
import chokidar from "chokidar";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
|
@ -8,7 +8,7 @@ import KeyValue from "App/Models/KeyValue";
|
||||||
import Database from "@ioc:Adonis/Lucid/Database";
|
import Database from "@ioc:Adonis/Lucid/Database";
|
||||||
import { sendMessToZulip } from "./sendMessToZulip";
|
import { sendMessToZulip } from "./sendMessToZulip";
|
||||||
import { getListLineByItem } from "./getListLineByItem";
|
import { getListLineByItem } from "./getListLineByItem";
|
||||||
import { checkIndexSN } from './checkIndexSN';
|
import { checkIndexSN } from "./checkIndexSN";
|
||||||
|
|
||||||
export async function runtimeCheckLogs(folderPath) {
|
export async function runtimeCheckLogs(folderPath) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -88,17 +88,21 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
// Watch for changes in the files listed
|
// Watch for changes in the files listed
|
||||||
async function watchFilesInList() {
|
async function watchFilesInList() {
|
||||||
//only check new file ---> fileList - fileList_old = new file
|
//only check new file ---> fileList - fileList_old = new file
|
||||||
await fileList.slice(0,20)
|
const watcher = chokidar.watch(
|
||||||
|
fileList
|
||||||
|
?.filter((i) => fileList_old.includes(i) === false)
|
||||||
|
.map((file) => folderPath + "/" + file)
|
||||||
|
);
|
||||||
|
await fileList
|
||||||
?.filter((i) => fileList_old.includes(i) === false)
|
?.filter((i) => fileList_old.includes(i) === false)
|
||||||
?.forEach((fileName) => {
|
?.forEach((fileName) => {
|
||||||
//path file
|
//path file
|
||||||
const filePath = `${folderPath}/${fileName}`;
|
const filePath = `${folderPath}/${fileName}`;
|
||||||
const scan = fs.watchFile(
|
watcher.on("change", async (path) => {
|
||||||
filePath,
|
// fs.watchFile(filePath,{ interval: 15000 },
|
||||||
{ interval: 15000 },
|
// async (eventType) => {
|
||||||
async (eventType) => {
|
//check special item, extra RAM, error in log
|
||||||
//check special item, extra RAM, error in log
|
if (path === filePath) {
|
||||||
|
|
||||||
let lines = [];
|
let lines = [];
|
||||||
let allFile = await LogDetectFile.all();
|
let allFile = await LogDetectFile.all();
|
||||||
let allReport = await LogReport.all();
|
let allReport = await LogReport.all();
|
||||||
|
|
@ -132,7 +136,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
|
|
||||||
//get index SN and send to ERP
|
//get index SN and send to ERP
|
||||||
|
|
||||||
checkIndexSN(contentFile, lastLine, fileName)
|
checkIndexSN(contentFile, lastLine, fileName);
|
||||||
|
|
||||||
//get list item to check
|
//get list item to check
|
||||||
let listKeyValues = allValue.filter(
|
let listKeyValues = allValue.filter(
|
||||||
|
|
@ -171,7 +175,12 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
// fileName
|
// fileName
|
||||||
// );
|
// );
|
||||||
//check report of line not exist
|
//check report of line not exist
|
||||||
let checkLog = allReport?.filter((report)=>report.$original.id_file === log?.id_ldf && report.$original.line === (index + 1) && report.$original.detected_content === value)
|
let checkLog = allReport?.filter(
|
||||||
|
(report) =>
|
||||||
|
report.$original.id_file === log?.id_ldf &&
|
||||||
|
report.$original.line === index + 1 &&
|
||||||
|
report.$original.detected_content === value
|
||||||
|
);
|
||||||
|
|
||||||
// await Database.rawQuery(
|
// await Database.rawQuery(
|
||||||
// "select * from log_reports where id_file = " +
|
// "select * from log_reports where id_file = " +
|
||||||
|
|
@ -220,7 +229,9 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
// );
|
// );
|
||||||
//Get all report newest
|
//Get all report newest
|
||||||
let listReport = await getListLineByItem(
|
let listReport = await getListLineByItem(
|
||||||
logsDetect.map((obj) => obj.$original).filter((l) => l.line > lastLine)
|
logsDetect
|
||||||
|
.map((obj) => obj.$original)
|
||||||
|
.filter((l) => l.line > lastLine)
|
||||||
);
|
);
|
||||||
|
|
||||||
let content =
|
let content =
|
||||||
|
|
@ -283,9 +294,7 @@ export async function runtimeCheckLogs(folderPath) {
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
scan.setMaxListeners(0);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
110
screenshot.js
110
screenshot.js
|
|
@ -1,63 +1,69 @@
|
||||||
const puppeteer = require("puppeteer");
|
let a = [1,2,3]
|
||||||
const zulip = require("zulip-js");
|
|
||||||
|
|
||||||
(async () => {
|
console.log(a.map(i=>i+1))
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
|
|
||||||
// Điều hướng đến trang web chứa thẻ <a>
|
|
||||||
await page.goto("https://www.cskh.evnspc.vn/TraCuu/LichNgungGiamCungCapDien");
|
|
||||||
|
|
||||||
// Tìm thẻ <a> cần click dựa trên selector CSS hoặc XPath
|
|
||||||
const selectBoxSelector1 = "select#idCongTyDienLuc";
|
|
||||||
await page.waitForSelector(selectBoxSelector1);
|
|
||||||
await page.select(selectBoxSelector1, "PB11");
|
|
||||||
|
|
||||||
// Chờ cho trang mới mở
|
// const puppeteer = require("puppeteer");
|
||||||
// await page.waitForNavigation('select#idCongTyDienLuc');
|
// const zulip = require("zulip-js");
|
||||||
|
|
||||||
// In ra nội dung của trang mới
|
// (async () => {
|
||||||
setTimeout(async () => {
|
// const browser = await puppeteer.launch();
|
||||||
const tableData = await page.evaluate(() => {
|
// const page = await browser.newPage();
|
||||||
const tbody = document.querySelector("table"); // 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 headerRow = document.querySelectorAll("thead"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
|
|
||||||
// Lấy tên các cột từ hàng đầu (thẻ <th>)
|
|
||||||
// const headerColumns = headerRow.querySelectorAll("tr");
|
|
||||||
// const columnNames = headerColumns.map((headerColumn) =>
|
|
||||||
// headerColumn.textContent.trim()
|
|
||||||
// );
|
|
||||||
const data1 = [];
|
|
||||||
// headerColumns.forEach((clo) => {
|
|
||||||
// const columns = Array.from(clo.querySelectorAll("th")); // 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
|
|
||||||
// data1.push(rowData); // Thêm dữ liệu của hàng vào mảng data
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
|
// // Điều hướng đến trang web chứa thẻ <a>
|
||||||
const data = [];
|
// await page.goto("https://www.cskh.evnspc.vn/TraCuu/LichNgungGiamCungCapDien");
|
||||||
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 headers = Array.from(row.querySelectorAll("th"));
|
|
||||||
const rowHeader = headers.map((header) => header.textContent.trim());
|
|
||||||
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
|
|
||||||
data1.push(rowHeader)
|
|
||||||
});
|
|
||||||
|
|
||||||
return { data: data, columnNames: data1 };
|
// // Tìm thẻ <a> cần click dựa trên selector CSS hoặc XPath
|
||||||
});
|
// const selectBoxSelector1 = "select#idCongTyDienLuc";
|
||||||
const content = []
|
// await page.waitForSelector(selectBoxSelector1);
|
||||||
tableData.data?.map((u,index)=>{
|
// await page.select(selectBoxSelector1, "PB11");
|
||||||
for(let i=0; i<u.length;i++){
|
|
||||||
tableData.data[index] = tableData.columnNames[index]+": "+u[]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
console.log("Table data:", );
|
|
||||||
|
|
||||||
await browser.close();
|
// // Chờ cho trang mới mở
|
||||||
}, 5000);
|
// // await page.waitForNavigation('select#idCongTyDienLuc');
|
||||||
})();
|
|
||||||
|
// // In ra nội dung của trang mới
|
||||||
|
// setTimeout(async () => {
|
||||||
|
// const tableData = await page.evaluate(() => {
|
||||||
|
// const tbody = document.querySelector("table"); // 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 headerRow = document.querySelectorAll("thead"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
|
||||||
|
// // Lấy tên các cột từ hàng đầu (thẻ <th>)
|
||||||
|
// // const headerColumns = headerRow.querySelectorAll("tr");
|
||||||
|
// // const columnNames = headerColumns.map((headerColumn) =>
|
||||||
|
// // headerColumn.textContent.trim()
|
||||||
|
// // );
|
||||||
|
// const data1 = [];
|
||||||
|
// // headerColumns.forEach((clo) => {
|
||||||
|
// // const columns = Array.from(clo.querySelectorAll("th")); // 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
|
||||||
|
// // data1.push(rowData); // Thêm dữ liệu của hàng vào mảng data
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// // 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 headers = Array.from(row.querySelectorAll("th"));
|
||||||
|
// const rowHeader = headers.map((header) => header.textContent.trim());
|
||||||
|
// 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
|
||||||
|
// data1.push(rowHeader)
|
||||||
|
// });
|
||||||
|
|
||||||
|
// return { data: data, columnNames: data1 };
|
||||||
|
// });
|
||||||
|
// const content = []
|
||||||
|
// tableData.data?.map((u,index)=>{
|
||||||
|
// for(let i=0; i<u.length;i++){
|
||||||
|
// tableData.data[index] = tableData.columnNames[index]+": "+u[]
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// console.log("Table data:", );
|
||||||
|
|
||||||
|
// await browser.close();
|
||||||
|
// }, 5000);
|
||||||
|
// })();
|
||||||
// console.log("data: ",
|
// console.log("data: ",
|
||||||
// data.paragraphText
|
// data.paragraphText
|
||||||
// .split(" ")
|
// .split(" ")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue