From b1864b02a86dc4cc219217c507a4c15fa978a5d7 Mon Sep 17 00:00:00 2001 From: joseph le Date: Wed, 29 Nov 2023 08:19:10 +0700 Subject: [PATCH] update regex catch special version --- app/utils/runtimeCheckLogs.ts | 69 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/app/utils/runtimeCheckLogs.ts b/app/utils/runtimeCheckLogs.ts index a7e378d..6f9f85e 100644 --- a/app/utils/runtimeCheckLogs.ts +++ b/app/utils/runtimeCheckLogs.ts @@ -1,15 +1,14 @@ import Env from "@ioc:Adonis/Core/Env"; -import fs from "fs"; -import chokidar from "chokidar"; -import moment from "moment"; +import KeyValue from "App/Models/KeyValue"; import LogDetectFile from "App/Models/LogDetectFile"; import LogReport from "App/Models/LogReport"; -import KeyValue from "App/Models/KeyValue"; -import Database from "@ioc:Adonis/Lucid/Database"; -import { sendMessToZulip } from "./sendMessToZulip"; -import { getListLineByItem } from "./getListLineByItem"; -import { checkIndexSN } from "./checkIndexSN"; +import chokidar from "chokidar"; +import fs from "fs"; import { DateTime } from "luxon"; +import moment from "moment"; +import { checkIndexSN } from "./checkIndexSN"; +import { getListLineByItem } from "./getListLineByItem"; +import { sendMessToZulip } from "./sendMessToZulip"; export async function runtimeCheckLogs(folderPath) { try { let fileList = Array(); @@ -36,11 +35,11 @@ export async function runtimeCheckLogs(folderPath) { const checkSpecialVersion = (paragraph) => { try { - const regex = /\(CAT3K_CAA-UNIVERSALK9-M\), Version 16\.9\.[2-9]/; + const regex = /\(CAT[1-9]K.*Version 16\.9\.[2-9]/; const regex1 = - /\(CAT3K_CAA-UNIVERSALK9-M\), Version 1[7-9]\.[0-9]\.[0-9]/; + /\(CAT[1-9]K.*Version 1[7-9]\.[0-9]\.[0-9]/; const regex2 = - /\(CAT3K_CAA-UNIVERSALK9-M\), Version [2-9][0-9]\.[0-9]\.[0-9]/; + /\(CAT[1-9]K.*Version [2-9][0-9]\.[0-9]\.[0-9]/; // Use the regular expression to find the match const match = paragraph.match(regex); const match1 = paragraph.match(regex1); @@ -73,9 +72,9 @@ export async function runtimeCheckLogs(folderPath) { if ( filePath?.split(".")[filePath.split(".").length - 1] === "log" && filePath.split("/")[filePath.split("/").length - 1]?.split("-")[0] === - //localhost - // filePath.split("\\")[filePath.split("\\").length - 1]?.split("-")[0] === - moment(Date.now()).format("YYYYMMDD").toString() + //localhost + // filePath.split("\\")[filePath.split("\\").length - 1]?.split("-")[0] === + moment(Date.now()).format("YYYYMMDD").toString() ) { //add information file to database console.log("New file added: ", filePath); @@ -218,7 +217,7 @@ export async function runtimeCheckLogs(folderPath) { if ( checkSpecialVersion(line) !== "" && listExcludeErr.filter((err) => line.includes(err)).length === - 0 + 0 ) { let checkVersion = checkSpecialVersion(line); let log = allFile?.filter( @@ -255,7 +254,7 @@ export async function runtimeCheckLogs(folderPath) { listKeyValues .map((obj) => obj.$original.value) .map(async (value) => { - + if ( line.includes(value) && listExcludeErr.filter((err) => line.includes(err)) @@ -334,10 +333,10 @@ export async function runtimeCheckLogs(folderPath) { } else { console.log( fileName + - "has changed(" + - contentFile.length + - ") ---SOS---" + - lines.length + "has changed(" + + contentFile.length + + ") ---SOS---" + + lines.length ); let allReport_new = await LogReport.query().whereRaw( `DATE(created_at) = ?`, @@ -351,7 +350,7 @@ export async function runtimeCheckLogs(folderPath) { let logsDetect = allReport_new?.filter( (i) => i.$original.id_file === fileDetect?.id_ldf ); - + //Get all report newest let listReport = await getListLineByItem( logsDetect @@ -382,12 +381,12 @@ export async function runtimeCheckLogs(folderPath) { contentFile[line - 1]?.replace( log.detected_content, "[" + - log.detected_content + - "](https://logs.danielvu.com/logs/" + - fileName + - "#" + - line + - ")" + log.detected_content + + "](https://logs.danielvu.com/logs/" + + fileName + + "#" + + line + + ")" ); }); content = @@ -410,20 +409,20 @@ 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:" + fileName + + "**:no_entry: :no_entry:" : "------------\n\n:warning: :warning: **" + fileName + "**"; sendMessToZulip( "stream", Env.get("ZULIP_STREAM_ALERT"), Env.get("ZULIP_TOPIC_ALERT"), icon + - "\n\n" + - content + - "\n\n" + - spoiler + - "\n\n***Issue found:***\n" + - issueFound + "\n\n" + + content + + "\n\n" + + spoiler + + "\n\n***Issue found:***\n" + + issueFound ); } }, 3000);