From d6f90dab2c25c3126487d3f246f9556f37c6f693 Mon Sep 17 00:00:00 2001 From: Alexandr Velikiy <39257464+VargBurz@users.noreply.github.com> Date: Thu, 26 Dec 2019 19:07:09 +0300 Subject: [PATCH] Error: Property 'length' is missing in type 'AnalyticMeta' #823 (#822) --- config.example.json | 2 -- docker-compose-mongo.yml | 1 - docker-compose.yml | 1 - server/src/config.ts | 2 -- server/src/services/notification_service.ts | 22 ++++----------------- 5 files changed, 4 insertions(+), 24 deletions(-) diff --git a/config.example.json b/config.example.json index 20a63f3..6a54b1c 100644 --- a/config.example.json +++ b/config.example.json @@ -2,8 +2,6 @@ "HASTIC_PORT": 8000, "HASTIC_API_KEY": "eyJrIjoiVjZqMHY0dHk4UEE3eEN4MzgzRnd2aURlMWlIdXdHNW4iLCJuIjoiaGFzdGljIiwiaWQiOjF9", "HASTIC_WEBHOOK_URL": "http://localhost:8080", - "HASTIC_WEBHOOK_TYPE": "application/x-www-form-urlencoded", - "HASTIC_WEBHOOK_SECRET": "mysecret", "GRAFANA_URL": "http://localhost:3000", "LEARNING_TIMEOUT": 120 } diff --git a/docker-compose-mongo.yml b/docker-compose-mongo.yml index fb10283..f7b9f0c 100644 --- a/docker-compose-mongo.yml +++ b/docker-compose-mongo.yml @@ -16,7 +16,6 @@ services: HASTIC_ALERT_TYPE: ${HASTIC_ALERT_TYPE} HASTIC_ALERTMANAGER_URL: ${HASTIC_ALERTMANAGER_URL} HASTIC_WEBHOOK_URL: ${HASTIC_WEBHOOK_URL} - HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} HASTIC_ALERT_IMAGE: ${HASTIC_ALERT_IMAGE} HASTIC_TIMEZONE_OFFSET: ${HASTIC_TIMEZONE_OFFSET} diff --git a/docker-compose.yml b/docker-compose.yml index 7a9d8f3..be4c9c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,6 @@ services: HASTIC_ALERT_TYPE: ${HASTIC_ALERT_TYPE} HASTIC_ALERTMANAGER_URL: ${HASTIC_ALERTMANAGER_URL} HASTIC_WEBHOOK_URL: ${HASTIC_WEBHOOK_URL} - HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} HASTIC_ALERT_IMAGE: ${HASTIC_ALERT_IMAGE} HASTIC_DB_CONNECTION_STRING: ${HASTIC_DB_CONNECTION_STRING} diff --git a/server/src/config.ts b/server/src/config.ts index a66730c..a58b26a 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -60,8 +60,6 @@ export const HASTIC_ALERT_TYPE = getConfigField('HASTIC_ALERT_TYPE', AlertTypes. export const HASTIC_ALERT_IMAGE = getConfigField('HASTIC_ALERT_IMAGE', false); export const HASTIC_WEBHOOK_URL = getConfigField('HASTIC_WEBHOOK_URL', null); -export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json'); -export const HASTIC_WEBHOOK_SECRET = getConfigField('HASTIC_WEBHOOK_SECRET', null); export const HASTIC_TIMEZONE_OFFSET = getTimeZoneOffset(); export const HASTIC_ALERTMANAGER_URL = getConfigField('HASTIC_ALERTMANAGER_URL', null); diff --git a/server/src/services/notification_service.ts b/server/src/services/notification_service.ts index bf45ce6..f0c312e 100644 --- a/server/src/services/notification_service.ts +++ b/server/src/services/notification_service.ts @@ -2,13 +2,8 @@ import * as AnalyticUnit from '../models/analytic_units'; import * as config from '../config'; import axios from 'axios'; -import * as querystring from 'querystring'; import * as _ from 'lodash'; -enum ContentType { - JSON = 'application/json', - URLENCODED ='application/x-www-form-urlencoded' -} export enum WebhookType { DETECT = 'DETECT', @@ -67,22 +62,13 @@ class WebhookNotifier implements Notifier { } notification.text += `\nInstance: ${config.HASTIC_INSTANCE_NAME}`; - - let data; - if(config.HASTIC_WEBHOOK_TYPE === ContentType.JSON) { - data = JSON.stringify(notification); - } else if(config.HASTIC_WEBHOOK_TYPE === ContentType.URLENCODED) { - data = querystring.stringify(notification); - } else { - throw new Error(`Unknown webhook type: ${config.HASTIC_WEBHOOK_TYPE}`); - } - - // TODO: use HASTIC_WEBHOOK_SECRET + const data = JSON.stringify(notification); + const options = { method: 'POST', url: config.HASTIC_WEBHOOK_URL, data, - headers: { 'Content-Type': config.HASTIC_WEBHOOK_TYPE } + headers: { 'Content-Type': 'application/json' } }; await axios(options); @@ -146,7 +132,7 @@ class AlertManagerNotifier implements Notifier { method: 'POST', url: `${config.HASTIC_ALERTMANAGER_URL}/api/v2/alerts`, data: JSON.stringify([alertData]), - headers: { 'Content-Type': ContentType.JSON } + headers: { 'Content-Type': 'application/json' } }; // first part: send "start" request