From a536bf0a6d06581f506270e028ff7eae33886387 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 15 Mar 2019 17:40:33 +0300 Subject: [PATCH] Add active webhooks amount to server status --- server/src/controllers/analytics_controller.ts | 4 ++++ server/src/index.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 9edacdc..5b553da 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -369,6 +369,10 @@ export function isAnalyticReady(): boolean { return analyticsService.ready; } +export async function getActiveWebhooks() { + const analyticUnits = await AnalyticUnit.findMany({ alert: true }); + return analyticUnits.map(analyticUnit => analyticUnit.id); +} export async function createAnalyticUnitFromObject(obj: any): Promise { if(obj.datasource !== undefined) { diff --git a/server/src/index.ts b/server/src/index.ts index a7d3b22..bce00de 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -42,6 +42,9 @@ rootRouter.use('/panel', panelRouter.routes(), panelRouter.allowedMethods()); rootRouter.use('/threshold', thresholdRouter.routes(), thresholdRouter.allowedMethods()); rootRouter.get('/', async (ctx) => { + const activeWebhooks = await AnalyticsController.getActiveWebhooks(); + const activeWebhooksAmount = activeWebhooks.length; + ctx.response.body = { server: 'OK', analyticsReady: AnalyticsController.isAnalyticReady(), @@ -51,7 +54,8 @@ rootRouter.get('/', async (ctx) => { docker: process.env.INSIDE_DOCKER !== undefined, zmqConectionString: ZMQ_CONNECTION_STRING, serverPort: HASTIC_PORT, - git: GIT_INFO + git: GIT_INFO, + activeWebhooksAmount }; });