|
|
@ -2,10 +2,12 @@ import { getJsonDataSync } from './services/json_service'; |
|
|
|
import { normalizeUrl } from './utils/url'; |
|
|
|
import { normalizeUrl } from './utils/url'; |
|
|
|
import { parseTimeZone } from './utils/time'; |
|
|
|
import { parseTimeZone } from './utils/time'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
import * as moment from 'moment'; |
|
|
|
import * as path from 'path'; |
|
|
|
import * as path from 'path'; |
|
|
|
import * as fs from 'fs'; |
|
|
|
import * as fs from 'fs'; |
|
|
|
import * as os from 'os'; |
|
|
|
import * as os from 'os'; |
|
|
|
import * as moment from 'moment'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let configFile = path.join(__dirname, '../../config.json'); |
|
|
|
let configFile = path.join(__dirname, '../../config.json'); |
|
|
|
let configExists = fs.existsSync(configFile); |
|
|
|
let configExists = fs.existsSync(configFile); |
|
|
@ -21,7 +23,8 @@ export type DBConfig = { |
|
|
|
export const ANALYTICS_PATH = path.join(__dirname, '../../analytics'); |
|
|
|
export const ANALYTICS_PATH = path.join(__dirname, '../../analytics'); |
|
|
|
|
|
|
|
|
|
|
|
export const HASTIC_DB_IN_MEMORY = getConfigField('HASTIC_IN_MEMORY_PERSISTANCE', false); |
|
|
|
export const HASTIC_DB_IN_MEMORY = getConfigField('HASTIC_IN_MEMORY_PERSISTANCE', false); |
|
|
|
export const HASTIC_DB_CONNECTION_TYPE = getConfigField('HASTIC_DB_CONNECTION_TYPE', 'nedb'); //nedb or mongodb
|
|
|
|
// TODO: enum for DB types
|
|
|
|
|
|
|
|
export const HASTIC_DB_CONNECTION_TYPE = getConfigField('HASTIC_DB_CONNECTION_TYPE', 'nedb', ['nedb', 'mongodb']); |
|
|
|
|
|
|
|
|
|
|
|
//connection string syntax: <db_user>:<db_password>@<db_url>/<db_name>
|
|
|
|
//connection string syntax: <db_user>:<db_password>@<db_url>/<db_name>
|
|
|
|
export const HASTIC_DB_CONNECTION_STRING = getConfigField( |
|
|
|
export const HASTIC_DB_CONNECTION_STRING = getConfigField( |
|
|
@ -45,14 +48,24 @@ export const ZMQ_DEV_PORT = getConfigField('ZMQ_DEV_PORT', '8002'); |
|
|
|
export const ZMQ_HOST = getConfigField('ZMQ_HOST', '127.0.0.1'); |
|
|
|
export const ZMQ_HOST = getConfigField('ZMQ_HOST', '127.0.0.1'); |
|
|
|
export const HASTIC_API_KEY = getConfigField('HASTIC_API_KEY'); |
|
|
|
export const HASTIC_API_KEY = getConfigField('HASTIC_API_KEY'); |
|
|
|
export const GRAFANA_URL = normalizeUrl(getConfigField('GRAFANA_URL', null)); |
|
|
|
export const GRAFANA_URL = normalizeUrl(getConfigField('GRAFANA_URL', null)); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: save orgId in analytic_units.db
|
|
|
|
// TODO: save orgId in analytic_units.db
|
|
|
|
export const ORG_ID = getConfigField('ORG_ID', 1); |
|
|
|
export const ORG_ID = getConfigField('ORG_ID', 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export enum AlertTypes { |
|
|
|
|
|
|
|
WEBHOOK = 'webhook', |
|
|
|
|
|
|
|
ALERTMANAGER = 'alertmanager' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
export const HASTIC_ALERT_TYPE = getConfigField('HASTIC_ALERT_TYPE', AlertTypes.WEBHOOK, _.values(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_URL = getConfigField('HASTIC_WEBHOOK_URL', null); |
|
|
|
export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json'); |
|
|
|
export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json'); |
|
|
|
export const HASTIC_WEBHOOK_SECRET = getConfigField('HASTIC_WEBHOOK_SECRET', null); |
|
|
|
export const HASTIC_WEBHOOK_SECRET = getConfigField('HASTIC_WEBHOOK_SECRET', null); |
|
|
|
export const HASTIC_WEBHOOK_IMAGE_ENABLED = getConfigField('HASTIC_WEBHOOK_IMAGE', false); |
|
|
|
|
|
|
|
export const TIMEZONE_UTC_OFFSET = getTimeZoneOffset(); |
|
|
|
export const TIMEZONE_UTC_OFFSET = getTimeZoneOffset(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const HASTIC_ALERTMANAGER_URL = getConfigField('HASTIC_ALERTMANAGER_URL', null); |
|
|
|
|
|
|
|
|
|
|
|
export const ANLYTICS_PING_INTERVAL = 500; // ms
|
|
|
|
export const ANLYTICS_PING_INTERVAL = 500; // ms
|
|
|
|
export const PACKAGE_VERSION = getPackageVersion(); |
|
|
|
export const PACKAGE_VERSION = getPackageVersion(); |
|
|
|
export const GIT_INFO = getGitInfo(); |
|
|
|
export const GIT_INFO = getGitInfo(); |
|
|
@ -63,7 +76,7 @@ export const ZMQ_CONNECTION_STRING = createZMQConnectionString(); |
|
|
|
export const HASTIC_INSTANCE_NAME = getConfigField('HASTIC_INSTANCE_NAME', os.hostname()); |
|
|
|
export const HASTIC_INSTANCE_NAME = getConfigField('HASTIC_INSTANCE_NAME', os.hostname()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getConfigField(field: string, defaultVal?: any) { |
|
|
|
function getConfigField(field: string, defaultVal?: any, allowedVals?: any[]) { |
|
|
|
let val; |
|
|
|
let val; |
|
|
|
|
|
|
|
|
|
|
|
if(process.env[field] !== undefined) { |
|
|
|
if(process.env[field] !== undefined) { |
|
|
@ -82,6 +95,11 @@ function getConfigField(field: string, defaultVal?: any) { |
|
|
|
} |
|
|
|
} |
|
|
|
val = defaultVal; |
|
|
|
val = defaultVal; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(allowedVals !== undefined && !_.includes(allowedVals, val)) { |
|
|
|
|
|
|
|
throw new Error(`${field} value must be in ${allowedVals}, got ${val}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(`${field}: ${val}`); |
|
|
|
console.log(`${field}: ${val}`); |
|
|
|
return val; |
|
|
|
return val; |
|
|
|
} |
|
|
|
} |
|
|
|