Browse Source

Error: Property 'length' is missing in type 'AnalyticMeta' #823 (#822)

pull/1/head
Alexandr Velikiy 5 years ago committed by rozetko
parent
commit
d6f90dab2c
  1. 2
      config.example.json
  2. 1
      docker-compose-mongo.yml
  3. 1
      docker-compose.yml
  4. 2
      server/src/config.ts
  5. 20
      server/src/services/notification_service.ts

2
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
}

1
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}

1
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}

2
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);

20
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}`;
const data = JSON.stringify(notification);
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 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

Loading…
Cancel
Save