From d84cf5b8ec254b94068378d1da62c62a55e79580 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 16:41:07 -0600 Subject: [PATCH 1/7] refactor: Update LogSeverity enum to use string values instead of enum values This refactor updates the LogSeverity enum to use string values instead of enum values. This change allows for better compatibility and flexibility when working with log severity levels. The enum values have been replaced with corresponding string values. Files modified: - Common/Types/Log/LogSeverity.ts - Ingestor/API/OTelIngest.ts - Ingestor/API/FluentIngest.ts - Model/AnalyticsModels/Log.ts - CommonUI/src/Components/LogsViewer/LogItem.tsx - CommonUI/src/Components/LogsViewer/LogsViewer.tsx - CommonUI/src/Components/Filters/DropdownFilter.tsx - Common/Types/ObjectID.ts - CommonUI/src/Components/Filters/FiltersForm.tsx --- Common/Types/Log/LogSeverity.ts | 11 + Common/Types/Monitor/MonitorStep.ts | 16 + Common/Types/Monitor/MonitorStepLogMonitor.ts | 48 +++ Common/Types/Monitor/MonitorType.ts | 22 ++ Common/Types/ObjectID.ts | 12 + .../src/Components/Filters/DropdownFilter.tsx | 3 +- .../src/Components/Filters/FiltersForm.tsx | 4 + .../src/Components/LogsViewer/LogItem.tsx | 3 +- .../src/Components/LogsViewer/LogsFilters.tsx | 280 ------------------ .../src/Components/LogsViewer/LogsViewer.tsx | 3 +- CommonUI/src/Components/Types/FieldType.ts | 1 + .../Monitor/LogMonitor/LogMonitorStepFrom.tsx | 124 ++++++++ .../Components/Form/Monitor/MonitorStep.tsx | 125 +++++++- Ingestor/API/FluentIngest.ts | 3 +- Ingestor/API/OTelIngest.ts | 2 +- Model/AnalyticsModels/Log.ts | 11 +- 16 files changed, 372 insertions(+), 296 deletions(-) create mode 100644 Common/Types/Log/LogSeverity.ts create mode 100644 Common/Types/Monitor/MonitorStepLogMonitor.ts delete mode 100644 CommonUI/src/Components/LogsViewer/LogsFilters.tsx create mode 100644 Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx diff --git a/Common/Types/Log/LogSeverity.ts b/Common/Types/Log/LogSeverity.ts new file mode 100644 index 00000000000..d9c7ae22efe --- /dev/null +++ b/Common/Types/Log/LogSeverity.ts @@ -0,0 +1,11 @@ +enum LogSeverity { + Unspecified = "Unspecified", + Information = "Information", + Warning = "Warning", + Error = "Error", + Trace = "Trace", + Debug = "Debug", + Fatal = "Fatal", +} + +export default LogSeverity; diff --git a/Common/Types/Monitor/MonitorStep.ts b/Common/Types/Monitor/MonitorStep.ts index aa235b2f017..f4e6b78f680 100644 --- a/Common/Types/Monitor/MonitorStep.ts +++ b/Common/Types/Monitor/MonitorStep.ts @@ -10,6 +10,7 @@ import JSONFunctions from "../JSONFunctions"; import ObjectID from "../ObjectID"; import Port from "../Port"; import MonitorCriteria from "./MonitorCriteria"; +import MonitorStepLogMonitor, { MonitorStepLogMonitorUtil } from "./MonitorStepLogMonitor"; import MonitorType from "./MonitorType"; import BrowserType from "./SyntheticMonitors//BrowserType"; import ScreenSizeType from "./SyntheticMonitors/ScreenSizeType"; @@ -35,6 +36,9 @@ export interface MonitorStepType { // this is for synthetic monitors. screenSizeTypes?: Array | undefined; browserTypes?: Array | undefined; + + // Log monitor type. + logMonitor?: MonitorStepLogMonitor | undefined; } export default class MonitorStep extends DatabaseProperty { @@ -54,6 +58,7 @@ export default class MonitorStep extends DatabaseProperty { customCode: undefined, screenSizeTypes: undefined, browserTypes: undefined, + logMonitor: undefined, }; } @@ -77,6 +82,7 @@ export default class MonitorStep extends DatabaseProperty { customCode: undefined, screenSizeTypes: undefined, browserTypes: undefined, + logMonitor: undefined, }; return monitorStep; @@ -133,6 +139,11 @@ export default class MonitorStep extends DatabaseProperty { return this; } + public setLogMonitor(logMonitor: MonitorStepLogMonitor): MonitorStep { + this.data!.logMonitor = logMonitor; + return this; + } + public setCustomCode(customCode: string): MonitorStep { this.data!.customCode = customCode; return this; @@ -157,6 +168,7 @@ export default class MonitorStep extends DatabaseProperty { customCode: undefined, screenSizeTypes: undefined, browserTypes: undefined, + lgoMonitor: undefined, }, }; } @@ -240,6 +252,7 @@ export default class MonitorStep extends DatabaseProperty { customCode: this.data.customCode || undefined, screenSizeTypes: this.data.screenSizeTypes || undefined, browserTypes: this.data.browserTypes || undefined, + logMonitor: this.data.logMonitor ? MonitorStepLogMonitorUtil.toJSON(this.data.logMonitor) : undefined, }, }); } @@ -328,6 +341,9 @@ export default class MonitorStep extends DatabaseProperty { screenSizeTypes: (json["screenSizeTypes"] as Array) || undefined, browserTypes: (json["browserTypes"] as Array) || undefined, + logMonitor: json["logMonitor"] + ? (json["logMonitor"] as JSONObject) + : undefined, }) as any; return monitorStep; diff --git a/Common/Types/Monitor/MonitorStepLogMonitor.ts b/Common/Types/Monitor/MonitorStepLogMonitor.ts new file mode 100644 index 00000000000..63242cdfcea --- /dev/null +++ b/Common/Types/Monitor/MonitorStepLogMonitor.ts @@ -0,0 +1,48 @@ +import Dictionary from "../Dictionary"; +import { JSONObject } from "../JSON"; +import LogSeverity from "../Log/LogSeverity"; +import ObjectID from "../ObjectID"; + +export default interface MonitorStepLogMonitor { + attributes: Dictionary; + body: string; + severityText: Array; + telemetryServiceId: Array; + lastXSecondsOfLogs: number; +} + +export class MonitorStepLogMonitorUtil { + + public static getDefault(): MonitorStepLogMonitor { + return { + attributes: {}, + body: "", + severityText: [], + telemetryServiceId: [], + lastXSecondsOfLogs: 60, + }; + } + + public static fromJSON(json: JSONObject): MonitorStepLogMonitor { + return { + attributes: + (json["attributes"] as Dictionary) || {}, + body: json["body"] as string, + severityText: json["severityText"] as Array, + telemetryServiceId: ObjectID.fromJSONArray( + json["telemetryServiceId"] as Array, + ), + lastXSecondsOfLogs: json["lastXSecondsOfLogs"] as number, + }; + } + + public static toJSON(monitor: MonitorStepLogMonitor): JSONObject { + return { + attributes: monitor.attributes, + body: monitor.body, + severityText: monitor.severityText, + telemetryServiceId: ObjectID.toJSONArray(monitor.telemetryServiceId), + lastXSecondsOfLogs: monitor.lastXSecondsOfLogs, + }; + } +} diff --git a/Common/Types/Monitor/MonitorType.ts b/Common/Types/Monitor/MonitorType.ts index 07f97fb0d88..0b6060c44e0 100644 --- a/Common/Types/Monitor/MonitorType.ts +++ b/Common/Types/Monitor/MonitorType.ts @@ -15,6 +15,11 @@ enum MonitorType { // These two monitor types are same but we are keeping them separate for now - this is for marketing purposes SyntheticMonitor = "Synthetic Monitor", CustomJavaScriptCode = "Custom JavaScript Code", + + // Telemetry monitor types + Logs = "Logs", + Metrics = "Metrics", + Traces = "Traces", } export default MonitorType; @@ -99,6 +104,23 @@ export class MonitorTypeHelper { description: "This monitor type lets you run custom JavaScript code on a schedule.", }, + { + monitorType: MonitorType.Logs, + title: "Logs", + description: "This monitor type lets you monitor logs from any source.", + }, + { + monitorType: MonitorType.Metrics, + title: "Metrics", + description: + "This monitor type lets you monitor metrics from any source.", + }, + { + monitorType: MonitorType.Traces, + title: "Traces", + description: + "This monitor type lets you monitor traces from any source.", + }, ]; return monitorTypeProps; diff --git a/Common/Types/ObjectID.ts b/Common/Types/ObjectID.ts index 0a8bca20a75..49aa32beb6d 100644 --- a/Common/Types/ObjectID.ts +++ b/Common/Types/ObjectID.ts @@ -47,6 +47,12 @@ export default class ObjectID extends DatabaseProperty { return new this(UUID.generate()); } + public static toJSONArray(ids: Array): Array { + return ids.map((id: ObjectID) => { + return id.toJSON(); + }); + } + protected static override toDatabase( value: ObjectID | FindOperator, ): string | null { @@ -76,6 +82,12 @@ export default class ObjectID extends DatabaseProperty { throw new BadDataException("Invalid JSON: " + JSON.stringify(json)); } + public static fromJSONArray(json: Array): Array { + return json.map((value: JSONObject) => { + return ObjectID.fromJSON(value); + }); + } + protected static override fromDatabase(_value: string): ObjectID | null { if (_value) { return new ObjectID(_value); diff --git a/CommonUI/src/Components/Filters/DropdownFilter.tsx b/CommonUI/src/Components/Filters/DropdownFilter.tsx index da1fe59f078..046160d98ce 100644 --- a/CommonUI/src/Components/Filters/DropdownFilter.tsx +++ b/CommonUI/src/Components/Filters/DropdownFilter.tsx @@ -9,6 +9,7 @@ export interface ComponentProps { filter: Filter; onFilterChanged?: undefined | ((filterData: FilterData) => void); filterData: FilterData; + isMultiSelect?: boolean | undefined; } type DropdownFilterFunction = ( @@ -50,7 +51,7 @@ const DropdownFilter: DropdownFilterFunction = ( } }} value={dropdownValue} - isMultiSelect={false} + isMultiSelect={props.isMultiSelect || false} placeholder={`Filter by ${filter.title}`} /> ); diff --git a/CommonUI/src/Components/Filters/FiltersForm.tsx b/CommonUI/src/Components/Filters/FiltersForm.tsx index 5c824643c33..7a789ea4c16 100644 --- a/CommonUI/src/Components/Filters/FiltersForm.tsx +++ b/CommonUI/src/Components/Filters/FiltersForm.tsx @@ -2,6 +2,7 @@ import Button, { ButtonStyleType } from "../Button/Button"; import ComponentLoader from "../ComponentLoader/ComponentLoader"; import ErrorMessage from "../ErrorMessage/ErrorMessage"; import FieldLabelElement from "../Forms/Fields/FieldLabel"; +import FieldType from "../Types/FieldType"; import BooleanFilter from "./BooleanFilter"; import DateFilter from "./DateFilter"; import DropdownFilter from "./DropdownFilter"; @@ -74,6 +75,9 @@ const FiltersForm: FiltersFormFunction = ( filter={filter} filterData={props.filterData} onFilterChanged={changeFilterData} + isMultiSelect={ + filter.type === FieldType.MultiSelectDropdown + } /> void; - onAutoScrollChanged: (turnOnAutoScroll: boolean) => void; - // telemetryServices?: Array; -} - -const LogsFilters: FunctionComponent = ( - props: ComponentProps, -): ReactElement => { - const [filterOptions, setFilterOptions] = React.useState({}); - - const [turnOnAutoScroll, setTurnOnAutoScroll] = React.useState(true); - const [showMoreFilters, setShowMoreFilters] = React.useState(false); - const [isSqlQuery] = React.useState(false); - - const showAutoScrollButton: boolean = - !isSqlQuery && !showMoreFilters && !filterOptions.searchText; - const showSearchButton: boolean = Boolean( - showMoreFilters || filterOptions.searchText, - ); - - return ( -
-
-
-
-
- {!isSqlQuery && ( -
-
- - { - setFilterOptions({ - ...filterOptions, - searchText: value, - }); - }} - /> -
- - {showMoreFilters && ( -
- - | null, - ) => { - if (value === null) { - setFilterOptions({ - ...filterOptions, - logSeverity: undefined, - }); - } else { - setFilterOptions({ - ...filterOptions, - logSeverity: value.toString() as LogSeverity, - }); - } - }} - options={DropdownUtil.getDropdownOptionsFromEnum( - LogSeverity, - )} - /> -
- )} - - {showMoreFilters && ( -
-
- - { - setFilterOptions({ - ...filterOptions, - startTime: value - ? OneUptimeDate.fromString(value) - : undefined, - }); - }} - type={InputType.DATETIME_LOCAL} - /> - {filterOptions.endTime && !filterOptions.startTime && ( - - )} -
-
- - { - setFilterOptions({ - ...filterOptions, - endTime: value - ? OneUptimeDate.fromString(value) - : undefined, - }); - }} - type={InputType.DATETIME_LOCAL} - /> - {filterOptions.startTime && !filterOptions.endTime && ( - - )} -
-
- )} -
- )} - {isSqlQuery && ( -
-
- - { - setFilterOptions({ - searchText: value, - }); - }} - showLineNumbers={true} - /> -
-
- )} -
- {showAutoScrollButton && ( -
-
- {!turnOnAutoScroll && ( -
-
- )} - {isSqlQuery && ( -
-
-
-
- )} - {showSearchButton && ( -
-
-
-
- )} -
-
- -
-
-
- {!isSqlQuery && ( -
- {!showMoreFilters && ( -
- )} -
- {/* {!isSqlQuery && ( -
-
-
- {/*
-
-
-
*/} -
-
-
-
-
- ); -}; - -export default LogsFilters; diff --git a/CommonUI/src/Components/LogsViewer/LogsViewer.tsx b/CommonUI/src/Components/LogsViewer/LogsViewer.tsx index 8420bd3b268..a24fcef9beb 100644 --- a/CommonUI/src/Components/LogsViewer/LogsViewer.tsx +++ b/CommonUI/src/Components/LogsViewer/LogsViewer.tsx @@ -5,7 +5,8 @@ import FiltersForm from "../Filters/FiltersForm"; import FieldType from "../Types/FieldType"; import LogItem from "./LogItem"; import { PromiseVoidFunction, VoidFunction } from "Common/Types/FunctionTypes"; -import Log, { LogSeverity } from "Model/AnalyticsModels/Log"; +import Log from "Model/AnalyticsModels/Log"; +import LogSeverity from "Common/Types/Log/LogSeverity"; import React, { FunctionComponent, ReactElement, Ref } from "react"; import Toggle from "../Toggle/Toggle"; import Card from "../Card/Card"; diff --git a/CommonUI/src/Components/Types/FieldType.ts b/CommonUI/src/Components/Types/FieldType.ts index e717cf89328..1f9ffd5a999 100644 --- a/CommonUI/src/Components/Types/FieldType.ts +++ b/CommonUI/src/Components/Types/FieldType.ts @@ -11,6 +11,7 @@ enum FieldType { Number = "Number", Password = "Password", Dropdown = "Dropdown", + MultiSelectDropdown = "MultiSelectDropdown", Text = "Text", Email = "Email", Date = "Date", diff --git a/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx b/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx new file mode 100644 index 00000000000..8f42e83003c --- /dev/null +++ b/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx @@ -0,0 +1,124 @@ +import LogSeverity from "Common/Types/Log/LogSeverity"; +import MonitorStepLogMonitor from "Common/Types/Monitor/MonitorStepLogMonitor"; +import FiltersForm from "CommonUI/src/Components/Filters/FiltersForm"; +import FieldType from "CommonUI/src/Components/Types/FieldType"; +import Query from "CommonUI/src/Utils/BaseDatabase/Query"; +import DropdownUtil from "CommonUI/src/Utils/Dropdown"; +import TelemetryService from "Model/Models/TelemetryService"; +import React, { FunctionComponent, ReactElement } from "react"; + +export interface ComponentProps { + monitorStepLogMonitor: MonitorStepLogMonitor; + onMonitorStepLogMonitorChanged: ( + monitorStepLogMonitor: MonitorStepLogMonitor, + ) => void; + attributeKeys: Array; + telemetryServices: Array; +} + +const LogMonitorStepForm: FunctionComponent = ( + props: ComponentProps, +): ReactElement => { + return ( + + id="logs-filter" + showFilter={true} + filterData={props.monitorStepLogMonitor} + onFilterChanged={(filterData: Query) => { + props.onMonitorStepLogMonitorChanged( + filterData as MonitorStepLogMonitor, + ); + }} + filters={[ + { + key: "body", + type: FieldType.Text, + title: "Search Log Body", + }, + { + key: "lastXSecondsOfLogs", + type: FieldType.Dropdown, + filterDropdownOptions: [ + { + label: "Last 5 seconds", + value: 5, + }, + { + label: "Last 10 seconds", + value: 10, + }, + { + label: "Last 30 seconds", + value: 30, + }, + { + label: "Last 1 minute", + value: 60, + }, + { + label: "Last 5 minutes", + value: 300, + }, + { + label: "Last 15 minutes", + value: 900, + }, + { + label: "Last 30 minutes", + value: 1800, + }, + { + label: "Last 1 hour", + value: 3600, + }, + { + label: "Last 6 hours", + value: 21600, + }, + { + label: "Last 12 hours", + value: 43200, + }, + { + label: "Last 24 hours", + value: 86400, + }, + ], + title: "Check Last X Seconds of Logs", + isAdvancedFilter: true, + }, + { + key: "severityText", + filterDropdownOptions: + DropdownUtil.getDropdownOptionsFromEnum(LogSeverity), + type: FieldType.MultiSelectDropdown, + title: "Log Severity", + isAdvancedFilter: true, + }, + { + key: "telemetryServiceId", + type: FieldType.MultiSelectDropdown, + filterDropdownOptions: props.telemetryServices.map( + (telemetryService: TelemetryService) => { + return { + label: telemetryService.name!, + value: telemetryService.id?.toString() || "", + }; + }, + ), + title: "Filter by Telemetry Service", + isAdvancedFilter: true, + }, + { + key: "attributes", + type: FieldType.JSON, + title: "Filter by Attributes", + jsonKeys: props.attributeKeys, + isAdvancedFilter: true, + }, + ]} + /> + ); +}; + +export default LogMonitorStepForm; diff --git a/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx b/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx index 14b514c3697..40afb39c3ac 100644 --- a/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx +++ b/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx @@ -8,6 +8,7 @@ import Exception from "Common/Types/Exception/Exception"; import IP from "Common/Types/IP/IP"; import MonitorCriteria from "Common/Types/Monitor/MonitorCriteria"; import MonitorStep from "Common/Types/Monitor/MonitorStep"; +import MonitorStepLogMonitor, { MonitorStepLogMonitorUtil } from "Common/Types/Monitor/MonitorStepLogMonitor"; import MonitorType from "Common/Types/Monitor/MonitorType"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; import Port from "Common/Types/Port"; @@ -27,7 +28,7 @@ import FieldLabelElement from "CommonUI/src/Components/Forms/Fields/FieldLabel"; import HorizontalRule from "CommonUI/src/Components/HorizontalRule/HorizontalRule"; import Input from "CommonUI/src/Components/Input/Input"; import Link from "CommonUI/src/Components/Link/Link"; -import { DOCS_URL } from "CommonUI/src/Config"; +import { APP_API_URL, DOCS_URL } from "CommonUI/src/Config"; import DropdownUtil from "CommonUI/src/Utils/Dropdown"; import React, { FunctionComponent, @@ -35,6 +36,19 @@ import React, { useEffect, useState, } from "react"; +import LogMonitorStepForm from "./LogMonitor/LogMonitorStepFrom"; +import TelemetryService from "Model/Models/TelemetryService"; +import ModelAPI, { ListResult } from "CommonUI/src/Utils/ModelAPI/ModelAPI"; +import DashboardNavigation from "../../../Utils/Navigation"; +import { LIMIT_PER_PROJECT } from "Common/Types/Database/LimitMax"; +import SortOrder from "Common/Types/BaseDatabase/SortOrder"; +import HTTPErrorResponse from "Common/Types/API/HTTPErrorResponse"; +import API from "CommonUI/src/Utils/API/API"; +import HTTPResponse from "Common/Types/API/HTTPResponse"; +import { JSONObject } from "Common/Types/JSON"; +import ComponentLoader from "CommonUI/src/Components/ComponentLoader/ComponentLoader"; +import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; +import { PromiseVoidFunction } from "Common/Types/FunctionTypes"; export interface ComponentProps { monitorStatusDropdownOptions: Array; @@ -58,12 +72,90 @@ const MonitorStepElement: FunctionComponent = ( props.initialValue || new MonitorStep(), ); + const [telemetryServices, setTelemetryServices] = useState< + Array + >([]); + const [attributeKeys, setAttributeKeys] = useState>([]); + const [error, setError] = useState(""); + const [isLoading, setIsLoading] = useState(true); + useEffect(() => { if (props.onChange && monitorStep) { props.onChange(monitorStep); } }, [monitorStep]); + const fetchLogAttributes: PromiseVoidFunction = async (): Promise => { + const attributeRepsonse: HTTPResponse | HTTPErrorResponse = + await API.post( + URL.fromString(APP_API_URL.toString()).addRoute( + "/telemetry/logs/get-attributes", + ), + {}, + { + ...ModelAPI.getCommonHeaders(), + }, + ); + + if (attributeRepsonse instanceof HTTPErrorResponse) { + throw attributeRepsonse; + } else { + const attributes: Array = attributeRepsonse.data[ + "attributes" + ] as Array; + setAttributeKeys(attributes); + } + }; + + const fetchTelemetryServices: PromiseVoidFunction = + async (): Promise => { + const telemetryServicesResult: ListResult = + await ModelAPI.getList({ + modelType: TelemetryService, + query: { + projectId: DashboardNavigation.getProjectId(), + }, + limit: LIMIT_PER_PROJECT, + skip: 0, + select: { + _id: true, + name: true, + }, + sort: { + name: SortOrder.Ascending, + }, + }); + + if (telemetryServicesResult instanceof HTTPErrorResponse) { + throw telemetryServicesResult; + } + + setTelemetryServices(telemetryServicesResult.data); + }; + + const fetchTelemetryServicesAndAttributes: PromiseVoidFunction = + async (): Promise => { + setIsLoading(true); + setError(""); + try { + await fetchTelemetryServices(); + + if (props.monitorType === MonitorType.Logs) { + await fetchLogAttributes(); + } + } catch (err) { + setError(API.getFriendlyErrorMessage(err as Error)); + } + + setIsLoading(false); + }; + + useEffect(() => { + fetchTelemetryServicesAndAttributes().catch((err: Error) => { + setError(API.getFriendlyErrorMessage(err as Error)); + }); + }, [props.monitorType]); + const [errors, setErrors] = useState>({}); const [touched, setTouched] = useState>({}); @@ -158,6 +250,14 @@ const MonitorStepElement: FunctionComponent = ( props.monitorType === MonitorType.CustomJavaScriptCode || props.monitorType === MonitorType.SyntheticMonitor; + if (isLoading) { + return ; + } + + if (error) { + return ; + } + return (
{hasMonitorDestination && ( @@ -267,6 +367,29 @@ const MonitorStepElement: FunctionComponent = (
)} + {props.monitorType === MonitorType.Logs && ( +
+ + { + monitorStep.setLogMonitor(value); + setMonitorStep(MonitorStep.clone(monitorStep)); + }} + attributeKeys={attributeKeys} + telemetryServices={telemetryServices} + /> +
+ )} + {props.monitorType === MonitorType.API && (
Date: Sun, 4 Aug 2024 17:29:38 -0600 Subject: [PATCH 2/7] refactor: Update LogSeverity enum to use string values instead of enum values --- Common/Types/Monitor/CriteriaFilter.ts | 3 ++ .../Types/Monitor/MonitorCriteriaInstance.ts | 54 +++++++++++++++++++ Common/Types/Monitor/MonitorStep.ts | 18 ++++++- Common/Types/Monitor/MonitorStepLogMonitor.ts | 1 - Common/Types/Monitor/MonitorType.ts | 3 ++ Common/Types/ObjectID.ts | 3 ++ .../Monitor/LogMonitor/LogMonitorStepFrom.tsx | 2 +- .../Components/Form/Monitor/MonitorStep.tsx | 51 +++++++++--------- .../src/Utils/Form/Monitor/CriteriaFilter.ts | 21 ++++++++ Ingestor/API/OTelIngest.ts | 3 +- 10 files changed, 130 insertions(+), 29 deletions(-) diff --git a/Common/Types/Monitor/CriteriaFilter.ts b/Common/Types/Monitor/CriteriaFilter.ts index 1c21437bae4..2a6c1df9f8f 100644 --- a/Common/Types/Monitor/CriteriaFilter.ts +++ b/Common/Types/Monitor/CriteriaFilter.ts @@ -34,6 +34,9 @@ export enum CheckOn { ScreenSizeType = "Screen Size", BrowserType = "Browser Type", + + // Log monitors. + LogCount = "Log Count", } export interface ServerMonitorOptions { diff --git a/Common/Types/Monitor/MonitorCriteriaInstance.ts b/Common/Types/Monitor/MonitorCriteriaInstance.ts index 2aad09e65be..1fcffe56d99 100644 --- a/Common/Types/Monitor/MonitorCriteriaInstance.ts +++ b/Common/Types/Monitor/MonitorCriteriaInstance.ts @@ -80,6 +80,31 @@ export default class MonitorCriteriaInstance extends DatabaseProperty { return monitorCriteriaInstance; } + if (arg.monitorType === MonitorType.Logs) { + const monitorCriteriaInstance: MonitorCriteriaInstance = + new MonitorCriteriaInstance(); + + monitorCriteriaInstance.data = { + id: ObjectID.generate().toString(), + monitorStatusId: arg.monitorStatusId, + filterCondition: FilterCondition.Any, + filters: [ + { + checkOn: CheckOn.LogCount, + filterType: FilterType.GreaterThan, + value: 0, // if there are some logs then monitor is online. + }, + ], + incidents: [], + changeMonitorStatus: true, + createIncidents: false, + name: `Check if ${arg.monitorName} is online`, + description: `This criteria checks if the ${arg.monitorName} is online`, + }; + + return monitorCriteriaInstance; + } + if (arg.monitorType === MonitorType.SSLCertificate) { const monitorCriteriaInstance: MonitorCriteriaInstance = new MonitorCriteriaInstance(); @@ -283,6 +308,35 @@ export default class MonitorCriteriaInstance extends DatabaseProperty { }; } + if (arg.monitorType === MonitorType.Logs) { + monitorCriteriaInstance.data = { + id: ObjectID.generate().toString(), + monitorStatusId: arg.monitorStatusId, + filterCondition: FilterCondition.Any, + filters: [ + { + checkOn: CheckOn.LogCount, + filterType: FilterType.EqualTo, + value: 0, // if there are no logs then the monitor is offline + }, + ], + incidents: [ + { + title: `${arg.monitorName} is offline`, + description: `${arg.monitorName} is currently offline.`, + incidentSeverityId: arg.incidentSeverityId, + autoResolveIncident: true, + id: ObjectID.generate().toString(), + onCallPolicyIds: [], + }, + ], + changeMonitorStatus: true, + createIncidents: true, + name: `Check if ${arg.monitorName} is offline`, + description: `This criteria checks if the ${arg.monitorName} is offline`, + }; + } + if (arg.monitorType === MonitorType.IncomingRequest) { monitorCriteriaInstance.data = { id: ObjectID.generate().toString(), diff --git a/Common/Types/Monitor/MonitorStep.ts b/Common/Types/Monitor/MonitorStep.ts index f4e6b78f680..86358f44725 100644 --- a/Common/Types/Monitor/MonitorStep.ts +++ b/Common/Types/Monitor/MonitorStep.ts @@ -10,7 +10,9 @@ import JSONFunctions from "../JSONFunctions"; import ObjectID from "../ObjectID"; import Port from "../Port"; import MonitorCriteria from "./MonitorCriteria"; -import MonitorStepLogMonitor, { MonitorStepLogMonitorUtil } from "./MonitorStepLogMonitor"; +import MonitorStepLogMonitor, { + MonitorStepLogMonitorUtil, +} from "./MonitorStepLogMonitor"; import MonitorType from "./MonitorType"; import BrowserType from "./SyntheticMonitors//BrowserType"; import ScreenSizeType from "./SyntheticMonitors/ScreenSizeType"; @@ -194,6 +196,16 @@ export default class MonitorStep extends DatabaseProperty { return "Monitor Destination is required."; } + if (monitorType === MonitorType.Logs) { + if (!value.data.logMonitor) { + return "Log Monitor is required"; + } + + if (!value.data.logMonitor.lastXSecondsOfLogs) { + return "Monitor Last Minutes of Logs is required."; + } + } + if ( !value.data.customCode && (monitorType === MonitorType.CustomJavaScriptCode || @@ -252,7 +264,9 @@ export default class MonitorStep extends DatabaseProperty { customCode: this.data.customCode || undefined, screenSizeTypes: this.data.screenSizeTypes || undefined, browserTypes: this.data.browserTypes || undefined, - logMonitor: this.data.logMonitor ? MonitorStepLogMonitorUtil.toJSON(this.data.logMonitor) : undefined, + logMonitor: this.data.logMonitor + ? MonitorStepLogMonitorUtil.toJSON(this.data.logMonitor) + : undefined, }, }); } diff --git a/Common/Types/Monitor/MonitorStepLogMonitor.ts b/Common/Types/Monitor/MonitorStepLogMonitor.ts index 63242cdfcea..eccdec0cf4d 100644 --- a/Common/Types/Monitor/MonitorStepLogMonitor.ts +++ b/Common/Types/Monitor/MonitorStepLogMonitor.ts @@ -12,7 +12,6 @@ export default interface MonitorStepLogMonitor { } export class MonitorStepLogMonitorUtil { - public static getDefault(): MonitorStepLogMonitor { return { attributes: {}, diff --git a/Common/Types/Monitor/MonitorType.ts b/Common/Types/Monitor/MonitorType.ts index 0b6060c44e0..54b12b061f8 100644 --- a/Common/Types/Monitor/MonitorType.ts +++ b/Common/Types/Monitor/MonitorType.ts @@ -181,6 +181,9 @@ export class MonitorTypeHelper { MonitorType.CustomJavaScriptCode, MonitorType.IncomingRequest, MonitorType.Server, + MonitorType.Logs, + MonitorType.Metrics, + MonitorType.Traces, ]; } diff --git a/Common/Types/ObjectID.ts b/Common/Types/ObjectID.ts index 49aa32beb6d..95192d53ee5 100644 --- a/Common/Types/ObjectID.ts +++ b/Common/Types/ObjectID.ts @@ -49,6 +49,9 @@ export default class ObjectID extends DatabaseProperty { public static toJSONArray(ids: Array): Array { return ids.map((id: ObjectID) => { + if (typeof id === "string") { + id = new ObjectID(id); + } return id.toJSON(); }); } diff --git a/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx b/Dashboard/src/Components/Form/Monitor/LogMonitor/LogMonitorStepFrom.tsx index 8f42e83003c..1086fe04df1 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: "Check Last X Seconds of Logs", + title: "Monitor Last X Time of Logs", isAdvancedFilter: true, }, { diff --git a/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx b/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx index 40afb39c3ac..eb2e9918fc8 100644 --- a/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx +++ b/Dashboard/src/Components/Form/Monitor/MonitorStep.tsx @@ -8,7 +8,9 @@ import Exception from "Common/Types/Exception/Exception"; import IP from "Common/Types/IP/IP"; import MonitorCriteria from "Common/Types/Monitor/MonitorCriteria"; import MonitorStep from "Common/Types/Monitor/MonitorStep"; -import MonitorStepLogMonitor, { MonitorStepLogMonitorUtil } from "Common/Types/Monitor/MonitorStepLogMonitor"; +import MonitorStepLogMonitor, { + MonitorStepLogMonitorUtil, +} from "Common/Types/Monitor/MonitorStepLogMonitor"; import MonitorType from "Common/Types/Monitor/MonitorType"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; import Port from "Common/Types/Port"; @@ -367,29 +369,6 @@ const MonitorStepElement: FunctionComponent = (
)} - {props.monitorType === MonitorType.Logs && ( -
- - { - monitorStep.setLogMonitor(value); - setMonitorStep(MonitorStep.clone(monitorStep)); - }} - attributeKeys={attributeKeys} - telemetryServices={telemetryServices} - /> -
- )} - {props.monitorType === MonitorType.API && (
= (
)} + {props.monitorType === MonitorType.Logs && ( +
+ + { + monitorStep.setLogMonitor(value); + setMonitorStep(MonitorStep.clone(monitorStep)); + }} + attributeKeys={attributeKeys} + telemetryServices={telemetryServices} + /> +
+ )} + {isCodeMonitor && (
{ + return i.value === CheckOn.LogCount; + }); + } + return options; } @@ -249,6 +255,17 @@ export default class CriteriaFilterUtil { }); } + if (checkOn === CheckOn.LogCount) { + options = options.filter((i: DropdownOption) => { + return ( + i.value === FilterType.GreaterThan || + i.value === FilterType.LessThan || + i.value === FilterType.LessThanOrEqualTo || + i.value === FilterType.GreaterThanOrEqualTo + ); + }); + } + if ( checkOn === CheckOn.CPUUsagePercent || checkOn === CheckOn.DiskUsagePercent || @@ -469,6 +486,10 @@ export default class CriteriaFilterUtil { return "1234"; } + if (checkOn === CheckOn.LogCount) { + return "1"; + } + if (checkOn === CheckOn.ServerProcessCommand) { return "node index.js"; } diff --git a/Ingestor/API/OTelIngest.ts b/Ingestor/API/OTelIngest.ts index ba84a981018..d2d905bd777 100644 --- a/Ingestor/API/OTelIngest.ts +++ b/Ingestor/API/OTelIngest.ts @@ -24,12 +24,13 @@ import Express, { } from "CommonServer/Utils/Express"; import logger from "CommonServer/Utils/Logger"; import Response from "CommonServer/Utils/Response"; -import Log, rity } from "Model/AnalyticsModels/Log"; +import Log from "Model/AnalyticsModels/Log"; import Metric, { MetricPointType } from "Model/AnalyticsModels/Metric"; import Span, { SpanKind, SpanStatus } from "Model/AnalyticsModels/Span"; import protobuf from "protobufjs"; import Dictionary from "Common/Types/Dictionary"; import ObjectID from "Common/Types/ObjectID"; +import LogSeverity from "Common/Types/Log/LogSeverity"; // Load proto file for OTel From 5c3175f9e73af60c0c41c314511a18739d7a6128 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 18:01:04 -0600 Subject: [PATCH 3/7] refactor: Update monitor interfaces to use consistent naming ``` --- .../IncomingRequestMonitor/CheckHeartbeat.ts | 4 +- .../Jobs/ServerMonitor/CheckOnlineStatus.ts | 10 +- .../MonitorTelemetryMonitor.ts | 110 +++++++++++++ .../CustomCodeMonitorResponse.ts | 2 +- .../Monitor/SSLMonitor/SslMonitorResponse.ts | 2 +- .../ServerMonitor/ServerMonitorResponse.ts | 2 +- .../SyntheticMonitorResponse.ts | 6 +- Common/Types/Probe/ProbeMonitorResponse.ts | 14 +- .../1717605043663-InitialMigration.ts | 2 +- .../Criteria/APIRequestCriteria.ts | 14 +- .../Criteria/CompareCriteria.ts | 0 .../Criteria/CustomCodeMonitorCriteria.ts | 26 ++-- .../Criteria/EvaluateOverTime.ts | 0 .../Criteria/IncomingRequestCriteria.ts | 4 +- .../Criteria/SSLMonitorCriteria.ts | 12 +- .../Criteria/ServerMonitorCriteria.ts | 36 ++--- .../Criteria/SyntheticMonitor.ts | 12 +- CommonServer/Utils/Monitor/DataToProcess.ts | 10 ++ .../MonitorResource.ts} | 145 +++++++++--------- CommonServer/Utils/Probe/DataToProcess.ts | 10 -- .../SummaryView/CustomMonitorSummaryView.tsx | 28 ++-- .../Monitor/SummaryView/PingMonitorView.tsx | 18 +-- .../SummaryView/SSLCertificateMonitorView.tsx | 14 +- .../Monitor/SummaryView/ServerMonitorView.tsx | 48 +++--- .../Monitor/SummaryView/Summary.tsx | 24 +-- .../Monitor/SummaryView/SummaryInfo.tsx | 36 ++--- .../SummaryView/SyntheticMonitorItemView.tsx | 18 +-- .../SummaryView/SyntheticMonitorView.tsx | 26 ++-- .../SummaryView/WebsiteMonitorView.tsx | 28 ++-- Dashboard/src/Pages/Monitor/View/Index.tsx | 22 +-- InfrastructureAgent/agent.go | 4 +- Ingestor/API/IncomingRequest.ts | 4 +- Ingestor/API/Probe.ts | 12 +- Ingestor/API/ServerMonitor.ts | 16 +- Model/Models/Monitor.ts | 74 ++++++++- Model/Models/MonitorProbe.ts | 4 +- Probe/Jobs/Monitor/FetchList.ts | 6 +- Probe/Utils/Monitors/Monitor.ts | 32 ++-- .../MonitorTypes/CustomCodeMonitor.ts | 6 +- .../Monitors/MonitorTypes/PortMonitor.ts | 4 +- .../Utils/Monitors/MonitorTypes/SslMonitor.ts | 6 +- .../Monitors/MonitorTypes/SyntheticMonitor.ts | 12 +- 42 files changed, 521 insertions(+), 342 deletions(-) create mode 100644 App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts rename CommonServer/Utils/{Probe => Monitor}/Criteria/APIRequestCriteria.ts (91%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/CompareCriteria.ts (100%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/CustomCodeMonitorCriteria.ts (76%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/EvaluateOverTime.ts (100%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/IncomingRequestCriteria.ts (98%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/SSLMonitorCriteria.ts (93%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/ServerMonitorCriteria.ts (86%) rename CommonServer/Utils/{Probe => Monitor}/Criteria/SyntheticMonitor.ts (76%) create mode 100644 CommonServer/Utils/Monitor/DataToProcess.ts rename CommonServer/Utils/{Probe/ProbeMonitorResponse.ts => Monitor/MonitorResource.ts} (89%) delete mode 100644 CommonServer/Utils/Probe/DataToProcess.ts diff --git a/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts b/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts index 5cccfd9afd9..4699f854725 100644 --- a/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts +++ b/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts @@ -6,7 +6,7 @@ import MonitorType from "Common/Types/Monitor/MonitorType"; import { EVERY_MINUTE } from "Common/Utils/CronTime"; import MonitorService from "CommonServer/Services/MonitorService"; import logger from "CommonServer/Utils/Logger"; -import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse"; +import MonitorService from "CommonServer/Utils/Monitor/Monitor"; import Monitor from "Model/Models/Monitor"; RunCron( @@ -67,7 +67,7 @@ RunCron( onlyCheckForIncomingRequestReceivedAt: true, }; - await ProbeMonitorResponseService.processProbeResponse(incomingRequest); + await MonitorResourceService.monitorResource(incomingRequest); } catch (error) { logger.error( `Error while processing incoming request monitor: ${monitor.id?.toString()}`, diff --git a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts index fec80609ebc..8c007cf0e18 100644 --- a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts +++ b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts @@ -3,12 +3,12 @@ import LIMIT_MAX from "Common/Types/Database/LimitMax"; import OneUptimeDate from "Common/Types/Date"; import { CheckOn } from "Common/Types/Monitor/CriteriaFilter"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import { EVERY_MINUTE } from "Common/Utils/CronTime"; import MonitorService from "CommonServer/Services/MonitorService"; import QueryHelper from "CommonServer/Types/Database/QueryHelper"; import logger from "CommonServer/Utils/Logger"; -import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse"; +import MonitorService from "CommonServer/Utils/Monitor/Monitor"; import Monitor from "Model/Models/Monitor"; RunCron( @@ -48,7 +48,7 @@ RunCron( continue; } - const serverMonitorResponse: ServerMonitorResponse = { + const serverMonitor: ServerMonitor = { monitorId: monitor.id!, onlyCheckRequestReceivedAt: true, requestReceivedAt: @@ -56,8 +56,8 @@ RunCron( hostname: "", }; - await ProbeMonitorResponseService.processProbeResponse( - serverMonitorResponse, + await MonitorResourceService.monitorResource( + serverMonitor, ); } catch (error) { logger.error( diff --git a/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts new file mode 100644 index 00000000000..9e228548ee1 --- /dev/null +++ b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts @@ -0,0 +1,110 @@ +import OneUptimeDate from "Common/Types/Date"; +import RunCron from "../../Utils/Cron"; +import LIMIT_MAX from "Common/Types/Database/LimitMax"; +import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; +import MonitorType from "Common/Types/Monitor/MonitorType"; +import { EVERY_MINUTE } from "Common/Utils/CronTime"; +import MonitorService from "CommonServer/Services/MonitorService"; +import QueryHelper from "CommonServer/Types/Database/QueryHelper"; +import logger from "CommonServer/Utils/Logger"; +import MonitorResourceService from "CommonServer/Utils/Monitor/MonitorResource"; +import Monitor from "Model/Models/Monitor"; +import CronTab from "CommonServer/Utils/CronTab"; + +RunCron( + "LogMonitor:MonitorLogMonitor", + { schedule: EVERY_MINUTE, runOnStartup: false }, + async () => { + logger.debug("Checking LogMonitor:MonitorLogMonitor"); + + const telemetryMonitors: Array = await MonitorService.findBy({ + query: { + monitorType: QueryHelper.any([ + MonitorType.Logs, + MonitorType.Traces, + MonitorType.Metrics, + ]), + telemetryMonitorNextMonitorAt: QueryHelper.lessThanEqualToOrNull( + OneUptimeDate.getCurrentDate(), + ), + }, + props: { + isRoot: true, + }, + select: { + _id: true, + monitorSteps: true, + createdAt: true, + monitoringInterval: true, + }, + limit: LIMIT_MAX, + skip: 0, + }); + + const updatePromises: Array> = []; + + for (const telemetryMonitor of telemetryMonitors) { + if (!telemetryMonitor.monitoringInterval) { + continue; + } + + let nextPing: Date = OneUptimeDate.addRemoveMinutes( + OneUptimeDate.getCurrentDate(), + 1, + ); + + try { + nextPing = CronTab.getNextExecutionTime( + telemetryMonitor?.monitoringInterval as string, + ); + } catch (err) { + logger.error(err); + } + + updatePromises.push( + MonitorService.updateOneById({ + id: telemetryMonitor.id!, + data: { + telemetryMonitorLastMonitorAt: OneUptimeDate.getCurrentDate(), + telemetryMonitorNextMonitorAt: nextPing, + }, + props: { + isRoot: true, + }, + }), + ); + } + + await Promise.all(updatePromises); + + logger.debug(`Found ${telemetryMonitors.length} telemetry monitors`); + + logger.debug(telemetryMonitors); + + for (const monitor of telemetryMonitors) { + try { + if (!monitor.monitorSteps) { + logger.debug("Monitor has no steps. Skipping..."); + continue; + } + + const incomingRequest: IncomingMonitorRequest = { + monitorId: monitor.id!, + requestHeaders: undefined, + requestBody: undefined, + requestMethod: undefined, + incomingRequestReceivedAt: + monitor.incomingRequestReceivedAt || monitor.createdAt!, + onlyCheckForIncomingRequestReceivedAt: true, + }; + + await MonitorResourceService.monitorResource(incomingRequest); + } catch (error) { + logger.error( + `Error while processing incoming request monitor: ${monitor.id?.toString()}`, + ); + logger.error(error); + } + } + }, +); diff --git a/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts b/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts index 628a30ced4b..93084474159 100644 --- a/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts +++ b/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts @@ -1,6 +1,6 @@ import { JSONObject } from "../../JSON"; -export default interface CustomCodeMonitorResponse { +export default interface CustomCodeMonitor { result: string | number | boolean | JSONObject | undefined; scriptError?: string | undefined; logMessages: string[]; diff --git a/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts b/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts index 1174cf06db7..3a040ef2d15 100644 --- a/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts +++ b/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts @@ -1,4 +1,4 @@ -export default interface SslMonitorResponse { +export default interface SslMonitor { isSelfSigned?: boolean; createdAt?: Date; expiresAt?: Date; diff --git a/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts b/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts index a003db403c8..69ff5cf2241 100644 --- a/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts +++ b/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts @@ -7,7 +7,7 @@ export interface ServerProcess { command: string; } -export default interface ServerMonitorResponse { +export default interface ServerMonitor { monitorId: ObjectID; hostname: string; // Hostname of the server basicInfrastructureMetrics?: BasicInfrastructureMetrics | undefined; diff --git a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts index 0765a1a95fd..d1da41ff3dc 100644 --- a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts +++ b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts @@ -1,10 +1,10 @@ -import CustomCodeMonitorResponse from "../CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "../CustomCodeMonitor/CustomCodeMonitor"; import BrowserType from "./BrowserType"; import ScreenSizeType from "./ScreenSizeType"; import Screenshots from "./Screenshot"; -export default interface SyntheticMonitorResponse - extends CustomCodeMonitorResponse { +export default interface SyntheticMonitor + extends CustomCodeMonitor { screenshots?: Screenshots | undefined; // base 64 encoded screenshots browserType: BrowserType; screenSizeType: ScreenSizeType; diff --git a/Common/Types/Probe/ProbeMonitorResponse.ts b/Common/Types/Probe/ProbeMonitorResponse.ts index 6315e466802..372cddfc6f5 100644 --- a/Common/Types/Probe/ProbeMonitorResponse.ts +++ b/Common/Types/Probe/ProbeMonitorResponse.ts @@ -3,13 +3,13 @@ import URL from "../API/URL"; import Dictionary from "../Dictionary"; import IP from "../IP/IP"; import { JSONObject } from "../JSON"; -import CustomCodeMonitorResponse from "../Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; -import SslMonitorResponse from "../Monitor/SSLMonitor/SslMonitorResponse"; -import SyntheticMonitorResponse from "../Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import CustomCodeMonitor from "../Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import SslMonitor from "../Monitor/SSLMonitor/SslMonitor"; +import SyntheticMonitor from "../Monitor/SyntheticMonitors/SyntheticMonitor"; import ObjectID from "../ObjectID"; import Port from "../Port"; -export default interface ProbeMonitorResponse { +export default interface ProbeMonitor { isOnline?: boolean | undefined; monitorDestination?: URL | IP | Hostname | undefined; monitorDestinationPort?: Port | undefined; @@ -21,8 +21,8 @@ export default interface ProbeMonitorResponse { monitorId: ObjectID; probeId: ObjectID; failureCause: string; - sslResponse?: SslMonitorResponse | undefined; - syntheticMonitorResponse?: Array | undefined; - customCodeMonitorResponse?: CustomCodeMonitorResponse | undefined; + sslResponse?: SslMonitor | undefined; + syntheticMonitor?: Array | undefined; + customCodeMonitor?: CustomCodeMonitor | undefined; monitoredAt: Date; } diff --git a/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts b/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts index 40be89368ff..3a1d7c8bb86 100644 --- a/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts +++ b/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts @@ -180,7 +180,7 @@ export default class InitialMigration implements MigrationInterface { `CREATE INDEX "IDX_db1783158a23bd20dbebaae56e" ON "MonitorStatus" ("projectId") `, ); await queryRunner.query( - `CREATE TABLE "Monitor" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "description" character varying(500), "slug" character varying(100) NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "monitorType" character varying(100) NOT NULL, "currentMonitorStatusId" uuid NOT NULL, "monitorSteps" jsonb, "monitoringInterval" character varying(100), "customFields" jsonb, "isOwnerNotifiedOfResourceCreation" boolean NOT NULL DEFAULT false, "disableActiveMonitoring" boolean NOT NULL DEFAULT false, "incomingRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "disableActiveMonitoringBecauseOfScheduledMaintenanceEvent" boolean NOT NULL DEFAULT false, "disableActiveMonitoringBecauseOfManualIncident" boolean NOT NULL DEFAULT false, "serverMonitorRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "serverMonitorSecretKey" uuid, "incomingRequestSecretKey" uuid, "incomingMonitorRequest" jsonb, "serverMonitorResponse" jsonb, CONSTRAINT "UQ_42ecc6e0ac9984cd24d5f9ddd8d" UNIQUE ("slug"), CONSTRAINT "PK_eb992d1e4e316083d3535709e43" PRIMARY KEY ("_id"))`, + `CREATE TABLE "Monitor" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "description" character varying(500), "slug" character varying(100) NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "monitorType" character varying(100) NOT NULL, "currentMonitorStatusId" uuid NOT NULL, "monitorSteps" jsonb, "monitoringInterval" character varying(100), "customFields" jsonb, "isOwnerNotifiedOfResourceCreation" boolean NOT NULL DEFAULT false, "disableActiveMonitoring" boolean NOT NULL DEFAULT false, "incomingRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "disableActiveMonitoringBecauseOfScheduledMaintenanceEvent" boolean NOT NULL DEFAULT false, "disableActiveMonitoringBecauseOfManualIncident" boolean NOT NULL DEFAULT false, "serverMonitorRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "serverMonitorSecretKey" uuid, "incomingRequestSecretKey" uuid, "incomingMonitorRequest" jsonb, "serverMonitor" jsonb, CONSTRAINT "UQ_42ecc6e0ac9984cd24d5f9ddd8d" UNIQUE ("slug"), CONSTRAINT "PK_eb992d1e4e316083d3535709e43" PRIMARY KEY ("_id"))`, ); await queryRunner.query( `CREATE INDEX "IDX_996acfb590bda327843f78b7ad" ON "Monitor" ("projectId") `, diff --git a/CommonServer/Utils/Probe/Criteria/APIRequestCriteria.ts b/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts similarity index 91% rename from CommonServer/Utils/Probe/Criteria/APIRequestCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts index 68f5e30d4a0..79ce07b4446 100644 --- a/CommonServer/Utils/Probe/Criteria/APIRequestCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts @@ -7,7 +7,7 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Typeof from "Common/Types/Typeof"; export default class APIRequestCriteria { @@ -46,7 +46,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitorResponse).isOnline; + (input.dataToProcess as ProbeMonitor).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, @@ -60,7 +60,7 @@ export default class APIRequestCriteria { const value: Array | number = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitorResponse).responseTimeInMs!; + (input.dataToProcess as ProbeMonitor).responseTimeInMs!; return CompareCriteria.compareCriteriaNumbers({ value: value, @@ -75,7 +75,7 @@ export default class APIRequestCriteria { const value: Array | number = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitorResponse).responseCode!; + (input.dataToProcess as ProbeMonitor).responseCode!; return CompareCriteria.compareCriteriaNumbers({ value: value, @@ -86,7 +86,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseBody) { let responseBody: string | JSONObject | undefined = ( - input.dataToProcess as ProbeMonitorResponse + input.dataToProcess as ProbeMonitor ).responseBody; if (responseBody && typeof responseBody === Typeof.Object) { @@ -123,7 +123,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseHeader) { const headerKeys: Array = Object.keys( - (input.dataToProcess as ProbeMonitorResponse).responseHeaders || {}, + (input.dataToProcess as ProbeMonitor).responseHeaders || {}, ).map((key: string) => { return key.toLowerCase(); }); @@ -154,7 +154,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseHeaderValue) { const headerValues: Array = Object.values( - (input.dataToProcess as ProbeMonitorResponse).responseHeaders || {}, + (input.dataToProcess as ProbeMonitor).responseHeaders || {}, ).map((key: string) => { return key.toLowerCase(); }); diff --git a/CommonServer/Utils/Probe/Criteria/CompareCriteria.ts b/CommonServer/Utils/Monitor/Criteria/CompareCriteria.ts similarity index 100% rename from CommonServer/Utils/Probe/Criteria/CompareCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/CompareCriteria.ts diff --git a/CommonServer/Utils/Probe/Criteria/CustomCodeMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts similarity index 76% rename from CommonServer/Utils/Probe/Criteria/CustomCodeMonitorCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts index 9c6f48fe377..5d1e3567637 100644 --- a/CommonServer/Utils/Probe/Criteria/CustomCodeMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts @@ -1,10 +1,10 @@ import CompareCriteria from "./CompareCriteria"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; export default class CustomCodeMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - monitorResponse: CustomCodeMonitorResponse; + Monitor: CustomCodeMonitor; criteriaFilter: CriteriaFilter; }): Promise { // Server Monitoring Checks @@ -12,14 +12,14 @@ export default class CustomCodeMonitoringCriteria { let threshold: number | string | undefined | null = input.criteriaFilter.value; - const syntheticMonitorResponse: CustomCodeMonitorResponse = - input.monitorResponse; + const syntheticMonitor: CustomCodeMonitor = + input.Monitor; if (input.criteriaFilter.checkOn === CheckOn.ExecutionTime) { threshold = CompareCriteria.convertToNumber(threshold); const currentExecutionTime: number = - syntheticMonitorResponse.executionTimeInMS || 0; + syntheticMonitor.executionTimeInMS || 0; return CompareCriteria.compareCriteriaNumbers({ value: currentExecutionTime, @@ -31,7 +31,7 @@ export default class CustomCodeMonitoringCriteria { if (input.criteriaFilter.checkOn === CheckOn.Error) { const emptyNotEmptyResult: string | null = CompareCriteria.compareEmptyAndNotEmpty({ - value: syntheticMonitorResponse.scriptError, + value: syntheticMonitor.scriptError, criteriaFilter: input.criteriaFilter, }); @@ -41,10 +41,10 @@ export default class CustomCodeMonitoringCriteria { if ( threshold && - typeof syntheticMonitorResponse.scriptError === "string" + typeof syntheticMonitor.scriptError === "string" ) { const result: string | null = CompareCriteria.compareCriteriaStrings({ - value: syntheticMonitorResponse.scriptError!, + value: syntheticMonitor.scriptError!, threshold: threshold.toString(), criteriaFilter: input.criteriaFilter, }); @@ -58,7 +58,7 @@ export default class CustomCodeMonitoringCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResultValue) { const emptyNotEmptyResult: string | null = CompareCriteria.compareEmptyAndNotEmpty({ - value: syntheticMonitorResponse.result, + value: syntheticMonitor.result, criteriaFilter: input.criteriaFilter, }); @@ -78,10 +78,10 @@ export default class CustomCodeMonitoringCriteria { if ( thresholdAsNumber !== null && - typeof syntheticMonitorResponse.result === "number" + typeof syntheticMonitor.result === "number" ) { const result: string | null = CompareCriteria.compareCriteriaNumbers({ - value: syntheticMonitorResponse.result, + value: syntheticMonitor.result, threshold: thresholdAsNumber as number, criteriaFilter: input.criteriaFilter, }); @@ -91,9 +91,9 @@ export default class CustomCodeMonitoringCriteria { } } - if (threshold && typeof syntheticMonitorResponse.result === "string") { + if (threshold && typeof syntheticMonitor.result === "string") { const result: string | null = CompareCriteria.compareCriteriaStrings({ - value: syntheticMonitorResponse.result, + value: syntheticMonitor.result, threshold: threshold.toString(), criteriaFilter: input.criteriaFilter, }); diff --git a/CommonServer/Utils/Probe/Criteria/EvaluateOverTime.ts b/CommonServer/Utils/Monitor/Criteria/EvaluateOverTime.ts similarity index 100% rename from CommonServer/Utils/Probe/Criteria/EvaluateOverTime.ts rename to CommonServer/Utils/Monitor/Criteria/EvaluateOverTime.ts diff --git a/CommonServer/Utils/Probe/Criteria/IncomingRequestCriteria.ts b/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts similarity index 98% rename from CommonServer/Utils/Probe/Criteria/IncomingRequestCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts index f61a91989a5..2a9f7edda89 100644 --- a/CommonServer/Utils/Probe/Criteria/IncomingRequestCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts @@ -11,7 +11,7 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import Typeof from "Common/Types/Typeof"; import EvaluateOverTime from "./EvaluateOverTime"; import CompareCriteria from "./CompareCriteria"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; export default class IncomingRequestCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { @@ -60,7 +60,7 @@ export default class IncomingRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitorResponse).isOnline; + (input.dataToProcess as ProbeMonitor).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, diff --git a/CommonServer/Utils/Probe/Criteria/SSLMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts similarity index 93% rename from CommonServer/Utils/Probe/Criteria/SSLMonitorCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts index d97790f7929..eba5fbb2e66 100644 --- a/CommonServer/Utils/Probe/Criteria/SSLMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts @@ -6,8 +6,8 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import SslMonitorResponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import SslMonitor from "Common/Types/Monitor/SSLMonitor/SslMonitor"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import EvaluateOverTime from "./EvaluateOverTime"; export default class ServerMonitorCriteria { @@ -18,10 +18,10 @@ export default class ServerMonitorCriteria { let threshold: number | string | undefined | null = input.criteriaFilter.value; - const dataToProcess: ProbeMonitorResponse = - input.dataToProcess as ProbeMonitorResponse; + const dataToProcess: ProbeMonitor = + input.dataToProcess as ProbeMonitor; - const sslResponse: SslMonitorResponse | undefined = + const sslResponse: SslMonitor | undefined = dataToProcess.sslResponse; let overTimeValue: Array | number | boolean | undefined = @@ -49,7 +49,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitorResponse).isOnline; + (input.dataToProcess as ProbeMonitor).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, diff --git a/CommonServer/Utils/Probe/Criteria/ServerMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts similarity index 86% rename from CommonServer/Utils/Probe/Criteria/ServerMonitorCriteria.ts rename to CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts index 242992ab573..92981913cc5 100644 --- a/CommonServer/Utils/Probe/Criteria/ServerMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts @@ -9,9 +9,9 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import ServerMonitorResponse, { +import ServerMonitor, { ServerProcess, -} from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +} from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; export default class ServerMonitorCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { @@ -45,7 +45,7 @@ export default class ServerMonitorCriteria { } } - const lastCheckTime: Date = (input.dataToProcess as ServerMonitorResponse) + const lastCheckTime: Date = (input.dataToProcess as ServerMonitor) .requestReceivedAt; const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes( @@ -92,13 +92,13 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.CPUUsagePercent && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); const currentCpuPercent: number | Array = (overTimeValue as Array) || - (input.dataToProcess as ServerMonitorResponse) + (input.dataToProcess as ServerMonitor) .basicInfrastructureMetrics?.cpuMetrics.percentUsed || 0; @@ -111,13 +111,13 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.MemoryUsagePercent && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); const memoryPercent: number | Array = (overTimeValue as Array) || - (input.dataToProcess as ServerMonitorResponse) + (input.dataToProcess as ServerMonitor) .basicInfrastructureMetrics?.memoryMetrics.percentUsed || 0; @@ -130,7 +130,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.DiskUsagePercent && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); @@ -139,7 +139,7 @@ export default class ServerMonitorCriteria { const diskPercent: number = ( - input.dataToProcess as ServerMonitorResponse + input.dataToProcess as ServerMonitor ).basicInfrastructureMetrics?.diskMetrics.filter( (item: BasicDiskMetrics) => { return ( @@ -159,7 +159,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessName && threshold && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { const thresholdProcessName: string = threshold .toString() @@ -168,7 +168,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processNames: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.name.trim().toLowerCase(); }, @@ -183,7 +183,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processNames: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.name.trim().toLowerCase(); }, @@ -200,7 +200,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessPID && threshold && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { const thresholdProcessPID: string = threshold .toString() @@ -209,7 +209,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processPIDs: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.pid.toString().trim().toLowerCase(); }, @@ -224,7 +224,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processPIDs: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.pid.toString().trim().toLowerCase(); }, @@ -243,7 +243,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessCommand && threshold && - !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt ) { const thresholdProcessCommand: string = threshold .toString() @@ -252,7 +252,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processCommands: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.command.trim().toLowerCase(); }, @@ -267,7 +267,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processCommands: Array = - (input.dataToProcess as ServerMonitorResponse)?.processes?.map( + (input.dataToProcess as ServerMonitor)?.processes?.map( (item: ServerProcess) => { return item.command.trim().toLowerCase(); }, diff --git a/CommonServer/Utils/Probe/Criteria/SyntheticMonitor.ts b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts similarity index 76% rename from CommonServer/Utils/Probe/Criteria/SyntheticMonitor.ts rename to CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts index e1621f86e9a..9bdf8020fd7 100644 --- a/CommonServer/Utils/Probe/Criteria/SyntheticMonitor.ts +++ b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts @@ -1,21 +1,21 @@ import CompareCriteria from "./CompareCriteria"; import CustomCodeMonitoringCriteria from "./CustomCodeMonitorCriteria"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; export default class SyntheticMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - monitorResponse: Array; + Monitor: Array; criteriaFilter: CriteriaFilter; }): Promise { - for (const syntheticMonitorResponse of input.monitorResponse) { + for (const syntheticMonitor of input.Monitor) { const threshold: number | string | undefined | null = input.criteriaFilter.value; // check custom code monitoring criteria first const result: string | null = await CustomCodeMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - monitorResponse: syntheticMonitorResponse, + Monitor: syntheticMonitor, criteriaFilter: input.criteriaFilter, }); @@ -27,7 +27,7 @@ export default class SyntheticMonitoringCriteria { if (CheckOn.ScreenSizeType === input.criteriaFilter.checkOn) { return CompareCriteria.checkEqualToOrNotEqualTo({ - value: syntheticMonitorResponse.screenSizeType, + value: syntheticMonitor.screenSizeType, threshold: threshold as number, criteriaFilter: input.criteriaFilter, }); @@ -35,7 +35,7 @@ export default class SyntheticMonitoringCriteria { if (CheckOn.BrowserType === input.criteriaFilter.checkOn) { return CompareCriteria.checkEqualToOrNotEqualTo({ - value: syntheticMonitorResponse.browserType, + value: syntheticMonitor.browserType, threshold: threshold as number, criteriaFilter: input.criteriaFilter, }); diff --git a/CommonServer/Utils/Monitor/DataToProcess.ts b/CommonServer/Utils/Monitor/DataToProcess.ts new file mode 100644 index 00000000000..2533c089a22 --- /dev/null +++ b/CommonServer/Utils/Monitor/DataToProcess.ts @@ -0,0 +1,10 @@ +import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; + +type DataToProcess = + | ProbeMonitor + | IncomingMonitorRequest + | ServerMonitor; + +export default DataToProcess; diff --git a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts b/CommonServer/Utils/Monitor/MonitorResource.ts similarity index 89% rename from CommonServer/Utils/Probe/ProbeMonitorResponse.ts rename to CommonServer/Utils/Monitor/MonitorResource.ts index 0fd98424977..05381674131 100644 --- a/CommonServer/Utils/Probe/ProbeMonitorResponse.ts +++ b/CommonServer/Utils/Monitor/MonitorResource.ts @@ -5,7 +5,7 @@ import MonitorMetricsByMinuteService from "../../Services/MonitorMetricsByMinute import MonitorProbeService from "../../Services/MonitorProbeService"; import MonitorService from "../../Services/MonitorService"; import MonitorStatusTimelineService from "../../Services/MonitorStatusTimelineService"; -import logger from "../../Utils/Logger"; +import logger from "../Logger"; import VMUtil from "../VM/VMAPI"; import APIRequestCriteria from "./Criteria/APIRequestCriteria"; import CustomCodeMonitoringCriteria from "./Criteria/CustomCodeMonitorCriteria"; @@ -26,7 +26,7 @@ import { CriteriaFilter, FilterCondition, } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorCriteria from "Common/Types/Monitor/MonitorCriteria"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; @@ -35,10 +35,10 @@ import MonitorSteps from "Common/Types/Monitor/MonitorSteps"; import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Typeof from "Common/Types/Typeof"; import MonitorMetricsByMinute from "Model/AnalyticsModels/MonitorMetricsByMinute"; import Incident from "Model/Models/Incident"; @@ -50,8 +50,8 @@ import MonitorStatusTimeline from "Model/Models/MonitorStatusTimeline"; import OnCallDutyPolicy from "Model/Models/OnCallDutyPolicy"; import OneUptimeDate from "Common/Types/Date"; -export default class ProbeMonitorResponseService { - public static async processProbeResponse( +export default class MonitorResourceService { + public static async monitorResource( dataToProcess: DataToProcess, ): Promise { let response: ProbeApiIngestResponse = { @@ -128,13 +128,13 @@ export default class ProbeMonitorResponseService { monitor.monitorType && MonitorTypeHelper.isProbableMonitor(monitor.monitorType) ) { - dataToProcess = dataToProcess as ProbeMonitorResponse; - if ((dataToProcess as ProbeMonitorResponse).probeId) { + dataToProcess = dataToProcess as ProbeMonitor; + if ((dataToProcess as ProbeMonitor).probeId) { const monitorProbe: MonitorProbe | null = await MonitorProbeService.findOneBy({ query: { monitorId: monitor.id!, - probeId: (dataToProcess as ProbeMonitorResponse).probeId!, + probeId: (dataToProcess as ProbeMonitor).probeId!, }, select: { lastMonitoringLog: true, @@ -151,13 +151,13 @@ export default class ProbeMonitorResponseService { await MonitorProbeService.updateOneBy({ query: { monitorId: monitor.id!, - probeId: (dataToProcess as ProbeMonitorResponse).probeId!, + probeId: (dataToProcess as ProbeMonitor).probeId!, }, data: { lastMonitoringLog: { ...(monitorProbe.lastMonitoringLog || {}), [( - dataToProcess as ProbeMonitorResponse + dataToProcess as ProbeMonitor ).monitorStepId.toString()]: { ...JSON.parse(JSON.stringify(dataToProcess)), monitoredAt: OneUptimeDate.getCurrentDate(), @@ -196,15 +196,15 @@ export default class ProbeMonitorResponseService { if ( monitor.monitorType === MonitorType.Server && - (dataToProcess as ServerMonitorResponse).requestReceivedAt + (dataToProcess as ServerMonitor).requestReceivedAt ) { await MonitorService.updateOneById({ id: monitor.id!, data: { serverMonitorRequestReceivedAt: ( - dataToProcess as ServerMonitorResponse + dataToProcess as ServerMonitor ).requestReceivedAt!, - serverMonitorResponse: dataToProcess as ServerMonitorResponse, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. + serverMonitor: dataToProcess as ServerMonitor, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. }, props: { isRoot: true, @@ -280,12 +280,12 @@ export default class ProbeMonitorResponseService { const monitorStep: MonitorStep | undefined = monitorSteps.data.monitorStepsInstanceArray[0]; - if ((dataToProcess as ProbeMonitorResponse).monitorStepId) { + if ((dataToProcess as ProbeMonitor).monitorStepId) { monitorSteps.data.monitorStepsInstanceArray.find( (monitorStep: MonitorStep) => { return ( monitorStep.id.toString() === - (dataToProcess as ProbeMonitorResponse).monitorStepId.toString() + (dataToProcess as ProbeMonitor).monitorStepId.toString() ); }, ); @@ -313,7 +313,7 @@ export default class ProbeMonitorResponseService { // now process probe response monitors - response = await ProbeMonitorResponseService.processMonitorStep({ + response = await MonitorResourceService.processMonitorStep({ dataToProcess: dataToProcess, monitorStep: monitorStep, monitor: monitor, @@ -400,16 +400,16 @@ export default class ProbeMonitorResponseService { const itemsToSave: Array = []; if ( - (data.dataToProcess as ServerMonitorResponse).basicInfrastructureMetrics + (data.dataToProcess as ServerMonitor).basicInfrastructureMetrics ) { // store cpu, memory, disk metrics. - if ((data.dataToProcess as ServerMonitorResponse).requestReceivedAt) { + if ((data.dataToProcess as ServerMonitor).requestReceivedAt) { let isOnline: boolean = true; const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes( - (data.dataToProcess as ServerMonitorResponse).requestReceivedAt, + (data.dataToProcess as ServerMonitor).requestReceivedAt, OneUptimeDate.getCurrentDate(), ); @@ -429,7 +429,7 @@ export default class ProbeMonitorResponseService { } const basicMetrics: BasicInfrastructureMetrics | undefined = ( - data.dataToProcess as ServerMonitorResponse + data.dataToProcess as ServerMonitor ).basicInfrastructureMetrics; if (!basicMetrics) { @@ -477,25 +477,25 @@ export default class ProbeMonitorResponseService { } } - if ((data.dataToProcess as ProbeMonitorResponse).responseTimeInMs) { + if ((data.dataToProcess as ProbeMonitor).responseTimeInMs) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ResponseTime; monitorMetricsByMinute.metricValue = ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).responseTimeInMs; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitorResponse).isOnline !== undefined) { + if ((data.dataToProcess as ProbeMonitor).isOnline !== undefined) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; @@ -504,52 +504,52 @@ export default class ProbeMonitorResponseService { monitorMetricsByMinute.metricValue = 0; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).probeId.toString(), }; - if ((data.dataToProcess as ProbeMonitorResponse).isOnline) { + if ((data.dataToProcess as ProbeMonitor).isOnline) { monitorMetricsByMinute.metricValue = 1; } itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitorResponse).responseCode) { + if ((data.dataToProcess as ProbeMonitor).responseCode) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ResponseStatusCode; monitorMetricsByMinute.metricValue = ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).responseCode; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse) { - for (const syntheticMonitorResponse of ( - data.dataToProcess as ProbeMonitorResponse - ).syntheticMonitorResponse || []) { + if ((data.dataToProcess as ProbeMonitor).syntheticMonitor) { + for (const syntheticMonitor of ( + data.dataToProcess as ProbeMonitor + ).syntheticMonitor || []) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ExecutionTime; monitorMetricsByMinute.metricValue = - syntheticMonitorResponse.executionTimeInMS; + syntheticMonitor.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).probeId.toString(), - browserType: syntheticMonitorResponse.browserType, - screenSizeType: syntheticMonitorResponse.screenSizeType, + browserType: syntheticMonitor.browserType, + screenSizeType: syntheticMonitor.screenSizeType, }; itemsToSave.push(monitorMetricsByMinute); @@ -557,11 +557,11 @@ export default class ProbeMonitorResponseService { } if ( - (data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse + (data.dataToProcess as ProbeMonitor).customCodeMonitor ) { - const customCodeMonitorResponse: CustomCodeMonitorResponse = ( - data.dataToProcess as ProbeMonitorResponse - ).customCodeMonitorResponse!; + const customCodeMonitor: CustomCodeMonitor = ( + data.dataToProcess as ProbeMonitor + ).customCodeMonitor!; const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); @@ -569,10 +569,10 @@ export default class ProbeMonitorResponseService { monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ExecutionTime; monitorMetricsByMinute.metricValue = - customCodeMonitorResponse.executionTimeInMS; + customCodeMonitor.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitorResponse + data.dataToProcess as ProbeMonitor ).probeId.toString(), }; @@ -620,17 +620,16 @@ export default class ProbeMonitorResponseService { // check if should close the incident. for (const openIncident of openIncidents) { - const shouldClose: boolean = - ProbeMonitorResponseService.shouldCloseIncident({ - openIncident, - autoResolveCriteriaInstanceIdIncidentIdsDictionary: - input.autoResolveCriteriaInstanceIdIncidentIdsDictionary, - criteriaInstance: input.criteriaInstance, - }); + const shouldClose: boolean = MonitorResourceService.shouldCloseIncident({ + openIncident, + autoResolveCriteriaInstanceIdIncidentIdsDictionary: + input.autoResolveCriteriaInstanceIdIncidentIdsDictionary, + criteriaInstance: input.criteriaInstance, + }); if (shouldClose) { // then resolve incident. - await ProbeMonitorResponseService.resolveOpenIncident({ + await MonitorResourceService.resolveOpenIncident({ openIncident: openIncident, rootCause: input.rootCause, dataToProcess: input.dataToProcess, @@ -792,10 +791,10 @@ export default class ProbeMonitorResponseService { if ( input.dataToProcess && - (input.dataToProcess as ProbeMonitorResponse).probeId + (input.dataToProcess as ProbeMonitor).probeId ) { incident.createdByProbeId = ( - input.dataToProcess as ProbeMonitorResponse + input.dataToProcess as ProbeMonitor ).probeId; } @@ -817,7 +816,7 @@ export default class ProbeMonitorResponseService { openIncident: Incident; rootCause: string; dataToProcess: - | ProbeMonitorResponse + | ProbeMonitor | IncomingMonitorRequest | DataToProcess; }): Promise { @@ -912,7 +911,7 @@ export default class ProbeMonitorResponseService { for (const criteriaInstance of criteria.data.monitorCriteriaInstanceArray) { const rootCause: string | null = - await ProbeMonitorResponseService.processMonitorCriteiaInstance({ + await MonitorResourceService.processMonitorCriteiaInstance({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -934,9 +933,9 @@ export default class ProbeMonitorResponseService { `; } - if ((input.dataToProcess as ProbeMonitorResponse).failureCause) { + if ((input.dataToProcess as ProbeMonitor).failureCause) { input.probeApiIngestResponse.rootCause += ` -**Cause**: ${(input.dataToProcess as ProbeMonitorResponse).failureCause || ""} +**Cause**: ${(input.dataToProcess as ProbeMonitor).failureCause || ""} `; } break; @@ -957,7 +956,7 @@ export default class ProbeMonitorResponseService { // process monitor criteria instance here. const rootCause: string | null = - await ProbeMonitorResponseService.isMonitorInstanceCriteriaFiltersMet({ + await MonitorResourceService.isMonitorInstanceCriteriaFiltersMet({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -985,7 +984,7 @@ export default class ProbeMonitorResponseService { for (const criteriaFilter of input.criteriaInstance.data?.filters || []) { const rootCause: string | null = - await ProbeMonitorResponseService.isMonitorInstanceCriteriaFilterMet({ + await MonitorResourceService.isMonitorInstanceCriteriaFilterMet({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -1047,11 +1046,11 @@ export default class ProbeMonitorResponseService { let responseBody: JSONObject | null = null; try { responseBody = JSON.parse( - ((input.dataToProcess as ProbeMonitorResponse) + ((input.dataToProcess as ProbeMonitor) .responseBody as string) || "{}", ); } catch (err) { - responseBody = (input.dataToProcess as ProbeMonitorResponse) + responseBody = (input.dataToProcess as ProbeMonitor) .responseBody as JSONObject; } @@ -1065,13 +1064,13 @@ export default class ProbeMonitorResponseService { storageMap = { responseBody: responseBody, - responseHeaders: (input.dataToProcess as ProbeMonitorResponse) + responseHeaders: (input.dataToProcess as ProbeMonitor) .responseHeaders, - responseStatusCode: (input.dataToProcess as ProbeMonitorResponse) + responseStatusCode: (input.dataToProcess as ProbeMonitor) .responseCode, - responseTimeInMs: (input.dataToProcess as ProbeMonitorResponse) + responseTimeInMs: (input.dataToProcess as ProbeMonitor) .responseTimeInMs, - isOnline: (input.dataToProcess as ProbeMonitorResponse).isOnline, + isOnline: (input.dataToProcess as ProbeMonitor).isOnline, }; } @@ -1130,12 +1129,12 @@ export default class ProbeMonitorResponseService { if ( input.monitor.monitorType === MonitorType.CustomJavaScriptCode && - (input.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse + (input.dataToProcess as ProbeMonitor).customCodeMonitor ) { const criteriaResult: string | null = await CustomCodeMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - monitorResponse: (input.dataToProcess as ProbeMonitorResponse) - .customCodeMonitorResponse!, + Monitor: (input.dataToProcess as ProbeMonitor) + .customCodeMonitor!, criteriaFilter: input.criteriaFilter, }); @@ -1146,13 +1145,13 @@ export default class ProbeMonitorResponseService { if ( input.monitor.monitorType === MonitorType.SyntheticMonitor && - (input.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse + (input.dataToProcess as ProbeMonitor).syntheticMonitor ) { const criteriaResult: string | null = await SyntheticMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - monitorResponse: - (input.dataToProcess as ProbeMonitorResponse) - .syntheticMonitorResponse || [], + Monitor: + (input.dataToProcess as ProbeMonitor) + .syntheticMonitor || [], criteriaFilter: input.criteriaFilter, }); diff --git a/CommonServer/Utils/Probe/DataToProcess.ts b/CommonServer/Utils/Probe/DataToProcess.ts deleted file mode 100644 index f808c856f61..00000000000 --- a/CommonServer/Utils/Probe/DataToProcess.ts +++ /dev/null @@ -1,10 +0,0 @@ -import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; - -type DataToProcess = - | ProbeMonitorResponse - | IncomingMonitorRequest - | ServerMonitorResponse; - -export default DataToProcess; diff --git a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx index 7a143a5ec21..d4ed72fec99 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx @@ -1,5 +1,5 @@ import OneUptimeDate from "Common/Types/Date"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; @@ -9,7 +9,7 @@ import FieldType from "CommonUI/src/Components/Types/FieldType"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - customCodeMonitorResponse: CustomCodeMonitorResponse; + customCodeMonitor: CustomCodeMonitor; moreDetailElement?: ReactElement; monitoredAt: Date; } @@ -17,7 +17,7 @@ export interface ComponentProps { const CustomCodeMonitorSummaryView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.customCodeMonitorResponse) { + if (!props.customCodeMonitor) { return ( ); @@ -25,20 +25,20 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( const [showMoreDetails, setShowMoreDetails] = React.useState(false); - const customMonitorResponse: CustomCodeMonitorResponse = - props.customCodeMonitorResponse; + const customMonitor: CustomCodeMonitor = + props.customCodeMonitor; - let executionTimeInMS: number = customMonitorResponse.executionTimeInMS || 0; + let executionTimeInMS: number = customMonitor.executionTimeInMS || 0; if (executionTimeInMS > 0) { executionTimeInMS = Math.round(executionTimeInMS); } - const fields: Array> = []; + const fields: Array> = []; if ( - customMonitorResponse.logMessages && - customMonitorResponse.logMessages.length > 0 + customMonitor.logMessages && + customMonitor.logMessages.length > 0 ) { fields.push({ key: "logMessages", @@ -48,7 +48,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( }); } - if (customMonitorResponse.result) { + if (customMonitor.result) { fields.push({ key: "result", title: "Result", @@ -57,7 +57,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( }); } - if (customMonitorResponse.scriptError) { + if (customMonitor.scriptError) { fields.push({ key: "scriptError", title: "Script Error", @@ -79,7 +79,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( = ( {showMoreDetails && (
- + id={"custom-code-monitor-summary-detail"} - item={customMonitorResponse} + item={customMonitor} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx index fbaf267553b..b9a7bd410be 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx @@ -1,17 +1,17 @@ import OneUptimeDate from "Common/Types/Date"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitorResponse: ProbeMonitorResponse; + probeMonitor: ProbeMonitor; } const PingMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { let responseTimeInMs: number = - props.probeMonitorResponse?.responseTimeInMs || 0; + props.probeMonitor?.responseTimeInMs || 0; if (responseTimeInMs > 0) { responseTimeInMs = Math.round(responseTimeInMs); @@ -24,9 +24,9 @@ const PingMonitorView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="Hostname or IP address" value={ - (props.probeMonitorResponse.monitorDestination?.toString() || "") + - (props.probeMonitorResponse.monitorDestinationPort?.toString() - ? `:${props.probeMonitorResponse.monitorDestinationPort.toString()}` + (props.probeMonitor.monitorDestination?.toString() || "") + + (props.probeMonitor.monitorDestinationPort?.toString() + ? `:${props.probeMonitor.monitorDestinationPort.toString()}` : "") || "-" } /> @@ -35,7 +35,7 @@ const PingMonitorView: FunctionComponent = ( = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Monitored At" value={ - props.probeMonitorResponse?.monitoredAt + props.probeMonitor?.monitoredAt ? OneUptimeDate.getDateAsLocalFormattedString( - props.probeMonitorResponse.monitoredAt, + props.probeMonitor.monitoredAt, ) : "-" } diff --git a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx index 1664c9a00bd..2effb34f5fe 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx @@ -1,26 +1,26 @@ import OneUptimeDate from "Common/Types/Date"; -import SslMonitorResponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import SslMonitor from "Common/Types/Monitor/SSLMonitor/SslMonitor"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitorResponse: ProbeMonitorResponse; + probeMonitor: ProbeMonitor; } const SSLCertificateMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.probeMonitorResponse || !props.probeMonitorResponse.sslResponse) { + if (!props.probeMonitor || !props.probeMonitor.sslResponse) { return ( ); } - const sslResponse: SslMonitorResponse = - props.probeMonitorResponse.sslResponse; + const sslResponse: SslMonitor = + props.probeMonitor.sslResponse; const [showMoreDetails, setShowMoreDetails] = React.useState(false); @@ -32,7 +32,7 @@ const SSLCertificateMonitorView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="URL" value={ - props.probeMonitorResponse.monitorDestination?.toString() || "-" + props.probeMonitor.monitorDestination?.toString() || "-" } />
diff --git a/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx index 1a05849be1e..06c59867f62 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx @@ -1,6 +1,6 @@ import OneUptimeDate from "Common/Types/Date"; import { BasicDiskMetrics } from "Common/Types/Infrastructure/BasicMetrics"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; @@ -12,7 +12,7 @@ import MemoryUtil from "Common/Utils/Memory"; import NumberUtil from "Common/Utils/Number"; export interface ComponentProps { - serverMonitorResponse: ServerMonitorResponse; + serverMonitor: ServerMonitor; } const ServerMonitorSummaryView: FunctionComponent = ( @@ -20,9 +20,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( ): ReactElement => { const [showMoreDetails, setShowMoreDetails] = React.useState(false); - const fields: Array> = []; + const fields: Array> = []; - if (props.serverMonitorResponse?.processes) { + if (props.serverMonitor?.processes) { fields.push({ key: "processes", title: "Processes", @@ -38,9 +38,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/2 shadow-none border-2 border-gray-100 " title="CPU % Used" value={ - props.serverMonitorResponse?.basicInfrastructureMetrics?.cpuMetrics?.percentUsed?.toString() + props.serverMonitor?.basicInfrastructureMetrics?.cpuMetrics?.percentUsed?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitorResponse.basicInfrastructureMetrics + props.serverMonitor.basicInfrastructureMetrics .cpuMetrics.percentUsed, ).toString() : "-" @@ -50,7 +50,7 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/2 shadow-none border-2 border-gray-100 " title="CPU Cores" value={ - props.serverMonitorResponse?.basicInfrastructureMetrics?.cpuMetrics?.cores?.toString() || + props.serverMonitor?.basicInfrastructureMetrics?.cpuMetrics?.cores?.toString() || "-" || "-" } @@ -66,9 +66,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Total Memory (GB)" value={ - props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.total?.toString() + props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.total?.toString() ? MemoryUtil.convertToGb( - props.serverMonitorResponse.basicInfrastructureMetrics + props.serverMonitor.basicInfrastructureMetrics .memoryMetrics.total, ).toString() : "-" @@ -78,9 +78,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Memory % Used" value={ - props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.percentUsed?.toString() + props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.percentUsed?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitorResponse.basicInfrastructureMetrics + props.serverMonitor.basicInfrastructureMetrics .memoryMetrics.percentUsed, ).toString() : "-" @@ -90,9 +90,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Memory % Free" value={ - props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.percentFree?.toString() + props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.percentFree?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitorResponse.basicInfrastructureMetrics + props.serverMonitor.basicInfrastructureMetrics .memoryMetrics.percentFree, ).toString() : "-" @@ -104,7 +104,7 @@ const ServerMonitorSummaryView: FunctionComponent = ( const getDiskMetrics: GetReactElementFunction = (): ReactElement => { const diskMetrics: Array | undefined = - props.serverMonitorResponse?.basicInfrastructureMetrics?.diskMetrics; + props.serverMonitor?.basicInfrastructureMetrics?.diskMetrics; if (!diskMetrics) { return
; @@ -162,45 +162,45 @@ const ServerMonitorSummaryView: FunctionComponent = (
- {props.serverMonitorResponse.failureCause && ( + {props.serverMonitor.failureCause && (
)} {showMoreDetails && fields.length > 0 && (
- {props.serverMonitorResponse?.basicInfrastructureMetrics + {props.serverMonitor?.basicInfrastructureMetrics ?.cpuMetrics && getCpuMetrics()} - {props.serverMonitorResponse?.basicInfrastructureMetrics + {props.serverMonitor?.basicInfrastructureMetrics ?.memoryMetrics && getMemoryMetrics()} - {props.serverMonitorResponse?.basicInfrastructureMetrics + {props.serverMonitor?.basicInfrastructureMetrics ?.diskMetrics && getDiskMetrics()} - + id={"website-monitor-summary-detail"} - item={props.serverMonitorResponse} + item={props.serverMonitor} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx index 762a355c9e9..515fe4c05b3 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx @@ -1,20 +1,20 @@ -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import ProbePicker from "./ProbePicker"; import SummaryInfo from "./SummaryInfo"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Card from "CommonUI/src/Components/Card/Card"; import { MonitorStepProbeResponse } from "Model/Models/MonitorProbe"; import Probe from "Model/Models/Probe"; import React, { FunctionComponent, ReactElement, useEffect } from "react"; export interface ComponentProps { - probeMonitorResponses?: Array | undefined; + probeMonitors?: Array | undefined; incomingMonitorRequest?: IncomingMonitorRequest | undefined; - serverMonitorResponse?: ServerMonitorResponse | undefined; + serverMonitor?: ServerMonitor | undefined; probes?: Array; monitorType: MonitorType; } @@ -38,18 +38,18 @@ const Summary: FunctionComponent = ( return <>; } - const probeResponses: Array = []; + const probeResponses: Array = []; - for (const probeResponse of props.probeMonitorResponses || []) { + for (const probeResponse of props.probeMonitors || []) { for (const monitorStepId in probeResponse) { - const probeMonitorResponse: ProbeMonitorResponse = probeResponse[ + const probeMonitor: ProbeMonitor = probeResponse[ monitorStepId - ] as ProbeMonitorResponse; + ] as ProbeMonitor; if ( - probeMonitorResponse.probeId?.toString() === + probeMonitor.probeId?.toString() === selectedProbe?.id?.toString() ) { - probeResponses.push(probeMonitorResponse); + probeResponses.push(probeMonitor); } } } @@ -78,9 +78,9 @@ const Summary: FunctionComponent = (
diff --git a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx index 271cd3877b8..cf267d76ec1 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx @@ -1,4 +1,4 @@ -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import IncomingRequestMonitorView from "./IncomingRequestMonitorSummaryView"; import PingMonitorView from "./PingMonitorView"; import SSLCertificateMonitorView from "./SSLCertificateMonitorView"; @@ -9,30 +9,30 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { monitorType: MonitorType; - probeMonitorResponses?: Array | undefined; // this is an array because of multiple monitor steps. + probeMonitors?: Array | undefined; // this is an array because of multiple monitor steps. incomingMonitorRequest?: IncomingMonitorRequest | undefined; - serverMonitorResponse?: ServerMonitorResponse | undefined; + serverMonitor?: ServerMonitor | undefined; } const SummaryInfo: FunctionComponent = ( props: ComponentProps, ): ReactElement => { type GetProbeableMonitorSummarysInfo = ( - probeMonitorResponse: ProbeMonitorResponse, + probeMonitor: ProbeMonitor, key: number, ) => ReactElement; const getProbableMonitorSummarysInfo: GetProbeableMonitorSummarysInfo = ( - probeMonitorResponse: ProbeMonitorResponse, + probeMonitor: ProbeMonitor, key: number, ): ReactElement => { - if (!probeMonitorResponse) { + if (!probeMonitor) { return ( = ( return ( ); } @@ -62,7 +62,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -71,7 +71,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -80,7 +80,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -90,7 +90,7 @@ const SummaryInfo: FunctionComponent = ( if ( MonitorTypeHelper.isProbableMonitor(props.monitorType) && - (!props.probeMonitorResponses || props.probeMonitorResponses.length === 0) + (!props.probeMonitors || props.probeMonitors.length === 0) ) { return ( = ( return (
- {props.probeMonitorResponses && - props.probeMonitorResponses.map( - (probeMonitorResponse: ProbeMonitorResponse, index: number) => { - return getProbableMonitorSummarysInfo(probeMonitorResponse, index); + {props.probeMonitors && + props.probeMonitors.map( + (probeMonitor: ProbeMonitor, index: number) => { + return getProbableMonitorSummarysInfo(probeMonitor, index); }, )} @@ -133,9 +133,9 @@ const SummaryInfo: FunctionComponent = ( )} {props.monitorType === MonitorType.Server && - props.serverMonitorResponse ? ( + props.serverMonitor ? ( ) : ( <> diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx index d4920be8697..9f06930fbf0 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx @@ -1,32 +1,32 @@ import CustomCodeMonitorSummaryView from "./CustomMonitorSummaryView"; import SummaryScreenshotGroup from "./ScreenshotGroup"; -import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import { GetReactElementFunction } from "CommonUI/src/Types/FunctionTypes"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - syntheticMonitorResponse: SyntheticMonitorResponse; + syntheticMonitor: SyntheticMonitor; monitoredAt: Date; } const SyntheticMonitorItemView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.syntheticMonitorResponse) { + if (!props.syntheticMonitor) { return ( ); } - const syntheticMonitorResponse: SyntheticMonitorResponse = - props.syntheticMonitorResponse; + const syntheticMonitor: SyntheticMonitor = + props.syntheticMonitor; const getMoreDetails: GetReactElementFunction = (): ReactElement => { return (
); @@ -35,11 +35,11 @@ const SyntheticMonitorItemView: FunctionComponent = ( return (
- {props.syntheticMonitorResponse.browserType} -{" "} - {props.syntheticMonitorResponse.screenSizeType} + {props.syntheticMonitor.browserType} -{" "} + {props.syntheticMonitor.screenSizeType}
diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx index b67de8a1d9f..2bd0980e9a3 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx @@ -1,45 +1,45 @@ import SyntheticMonitorItemView from "./SyntheticMonitorItemView"; -import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import HorizontalRule from "CommonUI/src/Components/HorizontalRule/HorizontalRule"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitorResponse: ProbeMonitorResponse; + probeMonitor: ProbeMonitor; } const SyntheticMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { if ( - !props.probeMonitorResponse || - !props.probeMonitorResponse.syntheticMonitorResponse + !props.probeMonitor || + !props.probeMonitor.syntheticMonitor ) { return ( ); } - const syntheticMonitorResponses: Array = - props.probeMonitorResponse.syntheticMonitorResponse; + const syntheticMonitors: Array = + props.probeMonitor.syntheticMonitor; return (
- {syntheticMonitorResponses && - syntheticMonitorResponses.map( + {syntheticMonitors && + syntheticMonitors.map( ( - syntheticMonitorResponse: SyntheticMonitorResponse, + syntheticMonitor: SyntheticMonitor, index: number, ) => { return (
- {index !== syntheticMonitorResponses.length - 1 && ( + {index !== syntheticMonitors.length - 1 && ( )}
diff --git a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx index c67d8cb6520..1655bc63b08 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx @@ -1,5 +1,5 @@ import OneUptimeDate from "Common/Types/Date"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; @@ -8,7 +8,7 @@ import FieldType from "CommonUI/src/Components/Types/FieldType"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitorResponse: ProbeMonitorResponse; + probeMonitor: ProbeMonitor; } const WebsiteMonitorSummaryView: FunctionComponent = ( @@ -17,15 +17,15 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( const [showMoreDetails, setShowMoreDetails] = React.useState(false); let responseTimeInMs: number = - props.probeMonitorResponse?.responseTimeInMs || 0; + props.probeMonitor?.responseTimeInMs || 0; if (responseTimeInMs > 0) { responseTimeInMs = Math.round(responseTimeInMs); } - const fields: Array> = []; + const fields: Array> = []; - if (props.probeMonitorResponse?.responseHeaders) { + if (props.probeMonitor?.responseHeaders) { fields.push({ key: "responseHeaders", title: "Response Headers", @@ -34,7 +34,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( }); } - if (props.probeMonitorResponse?.responseBody) { + if (props.probeMonitor?.responseBody) { fields.push({ key: "responseBody", title: "Response Body", @@ -50,7 +50,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="URL" value={ - props.probeMonitorResponse.monitorDestination?.toString() || "-" + props.probeMonitor.monitorDestination?.toString() || "-" } />
@@ -58,7 +58,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Monitored At" value={ - props.probeMonitorResponse?.monitoredAt + props.probeMonitor?.monitoredAt ? OneUptimeDate.getDateAsLocalFormattedString( - props.probeMonitorResponse.monitoredAt, + props.probeMonitor.monitoredAt, ) : "-" } />
- {props.probeMonitorResponse.failureCause && ( + {props.probeMonitor.failureCause && (
)} {showMoreDetails && fields.length > 0 && (
- + id={"website-monitor-summary-detail"} - item={props.probeMonitorResponse} + item={props.probeMonitor} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Pages/Monitor/View/Index.tsx b/Dashboard/src/Pages/Monitor/View/Index.tsx index cc0568a0e54..68562e1cdbc 100644 --- a/Dashboard/src/Pages/Monitor/View/Index.tsx +++ b/Dashboard/src/Pages/Monitor/View/Index.tsx @@ -21,7 +21,7 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import ObjectID from "Common/Types/ObjectID"; import Alert, { AlertType } from "CommonUI/src/Components/Alerts/Alert"; import Card from "CommonUI/src/Components/Card/Card"; @@ -104,8 +104,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { IncomingMonitorRequest | undefined >(undefined); - const [serverMonitorResponse, setServerMonitorResponse] = useState< - ServerMonitorResponse | undefined + const [serverMonitor, setServerMonitor] = useState< + ServerMonitor | undefined >(undefined); const getUptimePercent: () => ReactElement = (): ReactElement => { @@ -181,7 +181,7 @@ const MonitorView: FunctionComponent = (): ReactElement => { serverMonitorRequestReceivedAt: true, incomingRequestReceivedAt: true, incomingMonitorRequest: true, - serverMonitorResponse: true, + serverMonitor: true, isNoProbeEnabledOnThisMonitor: true, isAllProbesDisconnectedFromThisMonitor: true, }, @@ -193,8 +193,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { setIncomingMonitorRequest(item.incomingMonitorRequest); } - if (item?.serverMonitorResponse) { - setServerMonitorResponse(item.serverMonitorResponse); + if (item?.serverMonitor) { + setServerMonitor(item.serverMonitor); } const monitorStatuses: ListResult = await ModelAPI.getList( @@ -294,7 +294,7 @@ const MonitorView: FunctionComponent = (): ReactElement => { }, }); - const probeMonitorResponses: Array = []; + const probeMonitors: Array = []; for (let i: number = 0; i < monitorProbes.data.length; i++) { const monitorProbe: MonitorProbe | undefined = monitorProbes.data[i]; @@ -311,10 +311,10 @@ const MonitorView: FunctionComponent = (): ReactElement => { continue; } - probeMonitorResponses.push(monitorProbe?.lastMonitoringLog); + probeMonitors.push(monitorProbe?.lastMonitoringLog); } - setProbeResponses(probeMonitorResponses); + setProbeResponses(probeMonitors); } } catch (err) { setError(API.getFriendlyMessage(err)); @@ -604,8 +604,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { monitorType={monitorType!} probes={probes} incomingMonitorRequest={incomingMonitorRequest} - probeMonitorResponses={probeResponses} - serverMonitorResponse={serverMonitorResponse} + probeMonitors={probeResponses} + serverMonitor={serverMonitor} /> {shouldFetchMonitorMetrics && getMonitorMetricsChartGroup()} diff --git a/InfrastructureAgent/agent.go b/InfrastructureAgent/agent.go index 1bf6a56641e..86f462b2ec5 100644 --- a/InfrastructureAgent/agent.go +++ b/InfrastructureAgent/agent.go @@ -114,9 +114,9 @@ func collectMetricsJob(secretKey string, oneuptimeURL string) { } reqData := struct { - ServerMonitorResponse *model.ServerMonitorReport `json:"serverMonitorResponse"` + ServerMonitor *model.ServerMonitorReport `json:"serverMonitor"` }{ - ServerMonitorResponse: metricsReport, + ServerMonitor: metricsReport, } postBuilder := greq.New(oneuptimeURL).Post("/server-monitor/response/ingest/" + secretKey). JSONType().JSONBody(reqData) diff --git a/Ingestor/API/IncomingRequest.ts b/Ingestor/API/IncomingRequest.ts index 371ebfc890f..46c8d78ca06 100644 --- a/Ingestor/API/IncomingRequest.ts +++ b/Ingestor/API/IncomingRequest.ts @@ -14,7 +14,7 @@ import Express, { NextFunction, RequestHandler, } from "CommonServer/Utils/Express"; -import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse"; +import MonitorService from "CommonServer/Utils/Monitor/Monitor"; import Response from "CommonServer/Utils/Response"; import Monitor from "Model/Models/Monitor"; @@ -77,7 +77,7 @@ const processIncomingRequest: RequestHandler = async ( }; // process probe response here. - await ProbeMonitorResponseService.processProbeResponse(incomingRequest); + await MonitorResourceService.monitorResource(incomingRequest); return Response.sendEmptySuccessResponse(req, res); } catch (err) { diff --git a/Ingestor/API/Probe.ts b/Ingestor/API/Probe.ts index 6b235e28c90..319a2889095 100644 --- a/Ingestor/API/Probe.ts +++ b/Ingestor/API/Probe.ts @@ -6,7 +6,7 @@ import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import ProbeStatusReport from "Common/Types/Probe/ProbeStatusReport"; import { DisableAutomaticIncidentCreation } from "CommonServer/EnvironmentConfig"; import GlobalConfigService from "CommonServer/Services/GlobalConfigService"; @@ -20,7 +20,7 @@ import Express, { NextFunction, } from "CommonServer/Utils/Express"; import logger from "CommonServer/Utils/Logger"; -import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse"; +import MonitorService from "CommonServer/Utils/Monitor/Monitor"; import Response from "CommonServer/Utils/Response"; import GlobalConfig from "Model/Models/GlobalConfig"; import Probe from "Model/Models/Probe"; @@ -232,21 +232,21 @@ router.post( }); } - const probeResponse: ProbeMonitorResponse = JSONFunctions.deserialize( - req.body["probeMonitorResponse"], + const probeResponse: ProbeMonitor = JSONFunctions.deserialize( + req.body["probeMonitor"], ) as any; if (!probeResponse) { return Response.sendErrorResponse( req, res, - new BadDataException("ProbeMonitorResponse not found"), + new BadDataException("ProbeMonitor not found"), ); } // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = - await ProbeMonitorResponseService.processProbeResponse(probeResponse); + await MonitorResourceService.monitorResource(probeResponse); return Response.sendJsonObjectResponse(req, res, { probeApiIngestResponse: probeApiIngestResponse, diff --git a/Ingestor/API/ServerMonitor.ts b/Ingestor/API/ServerMonitor.ts index 71b0abca3a5..f594ee3f392 100644 --- a/Ingestor/API/ServerMonitor.ts +++ b/Ingestor/API/ServerMonitor.ts @@ -2,7 +2,7 @@ import BadDataException from "Common/Types/Exception/BadDataException"; import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; import MonitorService from "CommonServer/Services/MonitorService"; @@ -12,7 +12,7 @@ import Express, { ExpressRouter, NextFunction, } from "CommonServer/Utils/Express"; -import ProbeMonitorResponseService from "CommonServer/Utils/Probe/ProbeMonitorResponse"; +import MonitorService from "CommonServer/Utils/Monitor/Monitor"; import Response from "CommonServer/Utils/Response"; import Monitor from "Model/Models/Monitor"; @@ -92,12 +92,12 @@ router.post( // now process this request. - const serverMonitorResponse: ServerMonitorResponse = + const serverMonitor: ServerMonitor = JSONFunctions.deserialize( - req.body["serverMonitorResponse"] as JSONObject, + req.body["serverMonitor"] as JSONObject, ) as any; - if (!serverMonitorResponse) { + if (!serverMonitor) { throw new BadDataException("Invalid Server Monitor Response"); } @@ -105,12 +105,12 @@ router.post( throw new BadDataException("Monitor id not found"); } - serverMonitorResponse.monitorId = monitor.id; + serverMonitor.monitorId = monitor.id; // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = - await ProbeMonitorResponseService.processProbeResponse( - serverMonitorResponse, + await MonitorResourceService.monitorResource( + serverMonitor, ); return Response.sendJsonObjectResponse(req, res, { diff --git a/Model/Models/Monitor.ts b/Model/Models/Monitor.ts index 27cb965bf3a..65540e2eee4 100644 --- a/Model/Models/Monitor.ts +++ b/Model/Models/Monitor.ts @@ -22,7 +22,7 @@ import { JSONObject } from "Common/Types/JSON"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorSteps from "Common/Types/Monitor/MonitorSteps"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; import ObjectID from "Common/Types/ObjectID"; import Permission from "Common/Types/Permission"; import { @@ -709,6 +709,76 @@ export default class Monitor extends BaseModel { }) public incomingRequestReceivedAt?: Date = undefined; + @ColumnAccessControl({ + create: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.CreateProjectMonitor, + ], + read: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.ReadProjectMonitor, + ], + update: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.CreateProjectMonitor, + ], + }) + @Index() + @TableColumn({ + type: TableColumnType.Date, + required: false, + isDefaultValueColumn: false, + title: "Telemetry Monitor Next Monitor At", + description: + "This field is for Telemetry Monitor only. When is the next time we should monitor?", + }) + @Column({ + type: ColumnType.Date, + nullable: true, + }) + public telemetryMonitorNextMonitorAt?: Date = undefined; + + @ColumnAccessControl({ + create: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.CreateProjectMonitor, + ], + read: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.ReadProjectMonitor, + ], + update: [ + Permission.ProjectOwner, + Permission.ProjectAdmin, + Permission.ProjectMember, + Permission.CreateProjectMonitor, + ], + }) + @Index() + @TableColumn({ + type: TableColumnType.Date, + required: false, + isDefaultValueColumn: false, + title: "Telemetry Monitor Last Monitor At", + description: + "This field is for Telemetry Monitor only. When was the last time we monitored?", + }) + @Column({ + type: ColumnType.Date, + nullable: true, + }) + public telemetryMonitorLastMonitorAt?: Date = undefined; + @ColumnAccessControl({ create: [], read: [ @@ -923,7 +993,7 @@ export default class Monitor extends BaseModel { type: ColumnType.JSON, nullable: true, }) - public serverMonitorResponse?: ServerMonitorResponse = undefined; + public serverMonitor?: ServerMonitor = undefined; @ColumnAccessControl({ create: [], diff --git a/Model/Models/MonitorProbe.ts b/Model/Models/MonitorProbe.ts index 6f0afbcb739..a490c5f3b00 100644 --- a/Model/Models/MonitorProbe.ts +++ b/Model/Models/MonitorProbe.ts @@ -18,10 +18,10 @@ import Dictionary from "Common/Types/Dictionary"; import IconProp from "Common/Types/Icon/IconProp"; import ObjectID from "Common/Types/ObjectID"; import Permission from "Common/Types/Permission"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm"; -export type MonitorStepProbeResponse = Dictionary; +export type MonitorStepProbeResponse = Dictionary; @EnableDocumentation() @TenantColumn("projectId") diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index 3bddfb4ff66..f7d48d64b13 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -9,7 +9,7 @@ import URL from "Common/Types/API/URL"; import OneUptimeDate from "Common/Types/Date"; import APIException from "Common/Types/Exception/ApiException"; import { JSONArray } from "Common/Types/JSON"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import Sleep from "Common/Types/Sleep"; import API from "Common/Utils/API"; import logger from "CommonServer/Utils/Logger"; @@ -84,7 +84,7 @@ export default class FetchListAndProbe { ); const probeMonitorPromises: Array< - Promise> + Promise> > = []; // Array of promises to probe monitors for (const monitor of monitors) { @@ -93,7 +93,7 @@ export default class FetchListAndProbe { // all settled // eslint-disable-next-line no-undef - const results: PromiseSettledResult<(ProbeMonitorResponse | null)[]>[] = + const results: PromiseSettledResult<(ProbeMonitor | null)[]>[] = await Promise.allSettled(probeMonitorPromises); let resultIndex: number = 0; diff --git a/Probe/Utils/Monitors/Monitor.ts b/Probe/Utils/Monitors/Monitor.ts index 3cba8be650e..fa7ab600450 100644 --- a/Probe/Utils/Monitors/Monitor.ts +++ b/Probe/Utils/Monitors/Monitor.ts @@ -4,7 +4,7 @@ import ProbeAPIRequest from "../ProbeAPIRequest"; import ApiMonitor, { APIResponse } from "./MonitorTypes/ApiMonitor"; import CustomCodeMonitor from "./MonitorTypes/CustomCodeMonitor"; import PingMonitor, { PingResponse } from "./MonitorTypes/PingMonitor"; -import PortMonitor, { PortMonitorResponse } from "./MonitorTypes/PortMonitor"; +import PortMonitor, { PortMonitor } from "./MonitorTypes/PortMonitor"; import SSLMonitor, { SslResponse } from "./MonitorTypes/SslMonitor"; import SyntheticMonitor from "./MonitorTypes/SyntheticMonitor"; import WebsiteMonitor, { @@ -16,14 +16,14 @@ import OneUptimeDate from "Common/Types/Date"; import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; import MonitorStep from "Common/Types/Monitor/MonitorStep"; import MonitorType from "Common/Types/Monitor/MonitorType"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; -import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; import Port from "Common/Types/Port"; -import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; +import ProbeMonitor from "Common/Types/Monitor/Monitor"; import ScreenSizeType from "Common/Types/ScreenSizeType"; import API from "Common/Utils/API"; import LocalCache from "CommonServer/Infrastructure/LocalCache"; @@ -33,8 +33,8 @@ import Monitor from "Model/Models/Monitor"; export default class MonitorUtil { public static async probeMonitor( monitor: Monitor, - ): Promise> { - const results: Array = []; + ): Promise> { + const results: Array = []; if ( !monitor.monitorSteps || @@ -50,7 +50,7 @@ export default class MonitorUtil { continue; } - const result: ProbeMonitorResponse | null = await this.probeMonitorStep( + const result: ProbeMonitor | null = await this.probeMonitorStep( monitorStep, monitor, ); @@ -65,7 +65,7 @@ export default class MonitorUtil { ), { ...ProbeAPIRequest.getDefaultRequestBody(), - probeMonitorResponse: result as any, + probeMonitor: result as any, }, {}, {}, @@ -119,8 +119,8 @@ export default class MonitorUtil { public static async probeMonitorStep( monitorStep: MonitorStep, monitor: Monitor, - ): Promise { - const result: ProbeMonitorResponse = { + ): Promise { + const result: ProbeMonitor = { monitorStepId: monitorStep.id, monitorId: monitor.id!, probeId: ProbeUtil.getProbeId(), @@ -145,7 +145,7 @@ export default class MonitorUtil { if (LocalCache.getString("PROBE", "PING_MONITORING") === "PORT") { // probe is online but ping monitoring is blocked by the cloud provider. Fallback to port monitoring. - const response: PortMonitorResponse | null = await PortMonitor.ping( + const response: PortMonitor | null = await PortMonitor.ping( monitorStep.data?.monitorDestination, new Port(80), // use port 80 by default. { @@ -197,7 +197,7 @@ export default class MonitorUtil { result.monitorDestinationPort = monitorStep.data.monitorDestinationPort; - const response: PortMonitorResponse | null = await PortMonitor.ping( + const response: PortMonitor | null = await PortMonitor.ping( monitorStep.data?.monitorDestination, monitorStep.data.monitorDestinationPort, { @@ -222,7 +222,7 @@ export default class MonitorUtil { return result; } - const response: Array | null = + const response: Array | null = await SyntheticMonitor.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, @@ -235,7 +235,7 @@ export default class MonitorUtil { return null; } - result.syntheticMonitorResponse = response; + result.syntheticMonitor = response; } if (monitor.monitorType === MonitorType.CustomJavaScriptCode) { @@ -245,7 +245,7 @@ export default class MonitorUtil { return result; } - const response: CustomCodeMonitorResponse | null = + const response: CustomCodeMonitor | null = await CustomCodeMonitor.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, @@ -255,7 +255,7 @@ export default class MonitorUtil { return null; } - result.customCodeMonitorResponse = response; + result.customCodeMonitor = response; } if (monitor.monitorType === MonitorType.SSLCertificate) { diff --git a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts index dcb8a928fef..f5a62b5d852 100644 --- a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts @@ -1,6 +1,6 @@ import { PROBE_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS } from "../../../Config"; import ReturnResult from "Common/Types/IsolatedVM/ReturnResult"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; import ObjectID from "Common/Types/ObjectID"; import logger from "CommonServer/Utils/Logger"; import VMRunner from "CommonServer/Utils/VM/VMRunner"; @@ -13,7 +13,7 @@ export interface CustomCodeMonitorOptions { export default class CustomCodeMonitor { public static async execute( options: CustomCodeMonitorOptions, - ): Promise { + ): Promise { if (!options) { // this should never happen options = { @@ -21,7 +21,7 @@ export default class CustomCodeMonitor { }; } - const scriptResult: CustomCodeMonitorResponse = { + const scriptResult: CustomCodeMonitor = { logMessages: [], scriptError: undefined, result: undefined, diff --git a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts index 5cbb17a76c9..8f145f7faa6 100644 --- a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts @@ -14,7 +14,7 @@ import logger from "CommonServer/Utils/Logger"; import net from "net"; // TODO - make sure it work for the IPV6 -export interface PortMonitorResponse { +export interface PortMonitor { isOnline: boolean; responseTimeInMS?: PositiveNumber | undefined; failureCause: string; @@ -33,7 +33,7 @@ export default class PortMonitor { host: Hostname | IPv4 | IPv6 | URL, port: Port, pingOptions?: PingOptions, - ): Promise { + ): Promise { if (!pingOptions) { pingOptions = {}; } diff --git a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts index 745c436b0ae..e3263ea5af1 100644 --- a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts @@ -2,7 +2,7 @@ import OnlineCheck from "../../OnlineCheck"; import URL from "Common/Types/API/URL"; import OneUptimeDate from "Common/Types/Date"; import BadDataException from "Common/Types/Exception/BadDataException"; -import SSLMonitorReponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; +import SSLMonitorReponse from "Common/Types/Monitor/SSLMonitor/SslMonitor"; import ObjectID from "Common/Types/ObjectID"; import PositiveNumber from "Common/Types/PositiveNumber"; import Sleep from "Common/Types/Sleep"; @@ -48,7 +48,7 @@ export default class SSLMonitor { ); try { - const res: SslResponse = await this.getSslMonitorResponse( + const res: SslResponse = await this.getSslMonitor( url.hostname.hostname, url.hostname.port?.toNumber() || 443, ); @@ -111,7 +111,7 @@ export default class SSLMonitor { } } - public static async getSslMonitorResponse( + public static async getSslMonitor( host: string, port = 443, ): Promise { diff --git a/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts index 00728c321f2..6a3a1e6c9bd 100644 --- a/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts @@ -3,7 +3,7 @@ import BadDataException from "Common/Types/Exception/BadDataException"; import ReturnResult from "Common/Types/IsolatedVM/ReturnResult"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; import ScreenSizeType from "Common/Types/Monitor/SyntheticMonitors/ScreenSizeType"; -import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; import ObjectID from "Common/Types/ObjectID"; import logger from "CommonServer/Utils/Logger"; import VMRunner from "CommonServer/Utils/VM/VMRunner"; @@ -20,8 +20,8 @@ export interface SyntheticMonitorOptions { export default class SyntheticMonitor { public static async execute( options: SyntheticMonitorOptions, - ): Promise | null> { - const results: Array = []; + ): Promise | null> { + const results: Array = []; for (const browserType of options.browserTypes || []) { for (const screenSizeType of options.screenSizeTypes || []) { @@ -29,7 +29,7 @@ export default class SyntheticMonitor { `Running Synthetic Monitor: ${options?.monitorId?.toString()}, Screen Size: ${screenSizeType}, Browser: ${browserType}`, ); - const result: SyntheticMonitorResponse | null = + const result: SyntheticMonitor | null = await this.executeByBrowserAndScreenSize({ script: options.script, browserType: browserType, @@ -51,7 +51,7 @@ export default class SyntheticMonitor { script: string; browserType: BrowserType; screenSizeType: ScreenSizeType; - }): Promise { + }): Promise { if (!options) { // this should never happen options = { @@ -61,7 +61,7 @@ export default class SyntheticMonitor { }; } - const scriptResult: SyntheticMonitorResponse = { + const scriptResult: SyntheticMonitor = { logMessages: [], scriptError: undefined, result: undefined, From 29764ae7c7582ab30f25ce37d6ff85da440f09a1 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 19:39:36 -0600 Subject: [PATCH 4/7] refactor: Update monitor interfaces to use consistent naming --- .../SyntheticMonitorResponse.ts | 4 +- Common/Types/Probe/ProbeMonitorResponse.ts | 12 +-- .../Monitor/Criteria/APIRequestCriteria.ts | 14 ++-- .../Criteria/CustomCodeMonitorCriteria.ts | 6 +- .../Criteria/IncomingRequestCriteria.ts | 4 +- .../Monitor/Criteria/SSLMonitorCriteria.ts | 12 +-- .../Monitor/Criteria/ServerMonitorCriteria.ts | 36 ++++---- .../Monitor/Criteria/SyntheticMonitor.ts | 4 +- CommonServer/Utils/Monitor/DataToProcess.ts | 8 +- CommonServer/Utils/Monitor/MonitorResource.ts | 82 +++++++++---------- Model/Models/Monitor.ts | 4 +- Model/Models/MonitorProbe.ts | 4 +- 12 files changed, 95 insertions(+), 95 deletions(-) diff --git a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts index d1da41ff3dc..9a3a037046c 100644 --- a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts +++ b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts @@ -1,10 +1,10 @@ -import CustomCodeMonitor from "../CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "../CustomCodeMonitor/CustomCodeMonitorResponse"; import BrowserType from "./BrowserType"; import ScreenSizeType from "./ScreenSizeType"; import Screenshots from "./Screenshot"; export default interface SyntheticMonitor - extends CustomCodeMonitor { + extends CustomCodeMonitorResponse { screenshots?: Screenshots | undefined; // base 64 encoded screenshots browserType: BrowserType; screenSizeType: ScreenSizeType; diff --git a/Common/Types/Probe/ProbeMonitorResponse.ts b/Common/Types/Probe/ProbeMonitorResponse.ts index 372cddfc6f5..00e5eef4085 100644 --- a/Common/Types/Probe/ProbeMonitorResponse.ts +++ b/Common/Types/Probe/ProbeMonitorResponse.ts @@ -3,9 +3,9 @@ import URL from "../API/URL"; import Dictionary from "../Dictionary"; import IP from "../IP/IP"; import { JSONObject } from "../JSON"; -import CustomCodeMonitor from "../Monitor/CustomCodeMonitor/CustomCodeMonitor"; -import SslMonitor from "../Monitor/SSLMonitor/SslMonitor"; -import SyntheticMonitor from "../Monitor/SyntheticMonitors/SyntheticMonitor"; +import CustomCodeMonitorResponse from "../Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import SslMonitorResponse from "../Monitor/SSLMonitor/SslMonitorResponse"; +import SyntheticMonitorResponse from "../Monitor/SyntheticMonitors/SyntheticMonitorResponse"; import ObjectID from "../ObjectID"; import Port from "../Port"; @@ -21,8 +21,8 @@ export default interface ProbeMonitor { monitorId: ObjectID; probeId: ObjectID; failureCause: string; - sslResponse?: SslMonitor | undefined; - syntheticMonitor?: Array | undefined; - customCodeMonitor?: CustomCodeMonitor | undefined; + sslResponse?: SslMonitorResponse| undefined; + syntheticMonitor?: Array | undefined; + customCodeMonitor?: CustomCodeMonitorResponse | undefined; monitoredAt: Date; } diff --git a/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts b/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts index 79ce07b4446..68f5e30d4a0 100644 --- a/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/APIRequestCriteria.ts @@ -7,7 +7,7 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Typeof from "Common/Types/Typeof"; export default class APIRequestCriteria { @@ -46,7 +46,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitor).isOnline; + (input.dataToProcess as ProbeMonitorResponse).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, @@ -60,7 +60,7 @@ export default class APIRequestCriteria { const value: Array | number = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitor).responseTimeInMs!; + (input.dataToProcess as ProbeMonitorResponse).responseTimeInMs!; return CompareCriteria.compareCriteriaNumbers({ value: value, @@ -75,7 +75,7 @@ export default class APIRequestCriteria { const value: Array | number = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitor).responseCode!; + (input.dataToProcess as ProbeMonitorResponse).responseCode!; return CompareCriteria.compareCriteriaNumbers({ value: value, @@ -86,7 +86,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseBody) { let responseBody: string | JSONObject | undefined = ( - input.dataToProcess as ProbeMonitor + input.dataToProcess as ProbeMonitorResponse ).responseBody; if (responseBody && typeof responseBody === Typeof.Object) { @@ -123,7 +123,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseHeader) { const headerKeys: Array = Object.keys( - (input.dataToProcess as ProbeMonitor).responseHeaders || {}, + (input.dataToProcess as ProbeMonitorResponse).responseHeaders || {}, ).map((key: string) => { return key.toLowerCase(); }); @@ -154,7 +154,7 @@ export default class APIRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResponseHeaderValue) { const headerValues: Array = Object.values( - (input.dataToProcess as ProbeMonitor).responseHeaders || {}, + (input.dataToProcess as ProbeMonitorResponse).responseHeaders || {}, ).map((key: string) => { return key.toLowerCase(); }); diff --git a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts index 5d1e3567637..8ca6de3ba1b 100644 --- a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts @@ -1,10 +1,10 @@ import CompareCriteria from "./CompareCriteria"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; export default class CustomCodeMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - Monitor: CustomCodeMonitor; + Monitor: CustomCodeMonitorResponse; criteriaFilter: CriteriaFilter; }): Promise { // Server Monitoring Checks @@ -12,7 +12,7 @@ export default class CustomCodeMonitoringCriteria { let threshold: number | string | undefined | null = input.criteriaFilter.value; - const syntheticMonitor: CustomCodeMonitor = + const syntheticMonitor: CustomCodeMonitorResponse = input.Monitor; if (input.criteriaFilter.checkOn === CheckOn.ExecutionTime) { diff --git a/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts b/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts index 2a9f7edda89..f61a91989a5 100644 --- a/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/IncomingRequestCriteria.ts @@ -11,7 +11,7 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import Typeof from "Common/Types/Typeof"; import EvaluateOverTime from "./EvaluateOverTime"; import CompareCriteria from "./CompareCriteria"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; export default class IncomingRequestCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { @@ -60,7 +60,7 @@ export default class IncomingRequestCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitor).isOnline; + (input.dataToProcess as ProbeMonitorResponse).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, diff --git a/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts index eba5fbb2e66..d97790f7929 100644 --- a/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/SSLMonitorCriteria.ts @@ -6,8 +6,8 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import SslMonitor from "Common/Types/Monitor/SSLMonitor/SslMonitor"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import SslMonitorResponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import EvaluateOverTime from "./EvaluateOverTime"; export default class ServerMonitorCriteria { @@ -18,10 +18,10 @@ export default class ServerMonitorCriteria { let threshold: number | string | undefined | null = input.criteriaFilter.value; - const dataToProcess: ProbeMonitor = - input.dataToProcess as ProbeMonitor; + const dataToProcess: ProbeMonitorResponse = + input.dataToProcess as ProbeMonitorResponse; - const sslResponse: SslMonitor | undefined = + const sslResponse: SslMonitorResponse | undefined = dataToProcess.sslResponse; let overTimeValue: Array | number | boolean | undefined = @@ -49,7 +49,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.checkOn === CheckOn.IsOnline) { const currentIsOnline: boolean | Array = (overTimeValue as Array) || - (input.dataToProcess as ProbeMonitor).isOnline; + (input.dataToProcess as ProbeMonitorResponse).isOnline; return CompareCriteria.compareCriteriaBoolean({ value: currentIsOnline, diff --git a/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts index 92981913cc5..242992ab573 100644 --- a/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/ServerMonitorCriteria.ts @@ -9,9 +9,9 @@ import { CriteriaFilter, FilterType, } from "Common/Types/Monitor/CriteriaFilter"; -import ServerMonitor, { +import ServerMonitorResponse, { ServerProcess, -} from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +} from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; export default class ServerMonitorCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { @@ -45,7 +45,7 @@ export default class ServerMonitorCriteria { } } - const lastCheckTime: Date = (input.dataToProcess as ServerMonitor) + const lastCheckTime: Date = (input.dataToProcess as ServerMonitorResponse) .requestReceivedAt; const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes( @@ -92,13 +92,13 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.CPUUsagePercent && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); const currentCpuPercent: number | Array = (overTimeValue as Array) || - (input.dataToProcess as ServerMonitor) + (input.dataToProcess as ServerMonitorResponse) .basicInfrastructureMetrics?.cpuMetrics.percentUsed || 0; @@ -111,13 +111,13 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.MemoryUsagePercent && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); const memoryPercent: number | Array = (overTimeValue as Array) || - (input.dataToProcess as ServerMonitor) + (input.dataToProcess as ServerMonitorResponse) .basicInfrastructureMetrics?.memoryMetrics.percentUsed || 0; @@ -130,7 +130,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.DiskUsagePercent && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { threshold = CompareCriteria.convertToNumber(threshold); @@ -139,7 +139,7 @@ export default class ServerMonitorCriteria { const diskPercent: number = ( - input.dataToProcess as ServerMonitor + input.dataToProcess as ServerMonitorResponse ).basicInfrastructureMetrics?.diskMetrics.filter( (item: BasicDiskMetrics) => { return ( @@ -159,7 +159,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessName && threshold && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { const thresholdProcessName: string = threshold .toString() @@ -168,7 +168,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processNames: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.name.trim().toLowerCase(); }, @@ -183,7 +183,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processNames: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.name.trim().toLowerCase(); }, @@ -200,7 +200,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessPID && threshold && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { const thresholdProcessPID: string = threshold .toString() @@ -209,7 +209,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processPIDs: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.pid.toString().trim().toLowerCase(); }, @@ -224,7 +224,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processPIDs: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.pid.toString().trim().toLowerCase(); }, @@ -243,7 +243,7 @@ export default class ServerMonitorCriteria { if ( input.criteriaFilter.checkOn === CheckOn.ServerProcessCommand && threshold && - !(input.dataToProcess as ServerMonitor).onlyCheckRequestReceivedAt + !(input.dataToProcess as ServerMonitorResponse).onlyCheckRequestReceivedAt ) { const thresholdProcessCommand: string = threshold .toString() @@ -252,7 +252,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsExecuting) { const processCommands: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.command.trim().toLowerCase(); }, @@ -267,7 +267,7 @@ export default class ServerMonitorCriteria { if (input.criteriaFilter.filterType === FilterType.IsNotExecuting) { const processCommands: Array = - (input.dataToProcess as ServerMonitor)?.processes?.map( + (input.dataToProcess as ServerMonitorResponse)?.processes?.map( (item: ServerProcess) => { return item.command.trim().toLowerCase(); }, diff --git a/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts index 9bdf8020fd7..120964ca088 100644 --- a/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts +++ b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts @@ -1,11 +1,11 @@ import CompareCriteria from "./CompareCriteria"; import CustomCodeMonitoringCriteria from "./CustomCodeMonitorCriteria"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; +import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; export default class SyntheticMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - Monitor: Array; + Monitor: Array; criteriaFilter: CriteriaFilter; }): Promise { for (const syntheticMonitor of input.Monitor) { diff --git a/CommonServer/Utils/Monitor/DataToProcess.ts b/CommonServer/Utils/Monitor/DataToProcess.ts index 2533c089a22..f808c856f61 100644 --- a/CommonServer/Utils/Monitor/DataToProcess.ts +++ b/CommonServer/Utils/Monitor/DataToProcess.ts @@ -1,10 +1,10 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; type DataToProcess = - | ProbeMonitor + | ProbeMonitorResponse | IncomingMonitorRequest - | ServerMonitor; + | ServerMonitorResponse; export default DataToProcess; diff --git a/CommonServer/Utils/Monitor/MonitorResource.ts b/CommonServer/Utils/Monitor/MonitorResource.ts index 05381674131..8e75d0ddf86 100644 --- a/CommonServer/Utils/Monitor/MonitorResource.ts +++ b/CommonServer/Utils/Monitor/MonitorResource.ts @@ -26,7 +26,7 @@ import { CriteriaFilter, FilterCondition, } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorCriteria from "Common/Types/Monitor/MonitorCriteria"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; @@ -35,10 +35,10 @@ import MonitorSteps from "Common/Types/Monitor/MonitorSteps"; import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Typeof from "Common/Types/Typeof"; import MonitorMetricsByMinute from "Model/AnalyticsModels/MonitorMetricsByMinute"; import Incident from "Model/Models/Incident"; @@ -128,13 +128,13 @@ export default class MonitorResourceService { monitor.monitorType && MonitorTypeHelper.isProbableMonitor(monitor.monitorType) ) { - dataToProcess = dataToProcess as ProbeMonitor; - if ((dataToProcess as ProbeMonitor).probeId) { + dataToProcess = dataToProcess as ProbeMonitorResponse; + if ((dataToProcess as ProbeMonitorResponse).probeId) { const monitorProbe: MonitorProbe | null = await MonitorProbeService.findOneBy({ query: { monitorId: monitor.id!, - probeId: (dataToProcess as ProbeMonitor).probeId!, + probeId: (dataToProcess as ProbeMonitorResponse).probeId!, }, select: { lastMonitoringLog: true, @@ -151,13 +151,13 @@ export default class MonitorResourceService { await MonitorProbeService.updateOneBy({ query: { monitorId: monitor.id!, - probeId: (dataToProcess as ProbeMonitor).probeId!, + probeId: (dataToProcess as ProbeMonitorResponse).probeId!, }, data: { lastMonitoringLog: { ...(monitorProbe.lastMonitoringLog || {}), [( - dataToProcess as ProbeMonitor + dataToProcess as ProbeMonitorResponse ).monitorStepId.toString()]: { ...JSON.parse(JSON.stringify(dataToProcess)), monitoredAt: OneUptimeDate.getCurrentDate(), @@ -204,7 +204,7 @@ export default class MonitorResourceService { serverMonitorRequestReceivedAt: ( dataToProcess as ServerMonitor ).requestReceivedAt!, - serverMonitor: dataToProcess as ServerMonitor, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. + serverMonitorResponse: dataToProcess as ServerMonitor, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. }, props: { isRoot: true, @@ -280,12 +280,12 @@ export default class MonitorResourceService { const monitorStep: MonitorStep | undefined = monitorSteps.data.monitorStepsInstanceArray[0]; - if ((dataToProcess as ProbeMonitor).monitorStepId) { + if ((dataToProcess as ProbeMonitorResponse).monitorStepId) { monitorSteps.data.monitorStepsInstanceArray.find( (monitorStep: MonitorStep) => { return ( monitorStep.id.toString() === - (dataToProcess as ProbeMonitor).monitorStepId.toString() + (dataToProcess as ProbeMonitorResponse).monitorStepId.toString() ); }, ); @@ -477,25 +477,25 @@ export default class MonitorResourceService { } } - if ((data.dataToProcess as ProbeMonitor).responseTimeInMs) { + if ((data.dataToProcess as ProbeMonitorResponse).responseTimeInMs) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ResponseTime; monitorMetricsByMinute.metricValue = ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).responseTimeInMs; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitor).isOnline !== undefined) { + if ((data.dataToProcess as ProbeMonitorResponse).isOnline !== undefined) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; @@ -504,38 +504,38 @@ export default class MonitorResourceService { monitorMetricsByMinute.metricValue = 0; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), }; - if ((data.dataToProcess as ProbeMonitor).isOnline) { + if ((data.dataToProcess as ProbeMonitorResponse).isOnline) { monitorMetricsByMinute.metricValue = 1; } itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitor).responseCode) { + if ((data.dataToProcess as ProbeMonitorResponse).responseCode) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ResponseStatusCode; monitorMetricsByMinute.metricValue = ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).responseCode; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), }; itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitor).syntheticMonitor) { + if ((data.dataToProcess as ProbeMonitorResponse).syntheticMonitor) { for (const syntheticMonitor of ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).syntheticMonitor || []) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); @@ -546,7 +546,7 @@ export default class MonitorResourceService { syntheticMonitor.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), browserType: syntheticMonitor.browserType, screenSizeType: syntheticMonitor.screenSizeType, @@ -557,10 +557,10 @@ export default class MonitorResourceService { } if ( - (data.dataToProcess as ProbeMonitor).customCodeMonitor + (data.dataToProcess as ProbeMonitorResponse).customCodeMonitor ) { const customCodeMonitor: CustomCodeMonitor = ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).customCodeMonitor!; const monitorMetricsByMinute: MonitorMetricsByMinute = @@ -572,7 +572,7 @@ export default class MonitorResourceService { customCodeMonitor.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( - data.dataToProcess as ProbeMonitor + data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), }; @@ -791,10 +791,10 @@ export default class MonitorResourceService { if ( input.dataToProcess && - (input.dataToProcess as ProbeMonitor).probeId + (input.dataToProcess as ProbeMonitorResponse).probeId ) { incident.createdByProbeId = ( - input.dataToProcess as ProbeMonitor + input.dataToProcess as ProbeMonitorResponse ).probeId; } @@ -816,7 +816,7 @@ export default class MonitorResourceService { openIncident: Incident; rootCause: string; dataToProcess: - | ProbeMonitor + | ProbeMonitorResponse | IncomingMonitorRequest | DataToProcess; }): Promise { @@ -933,9 +933,9 @@ export default class MonitorResourceService { `; } - if ((input.dataToProcess as ProbeMonitor).failureCause) { + if ((input.dataToProcess as ProbeMonitorResponse).failureCause) { input.probeApiIngestResponse.rootCause += ` -**Cause**: ${(input.dataToProcess as ProbeMonitor).failureCause || ""} +**Cause**: ${(input.dataToProcess as ProbeMonitorResponse).failureCause || ""} `; } break; @@ -1046,11 +1046,11 @@ export default class MonitorResourceService { let responseBody: JSONObject | null = null; try { responseBody = JSON.parse( - ((input.dataToProcess as ProbeMonitor) + ((input.dataToProcess as ProbeMonitorResponse) .responseBody as string) || "{}", ); } catch (err) { - responseBody = (input.dataToProcess as ProbeMonitor) + responseBody = (input.dataToProcess as ProbeMonitorResponse) .responseBody as JSONObject; } @@ -1064,13 +1064,13 @@ export default class MonitorResourceService { storageMap = { responseBody: responseBody, - responseHeaders: (input.dataToProcess as ProbeMonitor) + responseHeaders: (input.dataToProcess as ProbeMonitorResponse) .responseHeaders, - responseStatusCode: (input.dataToProcess as ProbeMonitor) + responseStatusCode: (input.dataToProcess as ProbeMonitorResponse) .responseCode, - responseTimeInMs: (input.dataToProcess as ProbeMonitor) + responseTimeInMs: (input.dataToProcess as ProbeMonitorResponse) .responseTimeInMs, - isOnline: (input.dataToProcess as ProbeMonitor).isOnline, + isOnline: (input.dataToProcess as ProbeMonitorResponse).isOnline, }; } @@ -1129,11 +1129,11 @@ export default class MonitorResourceService { if ( input.monitor.monitorType === MonitorType.CustomJavaScriptCode && - (input.dataToProcess as ProbeMonitor).customCodeMonitor + (input.dataToProcess as ProbeMonitorResponse).customCodeMonitor ) { const criteriaResult: string | null = await CustomCodeMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - Monitor: (input.dataToProcess as ProbeMonitor) + Monitor: (input.dataToProcess as ProbeMonitorResponse) .customCodeMonitor!, criteriaFilter: input.criteriaFilter, }); @@ -1145,12 +1145,12 @@ export default class MonitorResourceService { if ( input.monitor.monitorType === MonitorType.SyntheticMonitor && - (input.dataToProcess as ProbeMonitor).syntheticMonitor + (input.dataToProcess as ProbeMonitorResponse).syntheticMonitor ) { const criteriaResult: string | null = await SyntheticMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ Monitor: - (input.dataToProcess as ProbeMonitor) + (input.dataToProcess as ProbeMonitorResponse) .syntheticMonitor || [], criteriaFilter: input.criteriaFilter, }); diff --git a/Model/Models/Monitor.ts b/Model/Models/Monitor.ts index 65540e2eee4..ddcd1d14515 100644 --- a/Model/Models/Monitor.ts +++ b/Model/Models/Monitor.ts @@ -22,7 +22,7 @@ import { JSONObject } from "Common/Types/JSON"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorSteps from "Common/Types/Monitor/MonitorSteps"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import Permission from "Common/Types/Permission"; import { @@ -993,7 +993,7 @@ export default class Monitor extends BaseModel { type: ColumnType.JSON, nullable: true, }) - public serverMonitor?: ServerMonitor = undefined; + public serverMonitorResponse?: ServerMonitorResponse = undefined; @ColumnAccessControl({ create: [], diff --git a/Model/Models/MonitorProbe.ts b/Model/Models/MonitorProbe.ts index a490c5f3b00..6f0afbcb739 100644 --- a/Model/Models/MonitorProbe.ts +++ b/Model/Models/MonitorProbe.ts @@ -18,10 +18,10 @@ import Dictionary from "Common/Types/Dictionary"; import IconProp from "Common/Types/Icon/IconProp"; import ObjectID from "Common/Types/ObjectID"; import Permission from "Common/Types/Permission"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm"; -export type MonitorStepProbeResponse = Dictionary; +export type MonitorStepProbeResponse = Dictionary; @EnableDocumentation() @TenantColumn("projectId") From 13b1998261f6809afaa8610a4152a4b94834bbb1 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 19:56:45 -0600 Subject: [PATCH 5/7] refactor: Update import statements for ProbeMonitor and ServerMonitor to use ProbeMonitorResponse and ServerMonitorResponse --- .../IncomingRequestMonitor/CheckHeartbeat.ts | 4 +- .../Jobs/ServerMonitor/CheckOnlineStatus.ts | 11 +++-- .../MonitorTelemetryMonitor.ts | 4 +- .../SummaryView/CustomMonitorSummaryView.tsx | 10 ++-- .../Monitor/SummaryView/PingMonitorView.tsx | 4 +- .../SummaryView/SSLCertificateMonitorView.tsx | 8 ++-- .../Monitor/SummaryView/ServerMonitorView.tsx | 48 +++++++++---------- .../Monitor/SummaryView/Summary.tsx | 12 ++--- .../Monitor/SummaryView/SummaryInfo.tsx | 18 +++---- .../SummaryView/SyntheticMonitorItemView.tsx | 6 +-- .../SummaryView/SyntheticMonitorView.tsx | 10 ++-- .../SummaryView/WebsiteMonitorView.tsx | 2 +- Dashboard/src/Pages/Monitor/View/Index.tsx | 2 +- Ingestor/API/IncomingRequest.ts | 4 +- Ingestor/API/Probe.ts | 10 ++-- Ingestor/API/ServerMonitor.ts | 8 ++-- Probe/Jobs/Monitor/FetchList.ts | 2 +- Probe/Utils/Monitors/Monitor.ts | 2 +- 18 files changed, 83 insertions(+), 82 deletions(-) diff --git a/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts b/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts index 4699f854725..57f28407943 100644 --- a/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts +++ b/App/FeatureSet/Workers/Jobs/IncomingRequestMonitor/CheckHeartbeat.ts @@ -6,7 +6,7 @@ import MonitorType from "Common/Types/Monitor/MonitorType"; import { EVERY_MINUTE } from "Common/Utils/CronTime"; import MonitorService from "CommonServer/Services/MonitorService"; import logger from "CommonServer/Utils/Logger"; -import MonitorService from "CommonServer/Utils/Monitor/Monitor"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Monitor from "Model/Models/Monitor"; RunCron( @@ -67,7 +67,7 @@ RunCron( onlyCheckForIncomingRequestReceivedAt: true, }; - await MonitorResourceService.monitorResource(incomingRequest); + await MonitorResourceUtil.monitorResource(incomingRequest); } catch (error) { logger.error( `Error while processing incoming request monitor: ${monitor.id?.toString()}`, diff --git a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts index 8c007cf0e18..93f403d18c5 100644 --- a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts +++ b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts @@ -3,12 +3,12 @@ import LIMIT_MAX from "Common/Types/Database/LimitMax"; import OneUptimeDate from "Common/Types/Date"; import { CheckOn } from "Common/Types/Monitor/CriteriaFilter"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import { EVERY_MINUTE } from "Common/Utils/CronTime"; import MonitorService from "CommonServer/Services/MonitorService"; import QueryHelper from "CommonServer/Types/Database/QueryHelper"; import logger from "CommonServer/Utils/Logger"; -import MonitorService from "CommonServer/Utils/Monitor/Monitor"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Monitor from "Model/Models/Monitor"; RunCron( @@ -48,7 +48,7 @@ RunCron( continue; } - const serverMonitor: ServerMonitor = { + const serverMonitorResponse: ServerMonitorResponse = { monitorId: monitor.id!, onlyCheckRequestReceivedAt: true, requestReceivedAt: @@ -56,9 +56,10 @@ RunCron( hostname: "", }; - await MonitorResourceService.monitorResource( - serverMonitor, + await MonitorResourceUtil.monitorResource( + serverMonitorResponse, ); + } catch (error) { logger.error( `Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`, diff --git a/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts index 9e228548ee1..a26dd620298 100644 --- a/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts +++ b/App/FeatureSet/Workers/Jobs/TelemetryMonitor/MonitorTelemetryMonitor.ts @@ -7,7 +7,7 @@ import { EVERY_MINUTE } from "Common/Utils/CronTime"; import MonitorService from "CommonServer/Services/MonitorService"; import QueryHelper from "CommonServer/Types/Database/QueryHelper"; import logger from "CommonServer/Utils/Logger"; -import MonitorResourceService from "CommonServer/Utils/Monitor/MonitorResource"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Monitor from "Model/Models/Monitor"; import CronTab from "CommonServer/Utils/CronTab"; @@ -98,7 +98,7 @@ RunCron( onlyCheckForIncomingRequestReceivedAt: true, }; - await MonitorResourceService.monitorResource(incomingRequest); + await MonitorResourceUtil.monitorResource(incomingRequest); } catch (error) { logger.error( `Error while processing incoming request monitor: ${monitor.id?.toString()}`, diff --git a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx index d4ed72fec99..c481f6c67fb 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx @@ -1,5 +1,5 @@ import OneUptimeDate from "Common/Types/Date"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; @@ -9,7 +9,7 @@ import FieldType from "CommonUI/src/Components/Types/FieldType"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - customCodeMonitor: CustomCodeMonitor; + customCodeMonitor: CustomCodeMonitorResponse; moreDetailElement?: ReactElement; monitoredAt: Date; } @@ -25,7 +25,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( const [showMoreDetails, setShowMoreDetails] = React.useState(false); - const customMonitor: CustomCodeMonitor = + const customMonitor: CustomCodeMonitorResponse = props.customCodeMonitor; let executionTimeInMS: number = customMonitor.executionTimeInMS || 0; @@ -34,7 +34,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( executionTimeInMS = Math.round(executionTimeInMS); } - const fields: Array> = []; + const fields: Array> = []; if ( customMonitor.logMessages && @@ -95,7 +95,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( {showMoreDetails && (
- + id={"custom-code-monitor-summary-detail"} item={customMonitor} fields={fields} diff --git a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx index b9a7bd410be..7025fdacec9 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx @@ -1,10 +1,10 @@ import OneUptimeDate from "Common/Types/Date"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitor; + probeMonitor: ProbeMonitorResponse; } const PingMonitorView: FunctionComponent = ( diff --git a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx index 2effb34f5fe..d499b394e13 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx @@ -1,13 +1,13 @@ import OneUptimeDate from "Common/Types/Date"; -import SslMonitor from "Common/Types/Monitor/SSLMonitor/SslMonitor"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import SslMonitorResponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitor; + probeMonitor: ProbeMonitorResponse; } const SSLCertificateMonitorView: FunctionComponent = ( @@ -19,7 +19,7 @@ const SSLCertificateMonitorView: FunctionComponent = ( ); } - const sslResponse: SslMonitor = + const sslResponse: SslMonitorResponse = props.probeMonitor.sslResponse; const [showMoreDetails, setShowMoreDetails] = React.useState(false); diff --git a/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx index 06c59867f62..1a05849be1e 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/ServerMonitorView.tsx @@ -1,6 +1,6 @@ import OneUptimeDate from "Common/Types/Date"; import { BasicDiskMetrics } from "Common/Types/Infrastructure/BasicMetrics"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; @@ -12,7 +12,7 @@ import MemoryUtil from "Common/Utils/Memory"; import NumberUtil from "Common/Utils/Number"; export interface ComponentProps { - serverMonitor: ServerMonitor; + serverMonitorResponse: ServerMonitorResponse; } const ServerMonitorSummaryView: FunctionComponent = ( @@ -20,9 +20,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( ): ReactElement => { const [showMoreDetails, setShowMoreDetails] = React.useState(false); - const fields: Array> = []; + const fields: Array> = []; - if (props.serverMonitor?.processes) { + if (props.serverMonitorResponse?.processes) { fields.push({ key: "processes", title: "Processes", @@ -38,9 +38,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/2 shadow-none border-2 border-gray-100 " title="CPU % Used" value={ - props.serverMonitor?.basicInfrastructureMetrics?.cpuMetrics?.percentUsed?.toString() + props.serverMonitorResponse?.basicInfrastructureMetrics?.cpuMetrics?.percentUsed?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitor.basicInfrastructureMetrics + props.serverMonitorResponse.basicInfrastructureMetrics .cpuMetrics.percentUsed, ).toString() : "-" @@ -50,7 +50,7 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/2 shadow-none border-2 border-gray-100 " title="CPU Cores" value={ - props.serverMonitor?.basicInfrastructureMetrics?.cpuMetrics?.cores?.toString() || + props.serverMonitorResponse?.basicInfrastructureMetrics?.cpuMetrics?.cores?.toString() || "-" || "-" } @@ -66,9 +66,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Total Memory (GB)" value={ - props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.total?.toString() + props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.total?.toString() ? MemoryUtil.convertToGb( - props.serverMonitor.basicInfrastructureMetrics + props.serverMonitorResponse.basicInfrastructureMetrics .memoryMetrics.total, ).toString() : "-" @@ -78,9 +78,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Memory % Used" value={ - props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.percentUsed?.toString() + props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.percentUsed?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitor.basicInfrastructureMetrics + props.serverMonitorResponse.basicInfrastructureMetrics .memoryMetrics.percentUsed, ).toString() : "-" @@ -90,9 +90,9 @@ const ServerMonitorSummaryView: FunctionComponent = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Memory % Free" value={ - props.serverMonitor?.basicInfrastructureMetrics?.memoryMetrics?.percentFree?.toString() + props.serverMonitorResponse?.basicInfrastructureMetrics?.memoryMetrics?.percentFree?.toString() ? NumberUtil.convertToTwoDecimalPlaces( - props.serverMonitor.basicInfrastructureMetrics + props.serverMonitorResponse.basicInfrastructureMetrics .memoryMetrics.percentFree, ).toString() : "-" @@ -104,7 +104,7 @@ const ServerMonitorSummaryView: FunctionComponent = ( const getDiskMetrics: GetReactElementFunction = (): ReactElement => { const diskMetrics: Array | undefined = - props.serverMonitor?.basicInfrastructureMetrics?.diskMetrics; + props.serverMonitorResponse?.basicInfrastructureMetrics?.diskMetrics; if (!diskMetrics) { return
; @@ -162,45 +162,45 @@ const ServerMonitorSummaryView: FunctionComponent = (
- {props.serverMonitor.failureCause && ( + {props.serverMonitorResponse.failureCause && (
)} {showMoreDetails && fields.length > 0 && (
- {props.serverMonitor?.basicInfrastructureMetrics + {props.serverMonitorResponse?.basicInfrastructureMetrics ?.cpuMetrics && getCpuMetrics()} - {props.serverMonitor?.basicInfrastructureMetrics + {props.serverMonitorResponse?.basicInfrastructureMetrics ?.memoryMetrics && getMemoryMetrics()} - {props.serverMonitor?.basicInfrastructureMetrics + {props.serverMonitorResponse?.basicInfrastructureMetrics ?.diskMetrics && getDiskMetrics()} - + id={"website-monitor-summary-detail"} - item={props.serverMonitor} + item={props.serverMonitorResponse} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx index 515fe4c05b3..43914a1ad97 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx @@ -1,11 +1,11 @@ -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ProbePicker from "./ProbePicker"; import SummaryInfo from "./SummaryInfo"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Card from "CommonUI/src/Components/Card/Card"; import { MonitorStepProbeResponse } from "Model/Models/MonitorProbe"; import Probe from "Model/Models/Probe"; @@ -14,7 +14,7 @@ import React, { FunctionComponent, ReactElement, useEffect } from "react"; export interface ComponentProps { probeMonitors?: Array | undefined; incomingMonitorRequest?: IncomingMonitorRequest | undefined; - serverMonitor?: ServerMonitor | undefined; + serverMonitor?: ServerMonitorResponse | undefined; probes?: Array; monitorType: MonitorType; } @@ -38,13 +38,13 @@ const Summary: FunctionComponent = ( return <>; } - const probeResponses: Array = []; + const probeResponses: Array = []; for (const probeResponse of props.probeMonitors || []) { for (const monitorStepId in probeResponse) { - const probeMonitor: ProbeMonitor = probeResponse[ + const probeMonitor: ProbeMonitorResponse = probeResponse[ monitorStepId - ] as ProbeMonitor; + ] as ProbeMonitorResponse; if ( probeMonitor.probeId?.toString() === selectedProbe?.id?.toString() diff --git a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx index cf267d76ec1..1161879c0a4 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx @@ -1,4 +1,4 @@ -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import IncomingRequestMonitorView from "./IncomingRequestMonitorSummaryView"; import PingMonitorView from "./PingMonitorView"; import SSLCertificateMonitorView from "./SSLCertificateMonitorView"; @@ -9,27 +9,27 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { monitorType: MonitorType; - probeMonitors?: Array | undefined; // this is an array because of multiple monitor steps. + probeMonitors?: Array | undefined; // this is an array because of multiple monitor steps. incomingMonitorRequest?: IncomingMonitorRequest | undefined; - serverMonitor?: ServerMonitor | undefined; + serverMonitorResponse?: ServerMonitorResponse | undefined; } const SummaryInfo: FunctionComponent = ( props: ComponentProps, ): ReactElement => { type GetProbeableMonitorSummarysInfo = ( - probeMonitor: ProbeMonitor, + probeMonitor: ProbeMonitorResponse, key: number, ) => ReactElement; const getProbableMonitorSummarysInfo: GetProbeableMonitorSummarysInfo = ( - probeMonitor: ProbeMonitor, + probeMonitor: ProbeMonitorResponse, key: number, ): ReactElement => { if (!probeMonitor) { @@ -118,7 +118,7 @@ const SummaryInfo: FunctionComponent = (
{props.probeMonitors && props.probeMonitors.map( - (probeMonitor: ProbeMonitor, index: number) => { + (probeMonitor: ProbeMonitorResponse, index: number) => { return getProbableMonitorSummarysInfo(probeMonitor, index); }, )} @@ -133,9 +133,9 @@ const SummaryInfo: FunctionComponent = ( )} {props.monitorType === MonitorType.Server && - props.serverMonitor ? ( + props.serverMonitorResponse ? ( ) : ( <> diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx index 9f06930fbf0..1ec6ffab23a 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx @@ -1,12 +1,12 @@ import CustomCodeMonitorSummaryView from "./CustomMonitorSummaryView"; import SummaryScreenshotGroup from "./ScreenshotGroup"; -import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; +import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import { GetReactElementFunction } from "CommonUI/src/Types/FunctionTypes"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - syntheticMonitor: SyntheticMonitor; + syntheticMonitor: SyntheticMonitorResponse; monitoredAt: Date; } @@ -19,7 +19,7 @@ const SyntheticMonitorItemView: FunctionComponent = ( ); } - const syntheticMonitor: SyntheticMonitor = + const syntheticMonitor: SyntheticMonitorResponse = props.syntheticMonitor; const getMoreDetails: GetReactElementFunction = (): ReactElement => { diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx index 2bd0980e9a3..7c91a921275 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx @@ -1,12 +1,12 @@ import SyntheticMonitorItemView from "./SyntheticMonitorItemView"; -import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import ErrorMessage from "CommonUI/src/Components/ErrorMessage/ErrorMessage"; import HorizontalRule from "CommonUI/src/Components/HorizontalRule/HorizontalRule"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitor; + probeMonitor: ProbeMonitorResponse; } const SyntheticMonitorView: FunctionComponent = ( @@ -21,7 +21,7 @@ const SyntheticMonitorView: FunctionComponent = ( ); } - const syntheticMonitors: Array = + const syntheticMonitors: Array = props.probeMonitor.syntheticMonitor; return ( @@ -29,7 +29,7 @@ const SyntheticMonitorView: FunctionComponent = ( {syntheticMonitors && syntheticMonitors.map( ( - syntheticMonitor: SyntheticMonitor, + syntheticMonitor: SyntheticMonitorResponse, index: number, ) => { return ( diff --git a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx index 1655bc63b08..6ff3e3d02ee 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx @@ -1,5 +1,5 @@ import OneUptimeDate from "Common/Types/Date"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Button, { ButtonStyleType } from "CommonUI/src/Components/Button/Button"; import Detail from "CommonUI/src/Components/Detail/Detail"; import Field from "CommonUI/src/Components/Detail/Field"; diff --git a/Dashboard/src/Pages/Monitor/View/Index.tsx b/Dashboard/src/Pages/Monitor/View/Index.tsx index 68562e1cdbc..294fc64e9d3 100644 --- a/Dashboard/src/Pages/Monitor/View/Index.tsx +++ b/Dashboard/src/Pages/Monitor/View/Index.tsx @@ -21,7 +21,7 @@ import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/Incomin import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import Alert, { AlertType } from "CommonUI/src/Components/Alerts/Alert"; import Card from "CommonUI/src/Components/Card/Card"; diff --git a/Ingestor/API/IncomingRequest.ts b/Ingestor/API/IncomingRequest.ts index 46c8d78ca06..184363c7e5f 100644 --- a/Ingestor/API/IncomingRequest.ts +++ b/Ingestor/API/IncomingRequest.ts @@ -14,7 +14,7 @@ import Express, { NextFunction, RequestHandler, } from "CommonServer/Utils/Express"; -import MonitorService from "CommonServer/Utils/Monitor/Monitor"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Response from "CommonServer/Utils/Response"; import Monitor from "Model/Models/Monitor"; @@ -77,7 +77,7 @@ const processIncomingRequest: RequestHandler = async ( }; // process probe response here. - await MonitorResourceService.monitorResource(incomingRequest); + await MonitorResourceUtil.monitorResource(incomingRequest); return Response.sendEmptySuccessResponse(req, res); } catch (err) { diff --git a/Ingestor/API/Probe.ts b/Ingestor/API/Probe.ts index 319a2889095..ec7e9906b66 100644 --- a/Ingestor/API/Probe.ts +++ b/Ingestor/API/Probe.ts @@ -6,7 +6,7 @@ import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import ProbeStatusReport from "Common/Types/Probe/ProbeStatusReport"; import { DisableAutomaticIncidentCreation } from "CommonServer/EnvironmentConfig"; import GlobalConfigService from "CommonServer/Services/GlobalConfigService"; @@ -20,7 +20,7 @@ import Express, { NextFunction, } from "CommonServer/Utils/Express"; import logger from "CommonServer/Utils/Logger"; -import MonitorService from "CommonServer/Utils/Monitor/Monitor"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Response from "CommonServer/Utils/Response"; import GlobalConfig from "Model/Models/GlobalConfig"; import Probe from "Model/Models/Probe"; @@ -232,7 +232,7 @@ router.post( }); } - const probeResponse: ProbeMonitor = JSONFunctions.deserialize( + const probeResponse: ProbeMonitorResponse = JSONFunctions.deserialize( req.body["probeMonitor"], ) as any; @@ -240,13 +240,13 @@ router.post( return Response.sendErrorResponse( req, res, - new BadDataException("ProbeMonitor not found"), + new BadDataException("ProbeMonitorResponse not found"), ); } // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = - await MonitorResourceService.monitorResource(probeResponse); + await MonitorResourceUtil.monitorResource(probeResponse); return Response.sendJsonObjectResponse(req, res, { probeApiIngestResponse: probeApiIngestResponse, diff --git a/Ingestor/API/ServerMonitor.ts b/Ingestor/API/ServerMonitor.ts index f594ee3f392..843e8b3871d 100644 --- a/Ingestor/API/ServerMonitor.ts +++ b/Ingestor/API/ServerMonitor.ts @@ -2,7 +2,7 @@ import BadDataException from "Common/Types/Exception/BadDataException"; import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import MonitorType from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitor"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; import MonitorService from "CommonServer/Services/MonitorService"; @@ -12,7 +12,7 @@ import Express, { ExpressRouter, NextFunction, } from "CommonServer/Utils/Express"; -import MonitorService from "CommonServer/Utils/Monitor/Monitor"; +import MonitorResourceUtil from "CommonServer/Utils/Monitor/MonitorResource"; import Response from "CommonServer/Utils/Response"; import Monitor from "Model/Models/Monitor"; @@ -92,7 +92,7 @@ router.post( // now process this request. - const serverMonitor: ServerMonitor = + const serverMonitorResponse: ServerMonitorResponse = JSONFunctions.deserialize( req.body["serverMonitor"] as JSONObject, ) as any; @@ -109,7 +109,7 @@ router.post( // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = - await MonitorResourceService.monitorResource( + await MonitorResourceUtil.monitorResource( serverMonitor, ); diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index f7d48d64b13..62663fa975c 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -9,7 +9,7 @@ import URL from "Common/Types/API/URL"; import OneUptimeDate from "Common/Types/Date"; import APIException from "Common/Types/Exception/ApiException"; import { JSONArray } from "Common/Types/JSON"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import Sleep from "Common/Types/Sleep"; import API from "Common/Utils/API"; import logger from "CommonServer/Utils/Logger"; diff --git a/Probe/Utils/Monitors/Monitor.ts b/Probe/Utils/Monitors/Monitor.ts index fa7ab600450..6ee92ababd4 100644 --- a/Probe/Utils/Monitors/Monitor.ts +++ b/Probe/Utils/Monitors/Monitor.ts @@ -23,7 +23,7 @@ import MonitorType from "Common/Types/Monitor/MonitorType"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; import Port from "Common/Types/Port"; -import ProbeMonitor from "Common/Types/Monitor/Monitor"; +import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import ScreenSizeType from "Common/Types/ScreenSizeType"; import API from "Common/Utils/API"; import LocalCache from "CommonServer/Infrastructure/LocalCache"; From 63197d263f1942a4f586729734c3599bb7992530 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 20:33:16 -0600 Subject: [PATCH 6/7] refactor: Update monitor interfaces to use consistent naming --- .../CustomCodeMonitorResponse.ts | 2 +- .../Monitor/SSLMonitor/SslMonitorResponse.ts | 2 +- .../ServerMonitor/ServerMonitorResponse.ts | 2 +- .../SyntheticMonitorResponse.ts | 2 +- Common/Types/Probe/ProbeMonitorResponse.ts | 6 +-- .../1717605043663-InitialMigration.ts | 2 +- .../Criteria/CustomCodeMonitorCriteria.ts | 24 ++++----- .../Monitor/Criteria/SyntheticMonitor.ts | 10 ++-- CommonServer/Utils/Monitor/MonitorResource.ts | 54 +++++++++---------- .../SummaryView/CustomMonitorSummaryView.tsx | 22 ++++---- .../Monitor/SummaryView/PingMonitorView.tsx | 16 +++--- .../SummaryView/SSLCertificateMonitorView.tsx | 8 +-- .../Monitor/SummaryView/Summary.tsx | 16 +++--- .../Monitor/SummaryView/SummaryInfo.tsx | 26 ++++----- .../SummaryView/SyntheticMonitorItemView.tsx | 16 +++--- .../SummaryView/SyntheticMonitorView.tsx | 14 ++--- .../SummaryView/WebsiteMonitorView.tsx | 26 ++++----- Dashboard/src/Pages/Monitor/View/Index.tsx | 14 ++--- InfrastructureAgent/agent.go | 4 +- Ingestor/API/Probe.ts | 2 +- Ingestor/API/ServerMonitor.ts | 8 +-- Probe/Jobs/Monitor/FetchList.ts | 4 +- Probe/Utils/Monitors/Monitor.ts | 40 +++++++------- .../MonitorTypes/CustomCodeMonitor.ts | 4 +- .../Monitors/MonitorTypes/PortMonitor.ts | 4 +- .../Utils/Monitors/MonitorTypes/SslMonitor.ts | 8 +-- .../Monitors/MonitorTypes/SyntheticMonitor.ts | 12 ++--- 27 files changed, 174 insertions(+), 174 deletions(-) diff --git a/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts b/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts index 93084474159..628a30ced4b 100644 --- a/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts +++ b/Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse.ts @@ -1,6 +1,6 @@ import { JSONObject } from "../../JSON"; -export default interface CustomCodeMonitor { +export default interface CustomCodeMonitorResponse { result: string | number | boolean | JSONObject | undefined; scriptError?: string | undefined; logMessages: string[]; diff --git a/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts b/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts index 3a040ef2d15..1174cf06db7 100644 --- a/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts +++ b/Common/Types/Monitor/SSLMonitor/SslMonitorResponse.ts @@ -1,4 +1,4 @@ -export default interface SslMonitor { +export default interface SslMonitorResponse { isSelfSigned?: boolean; createdAt?: Date; expiresAt?: Date; diff --git a/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts b/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts index 69ff5cf2241..a003db403c8 100644 --- a/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts +++ b/Common/Types/Monitor/ServerMonitor/ServerMonitorResponse.ts @@ -7,7 +7,7 @@ export interface ServerProcess { command: string; } -export default interface ServerMonitor { +export default interface ServerMonitorResponse { monitorId: ObjectID; hostname: string; // Hostname of the server basicInfrastructureMetrics?: BasicInfrastructureMetrics | undefined; diff --git a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts index 9a3a037046c..0765a1a95fd 100644 --- a/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts +++ b/Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse.ts @@ -3,7 +3,7 @@ import BrowserType from "./BrowserType"; import ScreenSizeType from "./ScreenSizeType"; import Screenshots from "./Screenshot"; -export default interface SyntheticMonitor +export default interface SyntheticMonitorResponse extends CustomCodeMonitorResponse { screenshots?: Screenshots | undefined; // base 64 encoded screenshots browserType: BrowserType; diff --git a/Common/Types/Probe/ProbeMonitorResponse.ts b/Common/Types/Probe/ProbeMonitorResponse.ts index 00e5eef4085..59e6d441291 100644 --- a/Common/Types/Probe/ProbeMonitorResponse.ts +++ b/Common/Types/Probe/ProbeMonitorResponse.ts @@ -9,7 +9,7 @@ import SyntheticMonitorResponse from "../Monitor/SyntheticMonitors/SyntheticMoni import ObjectID from "../ObjectID"; import Port from "../Port"; -export default interface ProbeMonitor { +export default interface ProbeMonitorResponse { isOnline?: boolean | undefined; monitorDestination?: URL | IP | Hostname | undefined; monitorDestinationPort?: Port | undefined; @@ -22,7 +22,7 @@ export default interface ProbeMonitor { probeId: ObjectID; failureCause: string; sslResponse?: SslMonitorResponse| undefined; - syntheticMonitor?: Array | undefined; - customCodeMonitor?: CustomCodeMonitorResponse | undefined; + syntheticMonitorResponse?: Array | undefined; + customCodeMonitorResponse?: CustomCodeMonitorResponse | undefined; monitoredAt: Date; } diff --git a/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts b/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts index 3a1d7c8bb86..40be89368ff 100644 --- a/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts +++ b/CommonServer/Infrastructure/Postgres/SchemaMigrations/1717605043663-InitialMigration.ts @@ -180,7 +180,7 @@ export default class InitialMigration implements MigrationInterface { `CREATE INDEX "IDX_db1783158a23bd20dbebaae56e" ON "MonitorStatus" ("projectId") `, ); await queryRunner.query( - `CREATE TABLE "Monitor" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "description" character varying(500), "slug" character varying(100) NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "monitorType" character varying(100) NOT NULL, "currentMonitorStatusId" uuid NOT NULL, "monitorSteps" jsonb, "monitoringInterval" character varying(100), "customFields" jsonb, "isOwnerNotifiedOfResourceCreation" boolean NOT NULL DEFAULT false, "disableActiveMonitoring" boolean NOT NULL DEFAULT false, "incomingRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "disableActiveMonitoringBecauseOfScheduledMaintenanceEvent" boolean NOT NULL DEFAULT false, "disableActiveMonitoringBecauseOfManualIncident" boolean NOT NULL DEFAULT false, "serverMonitorRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "serverMonitorSecretKey" uuid, "incomingRequestSecretKey" uuid, "incomingMonitorRequest" jsonb, "serverMonitor" jsonb, CONSTRAINT "UQ_42ecc6e0ac9984cd24d5f9ddd8d" UNIQUE ("slug"), CONSTRAINT "PK_eb992d1e4e316083d3535709e43" PRIMARY KEY ("_id"))`, + `CREATE TABLE "Monitor" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "description" character varying(500), "slug" character varying(100) NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, "monitorType" character varying(100) NOT NULL, "currentMonitorStatusId" uuid NOT NULL, "monitorSteps" jsonb, "monitoringInterval" character varying(100), "customFields" jsonb, "isOwnerNotifiedOfResourceCreation" boolean NOT NULL DEFAULT false, "disableActiveMonitoring" boolean NOT NULL DEFAULT false, "incomingRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "disableActiveMonitoringBecauseOfScheduledMaintenanceEvent" boolean NOT NULL DEFAULT false, "disableActiveMonitoringBecauseOfManualIncident" boolean NOT NULL DEFAULT false, "serverMonitorRequestReceivedAt" TIMESTAMP WITH TIME ZONE, "serverMonitorSecretKey" uuid, "incomingRequestSecretKey" uuid, "incomingMonitorRequest" jsonb, "serverMonitorResponse" jsonb, CONSTRAINT "UQ_42ecc6e0ac9984cd24d5f9ddd8d" UNIQUE ("slug"), CONSTRAINT "PK_eb992d1e4e316083d3535709e43" PRIMARY KEY ("_id"))`, ); await queryRunner.query( `CREATE INDEX "IDX_996acfb590bda327843f78b7ad" ON "Monitor" ("projectId") `, diff --git a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts index 8ca6de3ba1b..fad60b398c1 100644 --- a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts @@ -4,7 +4,7 @@ import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/Cu export default class CustomCodeMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - Monitor: CustomCodeMonitorResponse; + monitorResponse: CustomCodeMonitorResponse; criteriaFilter: CriteriaFilter; }): Promise { // Server Monitoring Checks @@ -12,14 +12,14 @@ export default class CustomCodeMonitoringCriteria { let threshold: number | string | undefined | null = input.criteriaFilter.value; - const syntheticMonitor: CustomCodeMonitorResponse = - input.Monitor; + const syntheticMonitorResponse: CustomCodeMonitorResponse = + input.monitorResponse; if (input.criteriaFilter.checkOn === CheckOn.ExecutionTime) { threshold = CompareCriteria.convertToNumber(threshold); const currentExecutionTime: number = - syntheticMonitor.executionTimeInMS || 0; + syntheticMonitorResponse.executionTimeInMS || 0; return CompareCriteria.compareCriteriaNumbers({ value: currentExecutionTime, @@ -31,7 +31,7 @@ export default class CustomCodeMonitoringCriteria { if (input.criteriaFilter.checkOn === CheckOn.Error) { const emptyNotEmptyResult: string | null = CompareCriteria.compareEmptyAndNotEmpty({ - value: syntheticMonitor.scriptError, + value: syntheticMonitorResponse.scriptError, criteriaFilter: input.criteriaFilter, }); @@ -41,10 +41,10 @@ export default class CustomCodeMonitoringCriteria { if ( threshold && - typeof syntheticMonitor.scriptError === "string" + typeof syntheticMonitorResponse.scriptError === "string" ) { const result: string | null = CompareCriteria.compareCriteriaStrings({ - value: syntheticMonitor.scriptError!, + value: syntheticMonitorResponse.scriptError!, threshold: threshold.toString(), criteriaFilter: input.criteriaFilter, }); @@ -58,7 +58,7 @@ export default class CustomCodeMonitoringCriteria { if (input.criteriaFilter.checkOn === CheckOn.ResultValue) { const emptyNotEmptyResult: string | null = CompareCriteria.compareEmptyAndNotEmpty({ - value: syntheticMonitor.result, + value: syntheticMonitorResponse.result, criteriaFilter: input.criteriaFilter, }); @@ -78,10 +78,10 @@ export default class CustomCodeMonitoringCriteria { if ( thresholdAsNumber !== null && - typeof syntheticMonitor.result === "number" + typeof syntheticMonitorResponse.result === "number" ) { const result: string | null = CompareCriteria.compareCriteriaNumbers({ - value: syntheticMonitor.result, + value: syntheticMonitorResponse.result, threshold: thresholdAsNumber as number, criteriaFilter: input.criteriaFilter, }); @@ -91,9 +91,9 @@ export default class CustomCodeMonitoringCriteria { } } - if (threshold && typeof syntheticMonitor.result === "string") { + if (threshold && typeof syntheticMonitorResponse.result === "string") { const result: string | null = CompareCriteria.compareCriteriaStrings({ - value: syntheticMonitor.result, + value: syntheticMonitorResponse.result, threshold: threshold.toString(), criteriaFilter: input.criteriaFilter, }); diff --git a/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts index 120964ca088..e1621f86e9a 100644 --- a/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts +++ b/CommonServer/Utils/Monitor/Criteria/SyntheticMonitor.ts @@ -5,17 +5,17 @@ import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/Syn export default class SyntheticMonitoringCriteria { public static async isMonitorInstanceCriteriaFilterMet(input: { - Monitor: Array; + monitorResponse: Array; criteriaFilter: CriteriaFilter; }): Promise { - for (const syntheticMonitor of input.Monitor) { + for (const syntheticMonitorResponse of input.monitorResponse) { const threshold: number | string | undefined | null = input.criteriaFilter.value; // check custom code monitoring criteria first const result: string | null = await CustomCodeMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - Monitor: syntheticMonitor, + monitorResponse: syntheticMonitorResponse, criteriaFilter: input.criteriaFilter, }); @@ -27,7 +27,7 @@ export default class SyntheticMonitoringCriteria { if (CheckOn.ScreenSizeType === input.criteriaFilter.checkOn) { return CompareCriteria.checkEqualToOrNotEqualTo({ - value: syntheticMonitor.screenSizeType, + value: syntheticMonitorResponse.screenSizeType, threshold: threshold as number, criteriaFilter: input.criteriaFilter, }); @@ -35,7 +35,7 @@ export default class SyntheticMonitoringCriteria { if (CheckOn.BrowserType === input.criteriaFilter.checkOn) { return CompareCriteria.checkEqualToOrNotEqualTo({ - value: syntheticMonitor.browserType, + value: syntheticMonitorResponse.browserType, threshold: threshold as number, criteriaFilter: input.criteriaFilter, }); diff --git a/CommonServer/Utils/Monitor/MonitorResource.ts b/CommonServer/Utils/Monitor/MonitorResource.ts index 8e75d0ddf86..e869a055518 100644 --- a/CommonServer/Utils/Monitor/MonitorResource.ts +++ b/CommonServer/Utils/Monitor/MonitorResource.ts @@ -26,7 +26,7 @@ import { CriteriaFilter, FilterCondition, } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; import IncomingMonitorRequest from "Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest"; import MonitorCriteria from "Common/Types/Monitor/MonitorCriteria"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; @@ -35,7 +35,7 @@ import MonitorSteps from "Common/Types/Monitor/MonitorSteps"; import MonitorType, { MonitorTypeHelper, } from "Common/Types/Monitor/MonitorType"; -import ServerMonitor from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; +import ServerMonitorResponse from "Common/Types/Monitor/ServerMonitor/ServerMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import ProbeApiIngestResponse from "Common/Types/Probe/ProbeApiIngestResponse"; import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; @@ -50,7 +50,7 @@ import MonitorStatusTimeline from "Model/Models/MonitorStatusTimeline"; import OnCallDutyPolicy from "Model/Models/OnCallDutyPolicy"; import OneUptimeDate from "Common/Types/Date"; -export default class MonitorResourceService { +export default class MonitorResourceUtil { public static async monitorResource( dataToProcess: DataToProcess, ): Promise { @@ -196,15 +196,15 @@ export default class MonitorResourceService { if ( monitor.monitorType === MonitorType.Server && - (dataToProcess as ServerMonitor).requestReceivedAt + (dataToProcess as ServerMonitorResponse).requestReceivedAt ) { await MonitorService.updateOneById({ id: monitor.id!, data: { serverMonitorRequestReceivedAt: ( - dataToProcess as ServerMonitor + dataToProcess as ServerMonitorResponse ).requestReceivedAt!, - serverMonitorResponse: dataToProcess as ServerMonitor, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. + serverMonitorResponse: dataToProcess as ServerMonitorResponse, // this could be redundant as we are already saving this in the incomingMonitorRequest. we should remove this in the future. }, props: { isRoot: true, @@ -313,7 +313,7 @@ export default class MonitorResourceService { // now process probe response monitors - response = await MonitorResourceService.processMonitorStep({ + response = await MonitorResourceUtil.processMonitorStep({ dataToProcess: dataToProcess, monitorStep: monitorStep, monitor: monitor, @@ -400,16 +400,16 @@ export default class MonitorResourceService { const itemsToSave: Array = []; if ( - (data.dataToProcess as ServerMonitor).basicInfrastructureMetrics + (data.dataToProcess as ServerMonitorResponse).basicInfrastructureMetrics ) { // store cpu, memory, disk metrics. - if ((data.dataToProcess as ServerMonitor).requestReceivedAt) { + if ((data.dataToProcess as ServerMonitorResponse).requestReceivedAt) { let isOnline: boolean = true; const differenceInMinutes: number = OneUptimeDate.getDifferenceInMinutes( - (data.dataToProcess as ServerMonitor).requestReceivedAt, + (data.dataToProcess as ServerMonitorResponse).requestReceivedAt, OneUptimeDate.getCurrentDate(), ); @@ -429,7 +429,7 @@ export default class MonitorResourceService { } const basicMetrics: BasicInfrastructureMetrics | undefined = ( - data.dataToProcess as ServerMonitor + data.dataToProcess as ServerMonitorResponse ).basicInfrastructureMetrics; if (!basicMetrics) { @@ -533,10 +533,10 @@ export default class MonitorResourceService { itemsToSave.push(monitorMetricsByMinute); } - if ((data.dataToProcess as ProbeMonitorResponse).syntheticMonitor) { + if ((data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse) { for (const syntheticMonitor of ( data.dataToProcess as ProbeMonitorResponse - ).syntheticMonitor || []) { + ).syntheticMonitorResponse || []) { const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); monitorMetricsByMinute.monitorId = data.monitorId; @@ -557,11 +557,11 @@ export default class MonitorResourceService { } if ( - (data.dataToProcess as ProbeMonitorResponse).customCodeMonitor + (data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse ) { - const customCodeMonitor: CustomCodeMonitor = ( + const customCodeMonitor: CustomCodeMonitorResponse = ( data.dataToProcess as ProbeMonitorResponse - ).customCodeMonitor!; + ).customCodeMonitorResponse!; const monitorMetricsByMinute: MonitorMetricsByMinute = new MonitorMetricsByMinute(); @@ -620,7 +620,7 @@ export default class MonitorResourceService { // check if should close the incident. for (const openIncident of openIncidents) { - const shouldClose: boolean = MonitorResourceService.shouldCloseIncident({ + const shouldClose: boolean = MonitorResourceUtil.shouldCloseIncident({ openIncident, autoResolveCriteriaInstanceIdIncidentIdsDictionary: input.autoResolveCriteriaInstanceIdIncidentIdsDictionary, @@ -629,7 +629,7 @@ export default class MonitorResourceService { if (shouldClose) { // then resolve incident. - await MonitorResourceService.resolveOpenIncident({ + await MonitorResourceUtil.resolveOpenIncident({ openIncident: openIncident, rootCause: input.rootCause, dataToProcess: input.dataToProcess, @@ -911,7 +911,7 @@ export default class MonitorResourceService { for (const criteriaInstance of criteria.data.monitorCriteriaInstanceArray) { const rootCause: string | null = - await MonitorResourceService.processMonitorCriteiaInstance({ + await MonitorResourceUtil.processMonitorCriteiaInstance({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -956,7 +956,7 @@ export default class MonitorResourceService { // process monitor criteria instance here. const rootCause: string | null = - await MonitorResourceService.isMonitorInstanceCriteriaFiltersMet({ + await MonitorResourceUtil.isMonitorInstanceCriteriaFiltersMet({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -984,7 +984,7 @@ export default class MonitorResourceService { for (const criteriaFilter of input.criteriaInstance.data?.filters || []) { const rootCause: string | null = - await MonitorResourceService.isMonitorInstanceCriteriaFilterMet({ + await MonitorResourceUtil.isMonitorInstanceCriteriaFilterMet({ dataToProcess: input.dataToProcess, monitorStep: input.monitorStep, monitor: input.monitor, @@ -1129,12 +1129,12 @@ export default class MonitorResourceService { if ( input.monitor.monitorType === MonitorType.CustomJavaScriptCode && - (input.dataToProcess as ProbeMonitorResponse).customCodeMonitor + (input.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse ) { const criteriaResult: string | null = await CustomCodeMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - Monitor: (input.dataToProcess as ProbeMonitorResponse) - .customCodeMonitor!, + monitorResponse: (input.dataToProcess as ProbeMonitorResponse) + .customCodeMonitorResponse!, criteriaFilter: input.criteriaFilter, }); @@ -1145,13 +1145,13 @@ export default class MonitorResourceService { if ( input.monitor.monitorType === MonitorType.SyntheticMonitor && - (input.dataToProcess as ProbeMonitorResponse).syntheticMonitor + (input.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse ) { const criteriaResult: string | null = await SyntheticMonitoringCriteria.isMonitorInstanceCriteriaFilterMet({ - Monitor: + monitorResponse: (input.dataToProcess as ProbeMonitorResponse) - .syntheticMonitor || [], + .syntheticMonitorResponse || [], criteriaFilter: input.criteriaFilter, }); diff --git a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx index c481f6c67fb..38cb4ff8da8 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx @@ -9,7 +9,7 @@ import FieldType from "CommonUI/src/Components/Types/FieldType"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - customCodeMonitor: CustomCodeMonitorResponse; + customCodeMonitorResponse: CustomCodeMonitorResponse; moreDetailElement?: ReactElement; monitoredAt: Date; } @@ -17,7 +17,7 @@ export interface ComponentProps { const CustomCodeMonitorSummaryView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.customCodeMonitor) { + if (!props.customCodeMonitorResponse) { return ( ); @@ -25,10 +25,10 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( const [showMoreDetails, setShowMoreDetails] = React.useState(false); - const customMonitor: CustomCodeMonitorResponse = - props.customCodeMonitor; + const customCodeMonitorResponse: CustomCodeMonitorResponse = + props.customCodeMonitorResponse; - let executionTimeInMS: number = customMonitor.executionTimeInMS || 0; + let executionTimeInMS: number = customCodeMonitorResponse.executionTimeInMS || 0; if (executionTimeInMS > 0) { executionTimeInMS = Math.round(executionTimeInMS); @@ -37,8 +37,8 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( const fields: Array> = []; if ( - customMonitor.logMessages && - customMonitor.logMessages.length > 0 + customCodeMonitorResponse.logMessages && + customCodeMonitorResponse.logMessages.length > 0 ) { fields.push({ key: "logMessages", @@ -48,7 +48,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( }); } - if (customMonitor.result) { + if (customCodeMonitorResponse.result) { fields.push({ key: "result", title: "Result", @@ -57,7 +57,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( }); } - if (customMonitor.scriptError) { + if (customCodeMonitorResponse.scriptError) { fields.push({ key: "scriptError", title: "Script Error", @@ -79,7 +79,7 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( = (
id={"custom-code-monitor-summary-detail"} - item={customMonitor} + item={customCodeMonitorResponse} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx index 7025fdacec9..fbaf267553b 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/PingMonitorView.tsx @@ -4,14 +4,14 @@ import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitorResponse; + probeMonitorResponse: ProbeMonitorResponse; } const PingMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { let responseTimeInMs: number = - props.probeMonitor?.responseTimeInMs || 0; + props.probeMonitorResponse?.responseTimeInMs || 0; if (responseTimeInMs > 0) { responseTimeInMs = Math.round(responseTimeInMs); @@ -24,9 +24,9 @@ const PingMonitorView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="Hostname or IP address" value={ - (props.probeMonitor.monitorDestination?.toString() || "") + - (props.probeMonitor.monitorDestinationPort?.toString() - ? `:${props.probeMonitor.monitorDestinationPort.toString()}` + (props.probeMonitorResponse.monitorDestination?.toString() || "") + + (props.probeMonitorResponse.monitorDestinationPort?.toString() + ? `:${props.probeMonitorResponse.monitorDestinationPort.toString()}` : "") || "-" } /> @@ -35,7 +35,7 @@ const PingMonitorView: FunctionComponent = ( = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Monitored At" value={ - props.probeMonitor?.monitoredAt + props.probeMonitorResponse?.monitoredAt ? OneUptimeDate.getDateAsLocalFormattedString( - props.probeMonitor.monitoredAt, + props.probeMonitorResponse.monitoredAt, ) : "-" } diff --git a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx index d499b394e13..1664c9a00bd 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SSLCertificateMonitorView.tsx @@ -7,20 +7,20 @@ import InfoCard from "CommonUI/src/Components/InfoCard/InfoCard"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitorResponse; + probeMonitorResponse: ProbeMonitorResponse; } const SSLCertificateMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.probeMonitor || !props.probeMonitor.sslResponse) { + if (!props.probeMonitorResponse || !props.probeMonitorResponse.sslResponse) { return ( ); } const sslResponse: SslMonitorResponse = - props.probeMonitor.sslResponse; + props.probeMonitorResponse.sslResponse; const [showMoreDetails, setShowMoreDetails] = React.useState(false); @@ -32,7 +32,7 @@ const SSLCertificateMonitorView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="URL" value={ - props.probeMonitor.monitorDestination?.toString() || "-" + props.probeMonitorResponse.monitorDestination?.toString() || "-" } />
diff --git a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx index 43914a1ad97..762a355c9e9 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/Summary.tsx @@ -12,9 +12,9 @@ import Probe from "Model/Models/Probe"; import React, { FunctionComponent, ReactElement, useEffect } from "react"; export interface ComponentProps { - probeMonitors?: Array | undefined; + probeMonitorResponses?: Array | undefined; incomingMonitorRequest?: IncomingMonitorRequest | undefined; - serverMonitor?: ServerMonitorResponse | undefined; + serverMonitorResponse?: ServerMonitorResponse | undefined; probes?: Array; monitorType: MonitorType; } @@ -40,16 +40,16 @@ const Summary: FunctionComponent = ( const probeResponses: Array = []; - for (const probeResponse of props.probeMonitors || []) { + for (const probeResponse of props.probeMonitorResponses || []) { for (const monitorStepId in probeResponse) { - const probeMonitor: ProbeMonitorResponse = probeResponse[ + const probeMonitorResponse: ProbeMonitorResponse = probeResponse[ monitorStepId ] as ProbeMonitorResponse; if ( - probeMonitor.probeId?.toString() === + probeMonitorResponse.probeId?.toString() === selectedProbe?.id?.toString() ) { - probeResponses.push(probeMonitor); + probeResponses.push(probeMonitorResponse); } } } @@ -78,9 +78,9 @@ const Summary: FunctionComponent = (
diff --git a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx index 1161879c0a4..090e170c2f0 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx @@ -15,7 +15,7 @@ import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { monitorType: MonitorType; - probeMonitors?: Array | undefined; // this is an array because of multiple monitor steps. + probeMonitorResponses?: Array | undefined; // this is an array because of multiple monitor steps. incomingMonitorRequest?: IncomingMonitorRequest | undefined; serverMonitorResponse?: ServerMonitorResponse | undefined; } @@ -24,15 +24,15 @@ const SummaryInfo: FunctionComponent = ( props: ComponentProps, ): ReactElement => { type GetProbeableMonitorSummarysInfo = ( - probeMonitor: ProbeMonitorResponse, + probeMonitorResponse: ProbeMonitorResponse, key: number, ) => ReactElement; const getProbableMonitorSummarysInfo: GetProbeableMonitorSummarysInfo = ( - probeMonitor: ProbeMonitorResponse, + probeMonitorResponse: ProbeMonitorResponse, key: number, ): ReactElement => { - if (!probeMonitor) { + if (!probeMonitorResponse) { return ( = ( return ( ); } @@ -62,7 +62,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -71,7 +71,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -80,7 +80,7 @@ const SummaryInfo: FunctionComponent = ( return ( ); } @@ -90,7 +90,7 @@ const SummaryInfo: FunctionComponent = ( if ( MonitorTypeHelper.isProbableMonitor(props.monitorType) && - (!props.probeMonitors || props.probeMonitors.length === 0) + (!props.probeMonitorResponses || props.probeMonitorResponses.length === 0) ) { return ( = ( return (
- {props.probeMonitors && - props.probeMonitors.map( - (probeMonitor: ProbeMonitorResponse, index: number) => { - return getProbableMonitorSummarysInfo(probeMonitor, index); + {props.probeMonitorResponses && + props.probeMonitorResponses.map( + (probeMonitorResponses: ProbeMonitorResponse, index: number) => { + return getProbableMonitorSummarysInfo(probeMonitorResponses, index); }, )} diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx index 1ec6ffab23a..d4920be8697 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorItemView.tsx @@ -6,27 +6,27 @@ import { GetReactElementFunction } from "CommonUI/src/Types/FunctionTypes"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - syntheticMonitor: SyntheticMonitorResponse; + syntheticMonitorResponse: SyntheticMonitorResponse; monitoredAt: Date; } const SyntheticMonitorItemView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { - if (!props.syntheticMonitor) { + if (!props.syntheticMonitorResponse) { return ( ); } - const syntheticMonitor: SyntheticMonitorResponse = - props.syntheticMonitor; + const syntheticMonitorResponse: SyntheticMonitorResponse = + props.syntheticMonitorResponse; const getMoreDetails: GetReactElementFunction = (): ReactElement => { return (
); @@ -35,11 +35,11 @@ const SyntheticMonitorItemView: FunctionComponent = ( return (
- {props.syntheticMonitor.browserType} -{" "} - {props.syntheticMonitor.screenSizeType} + {props.syntheticMonitorResponse.browserType} -{" "} + {props.syntheticMonitorResponse.screenSizeType}
diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx index 7c91a921275..326db919b30 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx @@ -6,15 +6,15 @@ import HorizontalRule from "CommonUI/src/Components/HorizontalRule/HorizontalRul import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitorResponse; + probeMonitorResponse: ProbeMonitorResponse; } const SyntheticMonitorView: FunctionComponent = ( props: ComponentProps, ): ReactElement => { if ( - !props.probeMonitor || - !props.probeMonitor.syntheticMonitor + !props.probeMonitorResponse || + !props.probeMonitorResponse.syntheticMonitorResponse ) { return ( @@ -22,22 +22,22 @@ const SyntheticMonitorView: FunctionComponent = ( } const syntheticMonitors: Array = - props.probeMonitor.syntheticMonitor; + props.probeMonitorResponse.syntheticMonitorResponse; return (
{syntheticMonitors && syntheticMonitors.map( ( - syntheticMonitor: SyntheticMonitorResponse, + syntheticMonitorResponse: SyntheticMonitorResponse, index: number, ) => { return (
{index !== syntheticMonitors.length - 1 && ( diff --git a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx index 6ff3e3d02ee..c67d8cb6520 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/WebsiteMonitorView.tsx @@ -8,7 +8,7 @@ import FieldType from "CommonUI/src/Components/Types/FieldType"; import React, { FunctionComponent, ReactElement } from "react"; export interface ComponentProps { - probeMonitor: ProbeMonitor; + probeMonitorResponse: ProbeMonitorResponse; } const WebsiteMonitorSummaryView: FunctionComponent = ( @@ -17,15 +17,15 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( const [showMoreDetails, setShowMoreDetails] = React.useState(false); let responseTimeInMs: number = - props.probeMonitor?.responseTimeInMs || 0; + props.probeMonitorResponse?.responseTimeInMs || 0; if (responseTimeInMs > 0) { responseTimeInMs = Math.round(responseTimeInMs); } - const fields: Array> = []; + const fields: Array> = []; - if (props.probeMonitor?.responseHeaders) { + if (props.probeMonitorResponse?.responseHeaders) { fields.push({ key: "responseHeaders", title: "Response Headers", @@ -34,7 +34,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( }); } - if (props.probeMonitor?.responseBody) { + if (props.probeMonitorResponse?.responseBody) { fields.push({ key: "responseBody", title: "Response Body", @@ -50,7 +50,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( className="w-full shadow-none border-2 border-gray-100 " title="URL" value={ - props.probeMonitor.monitorDestination?.toString() || "-" + props.probeMonitorResponse.monitorDestination?.toString() || "-" } />
@@ -58,7 +58,7 @@ const WebsiteMonitorSummaryView: FunctionComponent = ( = ( className="w-1/3 shadow-none border-2 border-gray-100 " title="Monitored At" value={ - props.probeMonitor?.monitoredAt + props.probeMonitorResponse?.monitoredAt ? OneUptimeDate.getDateAsLocalFormattedString( - props.probeMonitor.monitoredAt, + props.probeMonitorResponse.monitoredAt, ) : "-" } />
- {props.probeMonitor.failureCause && ( + {props.probeMonitorResponse.failureCause && (
)} {showMoreDetails && fields.length > 0 && (
- + id={"website-monitor-summary-detail"} - item={props.probeMonitor} + item={props.probeMonitorResponse} fields={fields} showDetailsInNumberOfColumns={1} /> diff --git a/Dashboard/src/Pages/Monitor/View/Index.tsx b/Dashboard/src/Pages/Monitor/View/Index.tsx index 294fc64e9d3..c487bed882c 100644 --- a/Dashboard/src/Pages/Monitor/View/Index.tsx +++ b/Dashboard/src/Pages/Monitor/View/Index.tsx @@ -104,8 +104,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { IncomingMonitorRequest | undefined >(undefined); - const [serverMonitor, setServerMonitor] = useState< - ServerMonitor | undefined + const [serverMonitorResponse, setServerMonitorResponse] = useState< + ServerMonitorResponse | undefined >(undefined); const getUptimePercent: () => ReactElement = (): ReactElement => { @@ -181,7 +181,7 @@ const MonitorView: FunctionComponent = (): ReactElement => { serverMonitorRequestReceivedAt: true, incomingRequestReceivedAt: true, incomingMonitorRequest: true, - serverMonitor: true, + serverMonitorResponse: true, isNoProbeEnabledOnThisMonitor: true, isAllProbesDisconnectedFromThisMonitor: true, }, @@ -193,8 +193,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { setIncomingMonitorRequest(item.incomingMonitorRequest); } - if (item?.serverMonitor) { - setServerMonitor(item.serverMonitor); + if (item?.serverMonitorResponse) { + setServerMonitorResponse(item.serverMonitorResponse); } const monitorStatuses: ListResult = await ModelAPI.getList( @@ -604,8 +604,8 @@ const MonitorView: FunctionComponent = (): ReactElement => { monitorType={monitorType!} probes={probes} incomingMonitorRequest={incomingMonitorRequest} - probeMonitors={probeResponses} - serverMonitor={serverMonitor} + probeMonitorResponses={probeResponses} + serverMonitorResponse={serverMonitorResponse} /> {shouldFetchMonitorMetrics && getMonitorMetricsChartGroup()} diff --git a/InfrastructureAgent/agent.go b/InfrastructureAgent/agent.go index 86f462b2ec5..1bf6a56641e 100644 --- a/InfrastructureAgent/agent.go +++ b/InfrastructureAgent/agent.go @@ -114,9 +114,9 @@ func collectMetricsJob(secretKey string, oneuptimeURL string) { } reqData := struct { - ServerMonitor *model.ServerMonitorReport `json:"serverMonitor"` + ServerMonitorResponse *model.ServerMonitorReport `json:"serverMonitorResponse"` }{ - ServerMonitor: metricsReport, + ServerMonitorResponse: metricsReport, } postBuilder := greq.New(oneuptimeURL).Post("/server-monitor/response/ingest/" + secretKey). JSONType().JSONBody(reqData) diff --git a/Ingestor/API/Probe.ts b/Ingestor/API/Probe.ts index ec7e9906b66..d283b47150a 100644 --- a/Ingestor/API/Probe.ts +++ b/Ingestor/API/Probe.ts @@ -233,7 +233,7 @@ router.post( } const probeResponse: ProbeMonitorResponse = JSONFunctions.deserialize( - req.body["probeMonitor"], + req.body["probeMonitorResponse"], ) as any; if (!probeResponse) { diff --git a/Ingestor/API/ServerMonitor.ts b/Ingestor/API/ServerMonitor.ts index 843e8b3871d..c3ec4705dea 100644 --- a/Ingestor/API/ServerMonitor.ts +++ b/Ingestor/API/ServerMonitor.ts @@ -94,10 +94,10 @@ router.post( const serverMonitorResponse: ServerMonitorResponse = JSONFunctions.deserialize( - req.body["serverMonitor"] as JSONObject, + req.body["serverMonitorResponse"] as JSONObject, ) as any; - if (!serverMonitor) { + if (!serverMonitorResponse) { throw new BadDataException("Invalid Server Monitor Response"); } @@ -105,12 +105,12 @@ router.post( throw new BadDataException("Monitor id not found"); } - serverMonitor.monitorId = monitor.id; + serverMonitorResponse.monitorId = monitor.id; // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = await MonitorResourceUtil.monitorResource( - serverMonitor, + serverMonitorResponse, ); return Response.sendJsonObjectResponse(req, res, { diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index 62663fa975c..3bddfb4ff66 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -84,7 +84,7 @@ export default class FetchListAndProbe { ); const probeMonitorPromises: Array< - Promise> + Promise> > = []; // Array of promises to probe monitors for (const monitor of monitors) { @@ -93,7 +93,7 @@ export default class FetchListAndProbe { // all settled // eslint-disable-next-line no-undef - const results: PromiseSettledResult<(ProbeMonitor | null)[]>[] = + const results: PromiseSettledResult<(ProbeMonitorResponse | null)[]>[] = await Promise.allSettled(probeMonitorPromises); let resultIndex: number = 0; diff --git a/Probe/Utils/Monitors/Monitor.ts b/Probe/Utils/Monitors/Monitor.ts index 6ee92ababd4..f5a249f1ab1 100644 --- a/Probe/Utils/Monitors/Monitor.ts +++ b/Probe/Utils/Monitors/Monitor.ts @@ -2,11 +2,11 @@ import { INGESTOR_URL } from "../../Config"; import ProbeUtil from "../Probe"; import ProbeAPIRequest from "../ProbeAPIRequest"; import ApiMonitor, { APIResponse } from "./MonitorTypes/ApiMonitor"; -import CustomCodeMonitor from "./MonitorTypes/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "./MonitorTypes/CustomCodeMonitorResponse"; import PingMonitor, { PingResponse } from "./MonitorTypes/PingMonitor"; -import PortMonitor, { PortMonitor } from "./MonitorTypes/PortMonitor"; +import PortMonitorResponse, { PortMonitorResponse } from "./MonitorTypes/PortMonitorResponse"; import SSLMonitor, { SslResponse } from "./MonitorTypes/SslMonitor"; -import SyntheticMonitor from "./MonitorTypes/SyntheticMonitor"; +import SyntheticMonitorResponse from "./MonitorTypes/SyntheticMonitorResponse"; import WebsiteMonitor, { ProbeWebsiteResponse, } from "./MonitorTypes/WebsiteMonitor"; @@ -16,12 +16,12 @@ import OneUptimeDate from "Common/Types/Date"; import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitorResponse/CustomCodeMonitorResponse"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; import MonitorStep from "Common/Types/Monitor/MonitorStep"; import MonitorType from "Common/Types/Monitor/MonitorType"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; -import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; +import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; import Port from "Common/Types/Port"; import ProbeMonitorResponse from "Common/Types/Probe/ProbeMonitorResponse"; import ScreenSizeType from "Common/Types/ScreenSizeType"; @@ -31,10 +31,10 @@ import logger from "CommonServer/Utils/Logger"; import Monitor from "Model/Models/Monitor"; export default class MonitorUtil { - public static async probeMonitor( + public static async probeMonitorResponse( monitor: Monitor, - ): Promise> { - const results: Array = []; + ): Promise> { + const results: Array = []; if ( !monitor.monitorSteps || @@ -50,7 +50,7 @@ export default class MonitorUtil { continue; } - const result: ProbeMonitor | null = await this.probeMonitorStep( + const result: ProbeMonitorResponse | null = await this.probeMonitorStep( monitorStep, monitor, ); @@ -65,7 +65,7 @@ export default class MonitorUtil { ), { ...ProbeAPIRequest.getDefaultRequestBody(), - probeMonitor: result as any, + probeMonitorResponse: result as any, }, {}, {}, @@ -119,8 +119,8 @@ export default class MonitorUtil { public static async probeMonitorStep( monitorStep: MonitorStep, monitor: Monitor, - ): Promise { - const result: ProbeMonitor = { + ): Promise { + const result: ProbeMonitorResponse = { monitorStepId: monitorStep.id, monitorId: monitor.id!, probeId: ProbeUtil.getProbeId(), @@ -145,7 +145,7 @@ export default class MonitorUtil { if (LocalCache.getString("PROBE", "PING_MONITORING") === "PORT") { // probe is online but ping monitoring is blocked by the cloud provider. Fallback to port monitoring. - const response: PortMonitor | null = await PortMonitor.ping( + const response: PortMonitorResponse | null = await PortMonitorResponse.ping( monitorStep.data?.monitorDestination, new Port(80), // use port 80 by default. { @@ -197,7 +197,7 @@ export default class MonitorUtil { result.monitorDestinationPort = monitorStep.data.monitorDestinationPort; - const response: PortMonitor | null = await PortMonitor.ping( + const response: PortMonitorResponse | null = await PortMonitorResponse.ping( monitorStep.data?.monitorDestination, monitorStep.data.monitorDestinationPort, { @@ -222,8 +222,8 @@ export default class MonitorUtil { return result; } - const response: Array | null = - await SyntheticMonitor.execute({ + const response: Array | null = + await SyntheticMonitorResponse.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, screenSizeTypes: monitorStep.data @@ -235,7 +235,7 @@ export default class MonitorUtil { return null; } - result.syntheticMonitor = response; + result.syntheticMonitorResponse = response; } if (monitor.monitorType === MonitorType.CustomJavaScriptCode) { @@ -245,8 +245,8 @@ export default class MonitorUtil { return result; } - const response: CustomCodeMonitor | null = - await CustomCodeMonitor.execute({ + const response: CustomCodeMonitorResponse | null = + await CustomCodeMonitorResponse.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, }); @@ -255,7 +255,7 @@ export default class MonitorUtil { return null; } - result.customCodeMonitor = response; + result.customCodeMonitorResponse = response; } if (monitor.monitorType === MonitorType.SSLCertificate) { diff --git a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts index f5a62b5d852..4161732f1e7 100644 --- a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts @@ -1,6 +1,6 @@ import { PROBE_CUSTOM_CODE_MONITOR_SCRIPT_TIMEOUT_IN_MS } from "../../../Config"; import ReturnResult from "Common/Types/IsolatedVM/ReturnResult"; -import CustomCodeMonitor from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitor"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import logger from "CommonServer/Utils/Logger"; import VMRunner from "CommonServer/Utils/VM/VMRunner"; @@ -21,7 +21,7 @@ export default class CustomCodeMonitor { }; } - const scriptResult: CustomCodeMonitor = { + const scriptResult: CustomCodeMonitorResponse = { logMessages: [], scriptError: undefined, result: undefined, diff --git a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts index 8f145f7faa6..5cbb17a76c9 100644 --- a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts @@ -14,7 +14,7 @@ import logger from "CommonServer/Utils/Logger"; import net from "net"; // TODO - make sure it work for the IPV6 -export interface PortMonitor { +export interface PortMonitorResponse { isOnline: boolean; responseTimeInMS?: PositiveNumber | undefined; failureCause: string; @@ -33,7 +33,7 @@ export default class PortMonitor { host: Hostname | IPv4 | IPv6 | URL, port: Port, pingOptions?: PingOptions, - ): Promise { + ): Promise { if (!pingOptions) { pingOptions = {}; } diff --git a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts index e3263ea5af1..18b1913c7de 100644 --- a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts @@ -2,7 +2,7 @@ import OnlineCheck from "../../OnlineCheck"; import URL from "Common/Types/API/URL"; import OneUptimeDate from "Common/Types/Date"; import BadDataException from "Common/Types/Exception/BadDataException"; -import SSLMonitorReponse from "Common/Types/Monitor/SSLMonitor/SslMonitor"; +import SslMonitorResponse from "Common/Types/Monitor/SSLMonitor/SslMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import PositiveNumber from "Common/Types/PositiveNumber"; import Sleep from "Common/Types/Sleep"; @@ -13,7 +13,7 @@ import { ClientRequest, IncomingMessage } from "http"; import https, { RequestOptions } from "https"; import tls, { TLSSocket } from "tls"; -export interface SslResponse extends SSLMonitorReponse { +export interface SslResponse extends SslMonitorResponse { isOnline: boolean; failureCause: string; } @@ -48,7 +48,7 @@ export default class SSLMonitor { ); try { - const res: SslResponse = await this.getSslMonitor( + const res: SslResponse = await this.getSslMonitorResponse( url.hostname.hostname, url.hostname.port?.toNumber() || 443, ); @@ -111,7 +111,7 @@ export default class SSLMonitor { } } - public static async getSslMonitor( + public static async getSslMonitorResponse( host: string, port = 443, ): Promise { diff --git a/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts index 6a3a1e6c9bd..00728c321f2 100644 --- a/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/SyntheticMonitor.ts @@ -3,7 +3,7 @@ import BadDataException from "Common/Types/Exception/BadDataException"; import ReturnResult from "Common/Types/IsolatedVM/ReturnResult"; import BrowserType from "Common/Types/Monitor/SyntheticMonitors/BrowserType"; import ScreenSizeType from "Common/Types/Monitor/SyntheticMonitors/ScreenSizeType"; -import SyntheticMonitor from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitor"; +import SyntheticMonitorResponse from "Common/Types/Monitor/SyntheticMonitors/SyntheticMonitorResponse"; import ObjectID from "Common/Types/ObjectID"; import logger from "CommonServer/Utils/Logger"; import VMRunner from "CommonServer/Utils/VM/VMRunner"; @@ -20,8 +20,8 @@ export interface SyntheticMonitorOptions { export default class SyntheticMonitor { public static async execute( options: SyntheticMonitorOptions, - ): Promise | null> { - const results: Array = []; + ): Promise | null> { + const results: Array = []; for (const browserType of options.browserTypes || []) { for (const screenSizeType of options.screenSizeTypes || []) { @@ -29,7 +29,7 @@ export default class SyntheticMonitor { `Running Synthetic Monitor: ${options?.monitorId?.toString()}, Screen Size: ${screenSizeType}, Browser: ${browserType}`, ); - const result: SyntheticMonitor | null = + const result: SyntheticMonitorResponse | null = await this.executeByBrowserAndScreenSize({ script: options.script, browserType: browserType, @@ -51,7 +51,7 @@ export default class SyntheticMonitor { script: string; browserType: BrowserType; screenSizeType: ScreenSizeType; - }): Promise { + }): Promise { if (!options) { // this should never happen options = { @@ -61,7 +61,7 @@ export default class SyntheticMonitor { }; } - const scriptResult: SyntheticMonitor = { + const scriptResult: SyntheticMonitorResponse = { logMessages: [], scriptError: undefined, result: undefined, From d0692ebc8fce3af778f23a0c794a4be1143abb2a Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Sun, 4 Aug 2024 20:44:30 -0600 Subject: [PATCH 7/7] refactor: Remove unnecessary whitespace in code --- .../Jobs/ServerMonitor/CheckOnlineStatus.ts | 5 +---- Common/Types/Probe/ProbeMonitorResponse.ts | 2 +- .../Criteria/CustomCodeMonitorCriteria.ts | 2 +- CommonServer/Utils/Monitor/MonitorResource.ts | 12 ++++++------ .../SummaryView/CustomMonitorSummaryView.tsx | 3 ++- .../Monitor/SummaryView/SummaryInfo.tsx | 6 +++--- .../SummaryView/SyntheticMonitorView.tsx | 8 ++++---- Dashboard/src/Pages/Monitor/View/Index.tsx | 6 +++--- Ingestor/API/ServerMonitor.ts | 4 +--- Probe/Utils/Monitors/Monitor.ts | 18 +++++++++--------- .../Monitors/MonitorTypes/CustomCodeMonitor.ts | 2 +- 11 files changed, 32 insertions(+), 36 deletions(-) diff --git a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts index 93f403d18c5..ba54dcde2ac 100644 --- a/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts +++ b/App/FeatureSet/Workers/Jobs/ServerMonitor/CheckOnlineStatus.ts @@ -56,10 +56,7 @@ RunCron( hostname: "", }; - await MonitorResourceUtil.monitorResource( - serverMonitorResponse, - ); - + await MonitorResourceUtil.monitorResource(serverMonitorResponse); } catch (error) { logger.error( `Error in ServerMonitor:CheckOnlineStatus for monitorId: ${monitor.id}`, diff --git a/Common/Types/Probe/ProbeMonitorResponse.ts b/Common/Types/Probe/ProbeMonitorResponse.ts index 59e6d441291..6315e466802 100644 --- a/Common/Types/Probe/ProbeMonitorResponse.ts +++ b/Common/Types/Probe/ProbeMonitorResponse.ts @@ -21,7 +21,7 @@ export default interface ProbeMonitorResponse { monitorId: ObjectID; probeId: ObjectID; failureCause: string; - sslResponse?: SslMonitorResponse| undefined; + sslResponse?: SslMonitorResponse | undefined; syntheticMonitorResponse?: Array | undefined; customCodeMonitorResponse?: CustomCodeMonitorResponse | undefined; monitoredAt: Date; diff --git a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts index fad60b398c1..9c6f48fe377 100644 --- a/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts +++ b/CommonServer/Utils/Monitor/Criteria/CustomCodeMonitorCriteria.ts @@ -19,7 +19,7 @@ export default class CustomCodeMonitoringCriteria { threshold = CompareCriteria.convertToNumber(threshold); const currentExecutionTime: number = - syntheticMonitorResponse.executionTimeInMS || 0; + syntheticMonitorResponse.executionTimeInMS || 0; return CompareCriteria.compareCriteriaNumbers({ value: currentExecutionTime, diff --git a/CommonServer/Utils/Monitor/MonitorResource.ts b/CommonServer/Utils/Monitor/MonitorResource.ts index e869a055518..ed10c3b964a 100644 --- a/CommonServer/Utils/Monitor/MonitorResource.ts +++ b/CommonServer/Utils/Monitor/MonitorResource.ts @@ -534,7 +534,7 @@ export default class MonitorResourceUtil { } if ((data.dataToProcess as ProbeMonitorResponse).syntheticMonitorResponse) { - for (const syntheticMonitor of ( + for (const syntheticMonitorResponse of ( data.dataToProcess as ProbeMonitorResponse ).syntheticMonitorResponse || []) { const monitorMetricsByMinute: MonitorMetricsByMinute = @@ -543,13 +543,13 @@ export default class MonitorResourceUtil { monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ExecutionTime; monitorMetricsByMinute.metricValue = - syntheticMonitor.executionTimeInMS; + syntheticMonitorResponse.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( data.dataToProcess as ProbeMonitorResponse ).probeId.toString(), - browserType: syntheticMonitor.browserType, - screenSizeType: syntheticMonitor.screenSizeType, + browserType: syntheticMonitorResponse.browserType, + screenSizeType: syntheticMonitorResponse.screenSizeType, }; itemsToSave.push(monitorMetricsByMinute); @@ -559,7 +559,7 @@ export default class MonitorResourceUtil { if ( (data.dataToProcess as ProbeMonitorResponse).customCodeMonitorResponse ) { - const customCodeMonitor: CustomCodeMonitorResponse = ( + const customCodeMonitorResponse: CustomCodeMonitorResponse = ( data.dataToProcess as ProbeMonitorResponse ).customCodeMonitorResponse!; @@ -569,7 +569,7 @@ export default class MonitorResourceUtil { monitorMetricsByMinute.projectId = data.projectId; monitorMetricsByMinute.metricType = CheckOn.ExecutionTime; monitorMetricsByMinute.metricValue = - customCodeMonitor.executionTimeInMS; + customCodeMonitorResponse.executionTimeInMS; monitorMetricsByMinute.miscData = { probeId: ( data.dataToProcess as ProbeMonitorResponse diff --git a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx index 38cb4ff8da8..0c07ccf664d 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/CustomMonitorSummaryView.tsx @@ -28,7 +28,8 @@ const CustomCodeMonitorSummaryView: FunctionComponent = ( const customCodeMonitorResponse: CustomCodeMonitorResponse = props.customCodeMonitorResponse; - let executionTimeInMS: number = customCodeMonitorResponse.executionTimeInMS || 0; + let executionTimeInMS: number = + customCodeMonitorResponse.executionTimeInMS || 0; if (executionTimeInMS > 0) { executionTimeInMS = Math.round(executionTimeInMS); diff --git a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx index 090e170c2f0..271cd3877b8 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SummaryInfo.tsx @@ -118,8 +118,8 @@ const SummaryInfo: FunctionComponent = (
{props.probeMonitorResponses && props.probeMonitorResponses.map( - (probeMonitorResponses: ProbeMonitorResponse, index: number) => { - return getProbableMonitorSummarysInfo(probeMonitorResponses, index); + (probeMonitorResponse: ProbeMonitorResponse, index: number) => { + return getProbableMonitorSummarysInfo(probeMonitorResponse, index); }, )} @@ -135,7 +135,7 @@ const SummaryInfo: FunctionComponent = ( {props.monitorType === MonitorType.Server && props.serverMonitorResponse ? ( ) : ( <> diff --git a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx index 326db919b30..b67de8a1d9f 100644 --- a/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx +++ b/Dashboard/src/Components/Monitor/SummaryView/SyntheticMonitorView.tsx @@ -21,13 +21,13 @@ const SyntheticMonitorView: FunctionComponent = ( ); } - const syntheticMonitors: Array = + const syntheticMonitorResponses: Array = props.probeMonitorResponse.syntheticMonitorResponse; return (
- {syntheticMonitors && - syntheticMonitors.map( + {syntheticMonitorResponses && + syntheticMonitorResponses.map( ( syntheticMonitorResponse: SyntheticMonitorResponse, index: number, @@ -39,7 +39,7 @@ const SyntheticMonitorView: FunctionComponent = ( syntheticMonitorResponse={syntheticMonitorResponse} monitoredAt={props.probeMonitorResponse.monitoredAt} /> - {index !== syntheticMonitors.length - 1 && ( + {index !== syntheticMonitorResponses.length - 1 && ( )}
diff --git a/Dashboard/src/Pages/Monitor/View/Index.tsx b/Dashboard/src/Pages/Monitor/View/Index.tsx index c487bed882c..cc0568a0e54 100644 --- a/Dashboard/src/Pages/Monitor/View/Index.tsx +++ b/Dashboard/src/Pages/Monitor/View/Index.tsx @@ -294,7 +294,7 @@ const MonitorView: FunctionComponent = (): ReactElement => { }, }); - const probeMonitors: Array = []; + const probeMonitorResponses: Array = []; for (let i: number = 0; i < monitorProbes.data.length; i++) { const monitorProbe: MonitorProbe | undefined = monitorProbes.data[i]; @@ -311,10 +311,10 @@ const MonitorView: FunctionComponent = (): ReactElement => { continue; } - probeMonitors.push(monitorProbe?.lastMonitoringLog); + probeMonitorResponses.push(monitorProbe?.lastMonitoringLog); } - setProbeResponses(probeMonitors); + setProbeResponses(probeMonitorResponses); } } catch (err) { setError(API.getFriendlyMessage(err)); diff --git a/Ingestor/API/ServerMonitor.ts b/Ingestor/API/ServerMonitor.ts index c3ec4705dea..ef20838898b 100644 --- a/Ingestor/API/ServerMonitor.ts +++ b/Ingestor/API/ServerMonitor.ts @@ -109,9 +109,7 @@ router.post( // process probe response here. const probeApiIngestResponse: ProbeApiIngestResponse = - await MonitorResourceUtil.monitorResource( - serverMonitorResponse, - ); + await MonitorResourceUtil.monitorResource(serverMonitorResponse); return Response.sendJsonObjectResponse(req, res, { probeApiIngestResponse: probeApiIngestResponse, diff --git a/Probe/Utils/Monitors/Monitor.ts b/Probe/Utils/Monitors/Monitor.ts index f5a249f1ab1..3cba8be650e 100644 --- a/Probe/Utils/Monitors/Monitor.ts +++ b/Probe/Utils/Monitors/Monitor.ts @@ -2,11 +2,11 @@ import { INGESTOR_URL } from "../../Config"; import ProbeUtil from "../Probe"; import ProbeAPIRequest from "../ProbeAPIRequest"; import ApiMonitor, { APIResponse } from "./MonitorTypes/ApiMonitor"; -import CustomCodeMonitorResponse from "./MonitorTypes/CustomCodeMonitorResponse"; +import CustomCodeMonitor from "./MonitorTypes/CustomCodeMonitor"; import PingMonitor, { PingResponse } from "./MonitorTypes/PingMonitor"; -import PortMonitorResponse, { PortMonitorResponse } from "./MonitorTypes/PortMonitorResponse"; +import PortMonitor, { PortMonitorResponse } from "./MonitorTypes/PortMonitor"; import SSLMonitor, { SslResponse } from "./MonitorTypes/SslMonitor"; -import SyntheticMonitorResponse from "./MonitorTypes/SyntheticMonitorResponse"; +import SyntheticMonitor from "./MonitorTypes/SyntheticMonitor"; import WebsiteMonitor, { ProbeWebsiteResponse, } from "./MonitorTypes/WebsiteMonitor"; @@ -16,7 +16,7 @@ import OneUptimeDate from "Common/Types/Date"; import { JSONObject } from "Common/Types/JSON"; import JSONFunctions from "Common/Types/JSONFunctions"; import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter"; -import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitorResponse/CustomCodeMonitorResponse"; +import CustomCodeMonitorResponse from "Common/Types/Monitor/CustomCodeMonitor/CustomCodeMonitorResponse"; import MonitorCriteriaInstance from "Common/Types/Monitor/MonitorCriteriaInstance"; import MonitorStep from "Common/Types/Monitor/MonitorStep"; import MonitorType from "Common/Types/Monitor/MonitorType"; @@ -31,7 +31,7 @@ import logger from "CommonServer/Utils/Logger"; import Monitor from "Model/Models/Monitor"; export default class MonitorUtil { - public static async probeMonitorResponse( + public static async probeMonitor( monitor: Monitor, ): Promise> { const results: Array = []; @@ -145,7 +145,7 @@ export default class MonitorUtil { if (LocalCache.getString("PROBE", "PING_MONITORING") === "PORT") { // probe is online but ping monitoring is blocked by the cloud provider. Fallback to port monitoring. - const response: PortMonitorResponse | null = await PortMonitorResponse.ping( + const response: PortMonitorResponse | null = await PortMonitor.ping( monitorStep.data?.monitorDestination, new Port(80), // use port 80 by default. { @@ -197,7 +197,7 @@ export default class MonitorUtil { result.monitorDestinationPort = monitorStep.data.monitorDestinationPort; - const response: PortMonitorResponse | null = await PortMonitorResponse.ping( + const response: PortMonitorResponse | null = await PortMonitor.ping( monitorStep.data?.monitorDestination, monitorStep.data.monitorDestinationPort, { @@ -223,7 +223,7 @@ export default class MonitorUtil { } const response: Array | null = - await SyntheticMonitorResponse.execute({ + await SyntheticMonitor.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, screenSizeTypes: monitorStep.data @@ -246,7 +246,7 @@ export default class MonitorUtil { } const response: CustomCodeMonitorResponse | null = - await CustomCodeMonitorResponse.execute({ + await CustomCodeMonitor.execute({ script: monitorStep.data.customCode, monitorId: monitor.id!, }); diff --git a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts index 4161732f1e7..dcb8a928fef 100644 --- a/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/CustomCodeMonitor.ts @@ -13,7 +13,7 @@ export interface CustomCodeMonitorOptions { export default class CustomCodeMonitor { public static async execute( options: CustomCodeMonitorOptions, - ): Promise { + ): Promise { if (!options) { // this should never happen options = {