|
@@ -4,7 +4,9 @@ import moment from 'moment';
|
|
|
import path from 'path';
|
|
import path from 'path';
|
|
|
import { Database as SQLiteDB, OPEN_CREATE, OPEN_READWRITE } from 'sqlite3';
|
|
import { Database as SQLiteDB, OPEN_CREATE, OPEN_READWRITE } from 'sqlite3';
|
|
|
|
|
|
|
|
|
|
+import { ServiceConfig, validateParamType } from '../../../common/interfaces/service-config.interface';
|
|
|
import { Logger } from '../../../common/util/logger.class';
|
|
import { Logger } from '../../../common/util/logger.class';
|
|
|
|
|
+
|
|
|
import { DBMigration } from './db-migration.class';
|
|
import { DBMigration } from './db-migration.class';
|
|
|
import { SQLiteController } from './sqlite-controller.base';
|
|
import { SQLiteController } from './sqlite-controller.base';
|
|
|
|
|
|
|
@@ -221,4 +223,46 @@ export class Database extends SQLiteController {
|
|
|
|
|
|
|
|
return result.rows.map(r => ({ time: new Date(r.Timegroup), avg: r.avg, peak: r.peak, max: r.max }));
|
|
return result.rows.map(r => ({ time: new Date(r.Timegroup), avg: r.avg, peak: r.peak, max: r.max }));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ async getHealthCheckConfigs(serverID: number) {
|
|
|
|
|
+ const res = await this.stmt(
|
|
|
|
|
+ `SELECT
|
|
|
|
|
+ HealthCheckConfig.*,
|
|
|
|
|
+ HealthCheckParams.Type as '_ParamType',
|
|
|
|
|
+ HealthCheckParams.Key as '_ParamKey',
|
|
|
|
|
+ HealthCheckParams.Value as '_ParamValue'
|
|
|
|
|
+ FROM HealthCheckConfig
|
|
|
|
|
+ LEFT OUTER JOIN HealthCheckParams ON HealthCheckConfig.ID = HealthCheckParams.ConfigID
|
|
|
|
|
+ WHERE HealthCheckConfig.ServerID = ?
|
|
|
|
|
+ ORDER BY HealthCheckConfig.Title, _ParamType, _ParamKey`,
|
|
|
|
|
+ [serverID]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return res.rows.reduce((res: ServiceConfig[], line, i) => {
|
|
|
|
|
+ const configID = line['ID'];
|
|
|
|
|
+ let config: ServiceConfig;
|
|
|
|
|
+ if (i === 0 || res[res.length - 1].id !== configID) {
|
|
|
|
|
+ config = {
|
|
|
|
|
+ id: configID,
|
|
|
|
|
+ title: line['Title'],
|
|
|
|
|
+ type: line['Type'],
|
|
|
|
|
+ params: []
|
|
|
|
|
+ };
|
|
|
|
|
+ res.push(config);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ config = res[res.length - 1];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!!line['_ParamKey']) {
|
|
|
|
|
+ const type = validateParamType(line['_ParamType']);
|
|
|
|
|
+ config.params.push({
|
|
|
|
|
+ type,
|
|
|
|
|
+ key: line['_ParamKey'],
|
|
|
|
|
+ value: type === 'number' ? Number(line['_ParamValue']) : line['_ParamValue']
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }, [] as ServiceConfig[]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|