diff --git a/Common/Models/DatabaseModels/Alert.ts b/Common/Models/DatabaseModels/Alert.ts index 2166d438ce..edf1008353 100644 --- a/Common/Models/DatabaseModels/Alert.ts +++ b/Common/Models/DatabaseModels/Alert.ts @@ -801,7 +801,6 @@ export default class Alert extends BaseModel { ], update: [], }) - @Index() @TableColumn({ type: TableColumnType.Markdown, required: false, diff --git a/Common/Models/DatabaseModels/Incident.ts b/Common/Models/DatabaseModels/Incident.ts index b49f5db110..68eba3c0e8 100644 --- a/Common/Models/DatabaseModels/Incident.ts +++ b/Common/Models/DatabaseModels/Incident.ts @@ -855,7 +855,6 @@ export default class Incident extends BaseModel { ], update: [], }) - @Index() @TableColumn({ type: TableColumnType.Markdown, required: false, diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433043136-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433043136-MigrationName.ts new file mode 100644 index 0000000000..14ac84de46 --- /dev/null +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433043136-MigrationName.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MigrationName1731433043136 implements MigrationInterface { + public name = 'MigrationName1731433043136' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."IDX_5218e92f700d91afe6a8db79cb"`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "IDX_5218e92f700d91afe6a8db79cb" ON "Incident" ("rootCause") `); + } + +} diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433309124-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433309124-MigrationName.ts new file mode 100644 index 0000000000..d5a2cacfc2 --- /dev/null +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1731433309124-MigrationName.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class MigrationName1731433309124 implements MigrationInterface { + public name = 'MigrationName1731433309124' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."IDX_fc40ea6a9ad55f29bca4f4a15d"`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "IDX_fc40ea6a9ad55f29bca4f4a15d" ON "Alert" ("rootCause") `); + } + +} diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts index 419387356b..72546773ec 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts @@ -78,6 +78,8 @@ import { MigrationName1729682875503 } from "./1729682875503-MigrationName"; import { MigrationName1730117995642 } from "./1730117995642-MigrationName"; import { MigrationName1730209089495 } from "./1730209089495-MigrationName"; import { MigrationName1730223198692 } from "./1730223198692-MigrationName"; +import { MigrationName1731433043136 } from "./1731433043136-MigrationName"; +import { MigrationName1731433309124 } from "./1731433309124-MigrationName"; export default [ InitialMigration, @@ -160,4 +162,6 @@ export default [ MigrationName1730117995642, MigrationName1730209089495, MigrationName1730223198692, + MigrationName1731433043136, + MigrationName1731433309124 ]; diff --git a/Common/Server/Utils/Browser.ts b/Common/Server/Utils/Browser.ts index 0a65f0c398..dfb080889d 100644 --- a/Common/Server/Utils/Browser.ts +++ b/Common/Server/Utils/Browser.ts @@ -8,6 +8,7 @@ import LocalFile from "./LocalFile"; import BadDataException from "../../Types/Exception/BadDataException"; import ScreenSizeType from "../../Types/ScreenSizeType"; import BrowserType from "../../Types/BrowserType"; +import logger from "./Logger"; export type Page = PlaywrightPage; export type Browser = PlaywrightBrowser; @@ -15,26 +16,31 @@ export type Browser = PlaywrightBrowser; export default class BrowserUtil { public static async convertHtmlToBase64Screenshot(data: { html: string; - }): Promise { - const html: string = data.html; - - const pageAndBrowser: { - page: Page; - browser: Browser; - } = await BrowserUtil.getPageByBrowserType({ - browserType: BrowserType.Chromium, - screenSizeType: ScreenSizeType.Desktop, - }); + }): Promise { + try { + const html: string = data.html; + + const pageAndBrowser: { + page: Page; + browser: Browser; + } = await BrowserUtil.getPageByBrowserType({ + browserType: BrowserType.Chromium, + screenSizeType: ScreenSizeType.Desktop, + }); - const page: Page = pageAndBrowser.page; - const browser: Browser = pageAndBrowser.browser; + const page: Page = pageAndBrowser.page; + const browser: Browser = pageAndBrowser.browser; - await page.setContent(html); - const screenshot: Buffer = await page.screenshot({ type: "png" }); + await page.setContent(html); + const screenshot: Buffer = await page.screenshot({ type: "png" }); - await browser.close(); + await browser.close(); - return screenshot.toString("base64"); + return screenshot.toString("base64"); + } catch (e) { + logger.debug(e); + return null; + } } public static async getPageByBrowserType(data: { diff --git a/Common/Server/Utils/Monitor/MonitorIncident.ts b/Common/Server/Utils/Monitor/MonitorIncident.ts index a9a66c81b6..3eb81f86f1 100644 --- a/Common/Server/Utils/Monitor/MonitorIncident.ts +++ b/Common/Server/Utils/Monitor/MonitorIncident.ts @@ -131,6 +131,8 @@ export default class MonitorIncident { // create incident here. + debugger; + logger.debug(`${input.monitor.id?.toString()} - Create incident.`); const incident: Incident = new Incident(); diff --git a/Common/Server/Utils/Monitor/MonitorResource.ts b/Common/Server/Utils/Monitor/MonitorResource.ts index e2b571ce54..12e71341fc 100644 --- a/Common/Server/Utils/Monitor/MonitorResource.ts +++ b/Common/Server/Utils/Monitor/MonitorResource.ts @@ -143,8 +143,7 @@ export default class MonitorResourceUtil { // get last log. We do this because there are many monitoring steps and we need to store those. logger.debug( - `${dataToProcess.monitorId.toString()} - monitor type ${ - monitor.monitorType + `${dataToProcess.monitorId.toString()} - monitor type ${monitor.monitorType }`, ); @@ -310,7 +309,7 @@ export default class MonitorResourceUtil { if (incidentTemplate.autoResolveIncident) { if ( !autoResolveCriteriaInstanceIdIncidentIdsDictionary[ - criteriaInstance.data.id.toString() + criteriaInstance.data.id.toString() ] ) { autoResolveCriteriaInstanceIdIncidentIdsDictionary[ @@ -346,7 +345,7 @@ export default class MonitorResourceUtil { if (alertTemplate.autoResolveAlert) { if ( !autoResolveCriteriaInstanceIdAlertIdsDictionary[ - criteriaInstance.data.id.toString() + criteriaInstance.data.id.toString() ] ) { autoResolveCriteriaInstanceIdAlertIdsDictionary[ @@ -416,13 +415,11 @@ export default class MonitorResourceUtil { if (response.criteriaMetId && response.rootCause) { logger.debug( - `${dataToProcess.monitorId.toString()} - Criteria met: ${ - response.criteriaMetId + `${dataToProcess.monitorId.toString()} - Criteria met: ${response.criteriaMetId }`, ); logger.debug( - `${dataToProcess.monitorId.toString()} - Root cause: ${ - response.rootCause + `${dataToProcess.monitorId.toString()} - Root cause: ${response.rootCause }`, ); @@ -483,7 +480,7 @@ export default class MonitorResourceUtil { !response.criteriaMetId && monitorSteps.data.defaultMonitorStatusId && monitor.currentMonitorStatusId?.toString() !== - monitorSteps.data.defaultMonitorStatusId.toString() + monitorSteps.data.defaultMonitorStatusId.toString() ) { logger.debug( `${dataToProcess.monitorId.toString()} - No criteria met. Change to default status.`, @@ -520,7 +517,7 @@ export default class MonitorResourceUtil { lastMonitorStatusTimeline && lastMonitorStatusTimeline.monitorStatusId && lastMonitorStatusTimeline.monitorStatusId.toString() === - monitorSteps.data.defaultMonitorStatusId.toString() + monitorSteps.data.defaultMonitorStatusId.toString() ) { // status is same as last status. do not create new status timeline. // do nothing! status is same as last status. @@ -957,6 +954,7 @@ export default class MonitorResourceUtil { probeApiIngestResponse: ProbeApiIngestResponse; criteriaInstance: MonitorCriteriaInstance; }): Promise { + // returns root cause if any. Otherwise criteria is not met. let finalResult: string | null = "All filters met. "; @@ -1019,10 +1017,14 @@ export default class MonitorResourceUtil { .responseBody as string, }); - finalResult += ` + if (screenshotInBase64) { + + finalResult += ` **Screenshot**: + ![Screenshot](data:image/png;base64,${screenshotInBase64}); `; + } } } }