From ea3c357be1babbe111a704be20910dce689a6593 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 5 Aug 2024 14:58:52 -0600 Subject: [PATCH] refactor: Remove unused "Model" dependency from package.json files --- Accounts/package.json | 2 -- AdminDashboard/package.json | 1 - .../MonitorTelemetryMonitor.ts | 22 ++++++++++--- App/package-lock.json | 3 -- .../Monitor/Criteria/LogMonitorCriteria.ts | 31 +++++++++++++++++++ CommonServer/Utils/Monitor/MonitorResource.ts | 14 +++++++++ CommonServer/package.json | 2 -- CommonUI/package.json | 2 -- Copilot/package.json | 1 - Dashboard/package.json | 1 - .../Monitor/LogMonitor/LogMonitorStepFrom.tsx | 4 +-- Ingestor/package.json | 1 - Nginx/package-lock.json | 3 -- Probe/package-lock.json | 3 -- Scripts/package-lock.json | 3 -- StatusPage/package-lock.json | 5 --- 16 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 CommonServer/Utils/Monitor/Criteria/LogMonitorCriteria.ts diff --git a/Accounts/package.json b/Accounts/package.json index 3464474145..ecb278c1b8 100644 --- a/Accounts/package.json +++ b/Accounts/package.json @@ -27,14 +27,12 @@ }, "dependencies": { "Common": "file:../Common", - "CommonServer": "file:../CommonServer", "CommonUI": "file:../CommonUI", "css-loader": "^6.11.0", "dotenv": "^16.4.5", "express": "^4.19.2", "file-loader": "^6.2.0", - "Model": "file:../Model", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.23.1", diff --git a/AdminDashboard/package.json b/AdminDashboard/package.json index 1b3c1666ab..2d40546a23 100644 --- a/AdminDashboard/package.json +++ b/AdminDashboard/package.json @@ -9,7 +9,6 @@ "CommonUI": "file:../CommonUI", "dotenv": "^16.4.5", "file-loader": "^6.2.0", - "Model": "file:../Model", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.23.1", diff --git a/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts index 2739aad9ca..7663c5d6c9 100644 --- a/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts +++ b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts @@ -32,7 +32,7 @@ RunCron( query: { disableActiveMonitoring: false, disableActiveMonitoringBecauseOfScheduledMaintenanceEvent: false, - disableActiveMonitoringBecauseOfManualIncident: false, + disableActiveMonitoringBecauseOfManualIncident: false, monitorType: DatabaseQueryHelper.any([ MonitorType.Logs, @@ -104,7 +104,8 @@ RunCron( try { if ( !monitor.monitorSteps || - monitor.monitorSteps.data?.monitorStepsInstanceArray.length === 0 + !monitor.monitorSteps.data?.monitorStepsInstanceArray?.length || + monitor.monitorSteps.data.monitorStepsInstanceArray.length === 0 ) { logger.debug("Monitor has no steps. Skipping..."); continue; @@ -113,7 +114,7 @@ RunCron( monitorResponses.push( monitorTelemetryMonitor({ monitorStep: - monitor.monitorSteps.data?.monitorStepsInstanceArray[0]!, + monitor.monitorSteps.data!.monitorStepsInstanceArray[0]!, monitorType: monitor.monitorType!, monitorId: monitor.id!, }), @@ -135,7 +136,13 @@ RunCron( }, ); -const monitorTelemetryMonitor = async (data: { +type MonitorTelemetryMonitorFunction = (data: { + monitorStep: MonitorStep; + monitorType: MonitorType; + monitorId: ObjectID; +}) => Promise; + +const monitorTelemetryMonitor: MonitorTelemetryMonitorFunction = async (data: { monitorStep: MonitorStep; monitorType: MonitorType; monitorId: ObjectID; @@ -152,7 +159,12 @@ const monitorTelemetryMonitor = async (data: { throw new BadDataException("Monitor type is not supported"); }; -const monitorLogs = async (data: { +type MonitorLogsFunction = (data: { + monitorStep: MonitorStep; + monitorId: ObjectID; +}) => Promise; + +const monitorLogs: MonitorLogsFunction = async (data: { monitorStep: MonitorStep; monitorId: ObjectID; }): Promise => { diff --git a/App/package-lock.json b/App/package-lock.json index a31c462982..23ef020b3a 100644 --- a/App/package-lock.json +++ b/App/package-lock.json @@ -14,7 +14,6 @@ "CommonServer": "file:../CommonServer", "ejs": "^3.1.9", "handlebars": "^4.7.8", - "Model": "file:../Model", "nodemailer": "^6.9.7", "ts-node": "^10.9.1", "twilio": "^4.20.0", @@ -82,7 +81,6 @@ "airtable": "^0.12.2", "bullmq": "^5.3.3", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", @@ -94,7 +92,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "marked": "^12.0.2", - "Model": "file:../Model", "node-cron": "^3.0.3", "nodemailer": "^6.9.10", "pg": "^8.7.3", diff --git a/CommonServer/Utils/Monitor/Criteria/LogMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/LogMonitorCriteria.ts new file mode 100644 index 0000000000..3d55406d5f --- /dev/null +++ b/CommonServer/Utils/Monitor/Criteria/LogMonitorCriteria.ts @@ -0,0 +1,31 @@ +import DataToProcess from "../DataToProcess"; +import CompareCriteria from "./CompareCriteria"; +import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; +import LogMonitorResponse from "Common/Types/Monitor/LogMonitor/LogMonitorResponse"; + +export default class LogMonitorCriteria { + public static async isMonitorInstanceCriteriaFilterMet(input: { + dataToProcess: DataToProcess; + criteriaFilter: CriteriaFilter; + }): Promise { + // Server Monitoring Checks + + let threshold: number | string | undefined | null = + input.criteriaFilter.value; + + if (input.criteriaFilter.checkOn === CheckOn.LogCount) { + threshold = CompareCriteria.convertToNumber(threshold); + + const currentLogCount: number = + (input.dataToProcess as LogMonitorResponse).logCount || 0; + + return CompareCriteria.compareCriteriaNumbers({ + value: currentLogCount, + threshold: threshold as number, + criteriaFilter: input.criteriaFilter, + }); + } + + return null; + } +} diff --git a/CommonServer/Utils/Monitor/MonitorResource.ts b/CommonServer/Utils/Monitor/MonitorResource.ts index f68e8195aa..6089aad3e4 100644 --- a/CommonServer/Utils/Monitor/MonitorResource.ts +++ b/CommonServer/Utils/Monitor/MonitorResource.ts @@ -49,6 +49,7 @@ import MonitorProbe from "Common/Models/DatabaseModels/MonitorProbe"; import MonitorStatusTimeline from "Common/Models/DatabaseModels/MonitorStatusTimeline"; import OnCallDutyPolicy from "Common/Models/DatabaseModels/OnCallDutyPolicy"; import OneUptimeDate from "Common/Types/Date"; +import LogMonitorCriteria from "./Criteria/LogMonitorCriteria"; export default class MonitorResourceUtil { public static async monitorResource( @@ -1202,6 +1203,19 @@ export default class MonitorResourceUtil { } } + if (input.monitor.monitorType === MonitorType.Logs) { + // check server monitor + const logMonitorResult: string | null = + await LogMonitorCriteria.isMonitorInstanceCriteriaFilterMet({ + dataToProcess: input.dataToProcess, + criteriaFilter: input.criteriaFilter, + }); + + if (logMonitorResult) { + return logMonitorResult; + } + } + return null; } } diff --git a/CommonServer/package.json b/CommonServer/package.json index 15a3b0a29c..0b0dc1442e 100644 --- a/CommonServer/package.json +++ b/CommonServer/package.json @@ -32,7 +32,6 @@ "airtable": "^0.12.2", "bullmq": "^5.3.3", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", @@ -44,7 +43,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "marked": "^12.0.2", - "Model": "file:../Model", "node-cron": "^3.0.3", "nodemailer": "^6.9.10", "otpauth": "^9.3.1", diff --git a/CommonUI/package.json b/CommonUI/package.json index c5ffb76b20..fd52505687 100644 --- a/CommonUI/package.json +++ b/CommonUI/package.json @@ -32,12 +32,10 @@ "@types/react-highlight": "^0.12.8", "@types/react-syntax-highlighter": "^15.5.13", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "formik": "^2.4.6", "history": "^5.3.0", "jwt-decode": "^4.0.0", "lodash": "^4.17.21", - "Model": "file:../Model", "moment-timezone": "^0.5.45", "prop-types": "^15.8.1", "qrcode": "^1.5.3", diff --git a/Copilot/package.json b/Copilot/package.json index 99a69157fa..0af0d54c77 100644 --- a/Copilot/package.json +++ b/Copilot/package.json @@ -19,7 +19,6 @@ "CommonServer": "file:../CommonServer", "dotenv": "^16.4.5", - "Model": "file:../Model", "openai": "^4.52.5", "ts-node": "^10.9.1" }, diff --git a/Dashboard/package.json b/Dashboard/package.json index eac1740f05..64fcc3575a 100644 --- a/Dashboard/package.json +++ b/Dashboard/package.json @@ -36,7 +36,6 @@ "CommonUI": "file:../CommonUI", "dotenv": "^16.4.5", "file-loader": "^6.2.0", - "Model": "file:../Model", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.23.0", diff --git a/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx b/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx index a560dba2b0..a4bd244b0e 100644 --- a/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx +++ b/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx @@ -84,7 +84,7 @@ const LogMonitorStepForm: FunctionComponent = ( value: 86400, }, ], - title: "Monitor Last X Time of Logs", + title: "Monitor Logs for Last", isAdvancedFilter: true, }, { @@ -96,7 +96,7 @@ const LogMonitorStepForm: FunctionComponent = ( isAdvancedFilter: true, }, { - key: "telemetryServiceId", + key: "telemetryServiceIds", type: FieldType.MultiSelectDropdown, filterDropdownOptions: props.telemetryServices.map( (telemetryService: TelemetryService) => { diff --git a/Ingestor/package.json b/Ingestor/package.json index 59b726daf9..94bff8a1e5 100644 --- a/Ingestor/package.json +++ b/Ingestor/package.json @@ -19,7 +19,6 @@ "CommonServer": "file:../CommonServer", "ejs": "^3.1.10", - "Model": "file:../Model", "protobufjs": "^7.3.2", "ts-node": "^10.9.1" }, diff --git a/Nginx/package-lock.json b/Nginx/package-lock.json index ff0cb286aa..e20acb2e10 100644 --- a/Nginx/package-lock.json +++ b/Nginx/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "Common": "file:../Common", "CommonServer": "file:../CommonServer", - "Model": "file:../Model", "ts-node": "^10.9.1" }, "devDependencies": { @@ -67,7 +66,6 @@ "airtable": "^0.12.2", "bullmq": "^5.3.3", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", @@ -79,7 +77,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "marked": "^12.0.2", - "Model": "file:../Model", "node-cron": "^3.0.3", "nodemailer": "^6.9.10", "pg": "^8.7.3", diff --git a/Probe/package-lock.json b/Probe/package-lock.json index 71979dfb4c..c18cc5fc32 100644 --- a/Probe/package-lock.json +++ b/Probe/package-lock.json @@ -14,7 +14,6 @@ "Common": "file:../Common", "CommonServer": "file:../CommonServer", "ejs": "^3.1.10", - "Model": "file:../Model", "ping": "^0.4.4", "playwright": "^1.45.1", "ts-node": "^10.9.1" @@ -76,7 +75,6 @@ "airtable": "^0.12.2", "bullmq": "^5.3.3", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", @@ -88,7 +86,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "marked": "^12.0.2", - "Model": "file:../Model", "node-cron": "^3.0.3", "nodemailer": "^6.9.10", "pg": "^8.7.3", diff --git a/Scripts/package-lock.json b/Scripts/package-lock.json index 0f55928746..6e03e4291e 100644 --- a/Scripts/package-lock.json +++ b/Scripts/package-lock.json @@ -13,7 +13,6 @@ "CommonServer": "file:../CommonServer", "ejs": "^3.1.10", - "Model": "file:../Model", "ts-node": "^10.9.2" }, "devDependencies": { @@ -84,7 +83,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "markdown-it": "^13.0.1", - "Model": "file:../Model", "node-device-detector": "^2.0.0", "nodemailer": "^6.7.3", "nodemailer-express-handlebars": "^5.0.0", @@ -5715,7 +5713,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "markdown-it": "^13.0.1", - "Model": "file:../Model", "node-device-detector": "^2.0.0", "nodemailer": "^6.7.3", "nodemailer-express-handlebars": "^5.0.0", diff --git a/StatusPage/package-lock.json b/StatusPage/package-lock.json index 2137e3be3d..b726af4354 100644 --- a/StatusPage/package-lock.json +++ b/StatusPage/package-lock.json @@ -15,7 +15,6 @@ "dotenv": "^16.4.5", "express": "^4.19.2", "file-loader": "^6.2.0", - "Model": "file:../Model", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.23.1", @@ -4651,7 +4650,6 @@ "airtable": "^0.12.2", "bullmq": "^5.3.3", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "cookie-parser": "^1.4.6", "cors": "^2.8.5", "cron-parser": "^4.8.1", @@ -4663,7 +4661,6 @@ "json2csv": "^5.0.7", "jsonwebtoken": "^9.0.0", "marked": "^12.0.2", - "Model": "file:../Model", "node-cron": "^3.0.3", "nodemailer": "^6.9.10", "pg": "^8.7.3", @@ -12484,12 +12481,10 @@ "@types/react-highlight": "^0.12.8", "@types/react-syntax-highlighter": "^15.5.13", "Common": "file:../Common", - "CommonProject": "file:../CommonProject", "formik": "^2.4.6", "history": "^5.3.0", "jwt-decode": "^4.0.0", "lodash": "^4.17.21", - "Model": "file:../Model", "moment-timezone": "^0.5.45", "prop-types": "^15.8.1", "react": "^18.3.1",