From 5d0b773f96e5dd765bab860c8c290d1911680b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel?= Date: Mon, 1 Oct 2018 09:56:50 +0200 Subject: [PATCH] Renamed all server routes --- init.js | 2 + public/controllers/agent/agents-preview.js | 6 +- public/controllers/management/monitoring.js | 2 +- public/controllers/misc/health-check.js | 6 +- public/controllers/misc/reporting.js | 4 +- public/controllers/settings/index.js | 20 +++---- public/directives/wz-menu/wz-menu.js | 4 +- public/services/api-request.js | 2 +- public/services/api-tester.js | 4 +- public/services/common-data.js | 4 +- public/services/csv-request.js | 4 +- public/services/pattern-handler.js | 4 +- public/services/reporting.js | 2 +- public/services/resolves/check-ram.js | 2 +- public/services/resolves/check-timestamp.js | 2 +- public/services/resolves/get-config.js | 2 +- public/services/resolves/get-ip.js | 2 +- public/services/resolves/settings-wizard.js | 2 +- public/services/vis-factory-handler.js | 4 +- public/templates/management/reporting.html | 2 +- server/controllers/index.js | 4 +- server/controllers/wazuh-api-elastic.js | 12 ++-- server/controllers/wazuh-api.js | 51 ++-------------- server/controllers/wazuh-elastic.js | 10 ++-- server/controllers/wazuh-utils.js | 66 +++++++++++++++++++++ server/routes/wazuh-api-elastic.js | 12 ++-- server/routes/wazuh-api.js | 42 +++---------- server/routes/wazuh-elastic.js | 18 +++--- server/routes/wazuh-reporting.js | 8 +-- server/routes/wazuh-utils.js | 43 ++++++++++++++ test/server/wazuh-api-elastic.js | 34 +++++------ test/server/wazuh-api.js | 42 ++++++------- test/server/wazuh-elastic.js | 34 +++++------ 33 files changed, 250 insertions(+), 206 deletions(-) create mode 100644 server/controllers/wazuh-utils.js create mode 100644 server/routes/wazuh-utils.js diff --git a/init.js b/init.js index b7845ff6ca..bebc06c361 100644 --- a/init.js +++ b/init.js @@ -17,6 +17,7 @@ import { WazuhApiElasticRoutes } from './server/routes/wazuh-api-elastic'; import { Monitoring } from './server/monitoring'; import { WazuhApiRoutes } from './server/routes/wazuh-api'; import { WazuhReportingRoutes } from './server/routes/wazuh-reporting'; +import { WazuhUtilsRoutes } from './server/routes/wazuh-utils'; export function initApp(server) { Initialize(server); @@ -25,4 +26,5 @@ export function initApp(server) { Monitoring(server, false); WazuhApiRoutes(server); WazuhReportingRoutes(server); + WazuhUtilsRoutes(server); } diff --git a/public/controllers/agent/agents-preview.js b/public/controllers/agent/agents-preview.js index e00b8b4af0..655733de85 100644 --- a/public/controllers/agent/agents-preview.js +++ b/public/controllers/agent/agents-preview.js @@ -127,12 +127,12 @@ class AgentsPreviewController { const data = await Promise.all([ this.genericReq.request( 'GET', - '/api/wazuh-api/agents-unique/' + api, + '/api/agents-unique/' + api, {} ), this.genericReq.request( 'GET', - `/api/wazuh-elastic/top/${firstUrlParam}/${secondUrlParam}/agent.name/${pattern}` + `/elastic/top/${firstUrlParam}/${secondUrlParam}/agent.name/${pattern}` ) ]); const [agentsUnique, agentsTop] = data; @@ -158,7 +158,7 @@ class AgentsPreviewController { this.$scope.mostActiveAgent.name = agentsTop.data.data; const info = await this.genericReq.request( 'GET', - `/api/wazuh-elastic/top/${firstUrlParam}/${secondUrlParam}/agent.id/${pattern}` + `/elastic/top/${firstUrlParam}/${secondUrlParam}/agent.id/${pattern}` ); if (info.data.data === '' && this.$scope.mostActiveAgent.name !== '') { this.$scope.mostActiveAgent.id = '000'; diff --git a/public/controllers/management/monitoring.js b/public/controllers/management/monitoring.js index 3657a08dc6..5ea1e6ce79 100644 --- a/public/controllers/management/monitoring.js +++ b/public/controllers/management/monitoring.js @@ -248,7 +248,7 @@ app.controller('clusterController', function( const visData = await genericReq.request( 'POST', - `/api/wazuh-elastic/create-vis/cluster-monitoring/${appState.getCurrentPattern()}`, + `/elastic/visualizations/cluster-monitoring/${appState.getCurrentPattern()}`, { nodes } ); diff --git a/public/controllers/misc/health-check.js b/public/controllers/misc/health-check.js index 425b60f544..6cf949ad37 100644 --- a/public/controllers/misc/health-check.js +++ b/public/controllers/misc/health-check.js @@ -74,7 +74,7 @@ class HealthCheck { const i = this.$scope.results.map(item => item.id).indexOf(2); const patternData = await this.genericReq.request( 'GET', - `/api/wazuh-elastic/pattern/${patternTitle}` + `/elastic/index-patterns/${patternTitle}` ); if (!patternData.data.status) { this.$scope.errors.push('The selected index-pattern is not present.'); @@ -89,7 +89,7 @@ class HealthCheck { const i = this.$scope.results.map(item => item.id).indexOf(3); const templateData = await this.genericReq.request( 'GET', - `/api/wazuh-elastic/template/${patternTitle}` + `/elastic/template/${patternTitle}` ); if (!templateData.data.status) { this.$scope.errors.push( @@ -136,7 +136,7 @@ class HealthCheck { const apiVersion = versionData.data.data; const setupData = await this.genericReq.request( 'GET', - '/api/wazuh-elastic/setup' + '/elastic/setup' ); if (!setupData.data.data['app-version'] || !apiVersion) { this.errorHandler.handle( diff --git a/public/controllers/misc/reporting.js b/public/controllers/misc/reporting.js index 4cced28861..3ac53d8a11 100644 --- a/public/controllers/misc/reporting.js +++ b/public/controllers/misc/reporting.js @@ -49,7 +49,7 @@ class ReportingController { this.$scope.loading = true; await this.genericReq.request( 'DELETE', - '/api/wazuh-reporting/report/' + name, + '/reports/' + name, {} ); await this.load(); @@ -110,7 +110,7 @@ class ReportingController { this.$scope.loading = true; const data = await this.genericReq.request( 'GET', - '/api/wazuh-reporting/reports', + '/reports', {} ); this.items = data.data.list; diff --git a/public/controllers/settings/index.js b/public/controllers/settings/index.js index 9a5fc2cec0..c4d990c6d1 100644 --- a/public/controllers/settings/index.js +++ b/public/controllers/settings/index.js @@ -82,7 +82,7 @@ app.controller('settingsController', function( } await genericReq.request( 'DELETE', - `/api/wazuh-api/apiEntries/${$scope.apiEntries[index]._id}` + `/elastic/apis/${$scope.apiEntries[index]._id}` ); $scope.showEditForm[$scope.apiEntries[index]._id] = false; $scope.apiEntries.splice(index, 1); @@ -166,7 +166,7 @@ app.controller('settingsController', function( // Get settings function const getSettings = async () => { try { - const patternList = await genericReq.request('GET', '/get-list', {}); + const patternList = await genericReq.request('GET', '/elastic/index-patterns', {}); $scope.indexPatterns = patternList.data.data; if (!patternList.data.data.length) { @@ -175,7 +175,7 @@ app.controller('settingsController', function( $location.path('/blank-screen'); return; } - const data = await genericReq.request('GET', '/api/wazuh-api/apiEntries'); + const data = await genericReq.request('GET', '/elastic/apis'); for (const entry of data.data) $scope.showEditForm[entry._id] = false; $scope.apiEntries = data.data.length > 0 ? data.data : []; @@ -297,7 +297,7 @@ app.controller('settingsController', function( // Insert new API entry const data = await genericReq.request( 'PUT', - '/api/wazuh-api/settings', + '/elastic/api', tmpData ); appState.setExtensions(data.data.response._id, tmpData.extensions); @@ -350,7 +350,7 @@ app.controller('settingsController', function( } try { - await genericReq.request('GET', '/api/wazuh-api/fetchAgents'); + await genericReq.request('GET', '/api/monitoring'); } catch (error) { if (error && error.status && error.status === -1) { errorHandler.handle( @@ -412,7 +412,7 @@ app.controller('settingsController', function( tmpData.cluster_info = data.data; await genericReq.request( 'PUT', - '/api/wazuh-api/update-settings', + '/elastic/api-settings', tmpData ); $scope.apiEntries[index]._source.cluster_info = tmpData.cluster_info; @@ -461,7 +461,7 @@ app.controller('settingsController', function( const data = await testAPI.check(tmpData); tmpData.cluster_info = data.data; - const tmpUrl = `/api/wazuh-api/updateApiHostname/${ + const tmpUrl = `/elastic/api-hostname/${ $scope.apiEntries[index]._id }`; await genericReq.request('PUT', tmpUrl, { @@ -501,7 +501,7 @@ app.controller('settingsController', function( $scope.changeIndexPattern = async newIndexPattern => { try { appState.setCurrentPattern(newIndexPattern); - await genericReq.request('GET', `/refresh-fields/${newIndexPattern}`, {}); + await genericReq.request('GET', `/elastic/known-fields/${newIndexPattern}`, {}); $scope.$emit('updatePattern', {}); errorHandler.info( 'Successfully changed the default index-pattern', @@ -528,7 +528,7 @@ app.controller('settingsController', function( const getAppLogs = async () => { try { $scope.loadingLogs = true; - const logs = await genericReq.request('GET', '/api/wazuh-api/logs', {}); + const logs = await genericReq.request('GET', '/utils/logs', {}); $scope.logs = logs.data.lastLogs.map(item => JSON.parse(item)); $scope.loadingLogs = false; if (!$scope.$$phase) $scope.$digest(); @@ -545,7 +545,7 @@ app.controller('settingsController', function( const getAppInfo = async () => { try { - const data = await genericReq.request('GET', '/api/wazuh-elastic/setup'); + const data = await genericReq.request('GET', '/elastic/setup'); $scope.appInfo = {}; $scope.appInfo['app-version'] = data.data.data['app-version']; $scope.appInfo['installationDate'] = data.data.data['installationDate']; diff --git a/public/directives/wz-menu/wz-menu.js b/public/directives/wz-menu/wz-menu.js index 2186d3b612..7e100f9cfa 100644 --- a/public/directives/wz-menu/wz-menu.js +++ b/public/directives/wz-menu/wz-menu.js @@ -62,7 +62,7 @@ class WzMenu { let filtered = false; // If there is no current pattern, fetch it if (!appState.getCurrentPattern()) { - const currentPattern = await genericReq.request('GET', '/get-list'); + const currentPattern = await genericReq.request('GET', '/elastic/index-patterns'); if (!currentPattern.data.data.length) { wzMisc.setBlankScr('Sorry but no valid index patterns were found'); $location.search('tab', null); @@ -72,7 +72,7 @@ class WzMenu { appState.setCurrentPattern(currentPattern.data.data[0].id); } else { // If there is current pattern, check if there is some pattern - const patternList = await genericReq.request('GET', '/get-list'); + const patternList = await genericReq.request('GET', '/elastic/index-patterns'); if (!patternList.data.data.length) { wzMisc.setBlankScr('Sorry but no valid index patterns were found'); diff --git a/public/services/api-request.js b/public/services/api-request.js index a343e30c87..3e35815270 100644 --- a/public/services/api-request.js +++ b/public/services/api-request.js @@ -31,7 +31,7 @@ export class ApiRequest { const data = await this.genericReq.request( 'POST', - '/api/wazuh-api/request', + '/api/request', requestData ); diff --git a/public/services/api-tester.js b/public/services/api-tester.js index efd805a602..77b55f86a3 100644 --- a/public/services/api-tester.js +++ b/public/services/api-tester.js @@ -45,7 +45,7 @@ export class ApiTester { /** End of checks for outdated cookies */ } else { const result = await this.$http.post( - chrome.addBasePath('/api/wazuh-api/checkStoredAPI'), + chrome.addBasePath('/api/check-stored-api'), data, headers ); @@ -74,7 +74,7 @@ export class ApiTester { timeout: timeout || 8000 }; - const url = chrome.addBasePath('/api/wazuh-api/checkAPI'); + const url = chrome.addBasePath('/api/check-api'); const response = await this.$http.post(url, data, headers); if (response.error) { diff --git a/public/services/common-data.js b/public/services/common-data.js index 925798a66b..83d3e145c1 100644 --- a/public/services/common-data.js +++ b/public/services/common-data.js @@ -145,7 +145,7 @@ export class CommonData { const gdprTabs = []; const data = await this.genericReq.request( 'GET', - '/api/wazuh-api/gdpr/all' + '/api/gdpr/all' ); if (!data.data) return []; for (const key in data.data) { @@ -162,7 +162,7 @@ export class CommonData { const pciTabs = []; const data = await this.genericReq.request( 'GET', - '/api/wazuh-api/pci/all' + '/api/pci/all' ); if (!data.data) return []; for (const key in data.data) { diff --git a/public/services/csv-request.js b/public/services/csv-request.js index 6c4d868a00..b980bd50e5 100644 --- a/public/services/csv-request.js +++ b/public/services/csv-request.js @@ -19,7 +19,7 @@ export class CSVRequest { } /** - * It fetchs data from /api/wazuh-api/csv route using the below parameters. + * It fetchs data from /api/csv route using the below parameters. * @param {string} path Wazuh API route * @param {number|string} id Elasticsearch document ID * @param {*} filters Array of Wazuh API filters. Optional @@ -28,7 +28,7 @@ export class CSVRequest { try { const output = await this.genericReq.request( 'POST', - '/api/wazuh-api/csv', + '/api/csv', { path, id, filters } ); return output.data; diff --git a/public/services/pattern-handler.js b/public/services/pattern-handler.js index 9d2cde63b4..f3a5206c31 100644 --- a/public/services/pattern-handler.js +++ b/public/services/pattern-handler.js @@ -20,7 +20,7 @@ export class PatternHandler { async getPatternList() { try { - const patternList = await this.genericReq.request('GET', '/get-list', {}); + const patternList = await this.genericReq.request('GET', '/elastic/index-patterns', {}); if (!patternList.data.data.length) { this.wzMisc.setBlankScr('Sorry but no valid index patterns were found'); @@ -49,7 +49,7 @@ export class PatternHandler { this.appState.setCurrentPattern(selectedPattern); await this.genericReq.request( 'GET', - `/refresh-fields/${selectedPattern}`, + `/elastic/known-fields/${selectedPattern}`, {} ); return this.appState.getCurrentPattern(); diff --git a/public/services/reporting.js b/public/services/reporting.js index 24b191edff..a7edf9927f 100644 --- a/public/services/reporting.js +++ b/public/services/reporting.js @@ -72,7 +72,7 @@ export class ReportingService { await this.genericReq.request( 'POST', - '/api/wazuh-reporting/report', + '/reports', data ); diff --git a/public/services/resolves/check-ram.js b/public/services/resolves/check-ram.js index 70263d743d..1c30ee8808 100644 --- a/public/services/resolves/check-ram.js +++ b/public/services/resolves/check-ram.js @@ -11,7 +11,7 @@ */ export async function totalRAM(genericReq, errorHandler) { try { - const data = await genericReq.request('GET', '/api/wazuh-api/ram'); + const data = await genericReq.request('GET', '/utils/memory'); const totalRAM = data.data.ram; if (totalRAM < 3072 && totalRAM > 2048) { errorHandler.handle( diff --git a/public/services/resolves/check-timestamp.js b/public/services/resolves/check-timestamp.js index 23a2371899..09e85879b1 100644 --- a/public/services/resolves/check-timestamp.js +++ b/public/services/resolves/check-timestamp.js @@ -13,7 +13,7 @@ export async function checkTimestamp(appState, genericReq, $location, wzMisc) { try { const data = await genericReq.request( 'GET', - '/api/wazuh-elastic/timestamp' + '/elastic/timestamp' ); const current = appState.getCreatedAt(); if (data && data.data) { diff --git a/public/services/resolves/get-config.js b/public/services/resolves/get-config.js index 736cdf97c8..c9c101a2f9 100644 --- a/public/services/resolves/get-config.js +++ b/public/services/resolves/get-config.js @@ -41,7 +41,7 @@ export async function getWzConfig($q, genericReq, errorHandler, wazuhConfig) { try { const config = await genericReq.request( 'GET', - '/api/wazuh-api/configuration', + '/utils/configuration', {} ); diff --git a/public/services/resolves/get-ip.js b/public/services/resolves/get-ip.js index 9c523ec68e..2c9862032a 100644 --- a/public/services/resolves/get-ip.js +++ b/public/services/resolves/get-ip.js @@ -39,7 +39,7 @@ export function getIp( const { savedObjects } = savedObjectsData; - const data = await genericReq.request('GET', '/get-list'); + const data = await genericReq.request('GET', '/elastic/index-patterns'); let currentPattern = ''; diff --git a/public/services/resolves/settings-wizard.js b/public/services/resolves/settings-wizard.js index bba009e8f2..cca4688d57 100644 --- a/public/services/resolves/settings-wizard.js +++ b/public/services/resolves/settings-wizard.js @@ -183,7 +183,7 @@ export function settingsWizard( // There's no cookie for current API if (!appState.getCurrentAPI()) { genericReq - .request('GET', '/api/wazuh-api/apiEntries') + .request('GET', '/elastic/apis') .then(data => { if (data.data.length > 0) { const apiEntries = data.data; diff --git a/public/services/vis-factory-handler.js b/public/services/vis-factory-handler.js index d635411435..2b67ca4b94 100644 --- a/public/services/vis-factory-handler.js +++ b/public/services/vis-factory-handler.js @@ -48,7 +48,7 @@ export class VisFactoryService { try { const data = await this.genericReq.request( 'GET', - `/api/wazuh-elastic/create-vis/overview-${tab}/${this.appState.getCurrentPattern()}` + `/elastic/visualizations/overview-${tab}/${this.appState.getCurrentPattern()}` ); this.rawVisualizations.assignItems(data.data.raw); this.commonData.assignFilters(filterHandler, tab, localChange); @@ -64,7 +64,7 @@ export class VisFactoryService { try { const data = await this.genericReq.request( 'GET', - `/api/wazuh-elastic/create-vis/agents-${tab}/${this.appState.getCurrentPattern()}` + `/elastic/visualizations/agents-${tab}/${this.appState.getCurrentPattern()}` ); this.rawVisualizations.assignItems(data.data.raw); this.commonData.assignFilters(filterHandler, tab, localChange, id); diff --git a/public/templates/management/reporting.html b/public/templates/management/reporting.html index 9d8286bf99..fd674fd77f 100644 --- a/public/templates/management/reporting.html +++ b/public/templates/management/reporting.html @@ -47,7 +47,7 @@ {{item.size / 1024 | number: 2}}KB {{item.date.split('T')[0]}} {{item.date.split('T')[1].split('.')[0]}} - + diff --git a/server/controllers/index.js b/server/controllers/index.js index 8f0d786c98..c5c7fd7623 100644 --- a/server/controllers/index.js +++ b/server/controllers/index.js @@ -13,10 +13,12 @@ import { WazuhElasticCtrl } from './wazuh-elastic'; import { WazuhApiElasticCtrl } from './wazuh-api-elastic'; import { WazuhApiCtrl } from './wazuh-api'; import { WazuhReportingCtrl } from './wazuh-reporting'; +import { WazuhUtilsCtrl } from './wazuh-utils'; export { WazuhElasticCtrl, WazuhApiElasticCtrl, WazuhApiCtrl, - WazuhReportingCtrl + WazuhReportingCtrl, + WazuhUtilsCtrl }; diff --git a/server/controllers/wazuh-api-elastic.js b/server/controllers/wazuh-api-elastic.js index 67a8ea732a..cb79c47a7a 100644 --- a/server/controllers/wazuh-api-elastic.js +++ b/server/controllers/wazuh-api-elastic.js @@ -49,7 +49,7 @@ export class WazuhApiElasticCtrl { return reply(result); } catch (error) { - log('GET /api/wazuh-api/apiEntries', error.message || error); + log('GET /elastic/apis', error.message || error); return ErrorResponse(error.message || error, 2001, 500, reply); } } @@ -60,7 +60,7 @@ export class WazuhApiElasticCtrl { return reply(data); } catch (error) { - log('DELETE /api/wazuh-api/apiEntries/{id}', error.message || error); + log('DELETE /elastic/apis/{id}', error.message || error); return ErrorResponse(error.message || error, 2002, 500, reply); } } @@ -82,7 +82,7 @@ export class WazuhApiElasticCtrl { return reply({ statusCode: 200, message: 'ok' }); } catch (error) { - log('PUT /api/wazuh-api/apiEntries/{id}', error.message || error); + log('PUT /elastic/apis/{id}', error.message || error); return ErrorResponse( `Could not save data in elasticsearch due to ${error.message || error}`, 2003, @@ -158,7 +158,7 @@ export class WazuhApiElasticCtrl { return reply({ statusCode: 200, message: 'ok', response }); } catch (error) { - log('PUT /api/wazuh-api/settings', error.message || error); + log('PUT /elastic/api', error.message || error); return ErrorResponse( `Could not save data in elasticsearch due to ${error.message || error}`, 2011, @@ -176,7 +176,7 @@ export class WazuhApiElasticCtrl { return reply({ statusCode: 200, message: 'ok' }); } catch (error) { - log('PUT /api/wazuh-api/updateApiHostname/{id}', error.message || error); + log('PUT /elastic/api-hostname/{id}', error.message || error); return ErrorResponse( `Could not save data in elasticsearch due to ${error.message || error}`, 2012, @@ -206,7 +206,7 @@ export class WazuhApiElasticCtrl { return reply({ statusCode: 200, message: 'ok' }); } catch (error) { - log('PUT /api/wazuh-api/update-settings', error.message || error); + log('PUT /elastic/api-settings', error.message || error); return ErrorResponse( `Could not save data in elasticsearch due to ${error.message || error}`, 2014, diff --git a/server/controllers/wazuh-api.js b/server/controllers/wazuh-api.js index 111ec9464e..8d08cc0891 100644 --- a/server/controllers/wazuh-api.js +++ b/server/controllers/wazuh-api.js @@ -157,7 +157,7 @@ export class WazuhApiCtrl { } } catch (error) { if (error.code === 'ECONNREFUSED') { - log('POST /api/wazuh-api/checkStoredAPI', error.message || error); + log('POST /api/check-stored-api', error.message || error); return reply({ statusCode: 200, data: { password: '****', apiIsDown: true } @@ -203,11 +203,11 @@ export class WazuhApiCtrl { } catch (error) {} // eslint-disable-line } } catch (error) { - log('POST /api/wazuh-api/checkStoredAPI', error.message || error); + log('POST /api/check-stored-api', error.message || error); return ErrorResponse(error.message || error, 3020, 500, reply); } } - log('POST /api/wazuh-api/checkStoredAPI', error.message || error); + log('POST /api/check-stored-api', error.message || error); return ErrorResponse(error.message || error, 3002, 500, reply); } } @@ -362,7 +362,7 @@ export class WazuhApiCtrl { throw new Error(tmpMsg); } catch (error) { - log('POST /api/wazuh-api/checkAPI', error.message || error); + log('POST /api/check-api', error.message || error); return ErrorResponse(error.message || error, 3005, 500, reply); } } @@ -714,20 +714,6 @@ export class WazuhApiCtrl { } } - getConfigurationFile(req, reply) { - try { - const configFile = getConfiguration(); - - return reply({ - statusCode: 200, - error: 0, - data: configFile || {} - }); - } catch (error) { - return ErrorResponse(error.message || error, 3019, 500, reply); - } - } - /** * Get full data on CSV format from a list Wazuh API endpoint * @param {*} req @@ -836,16 +822,6 @@ export class WazuhApiCtrl { } } - async totalRam(req, reply) { - try { - // RAM in MB - const ram = Math.ceil(totalmem() / 1024 / 1024); - return reply({ statusCode: 200, error: 0, ram }); - } catch (error) { - return ErrorResponse(error.message || error, 3033, 500, reply); - } - } - async getAgentsFieldsUniqueCount(req, reply) { try { if (!req.params || !req.params.api) @@ -1009,23 +985,4 @@ export class WazuhApiCtrl { return ErrorResponse(error.message || error, 3035, 500, reply); } } - - async getAppLogs(req, reply) { - try { - const lastLogs = await simpleTail( - path.join(__dirname, '../../../../optimize/wazuh-logs/wazuhapp.log'), - 20 - ); - return lastLogs && Array.isArray(lastLogs) - ? reply({ - error: 0, - lastLogs: lastLogs.filter( - item => typeof item === 'string' && item.length - ) - }) - : reply({ error: 0, lastLogs: [] }); - } catch (error) { - return ErrorResponse(error.message || error, 3036, 500, reply); - } - } } diff --git a/server/controllers/wazuh-elastic.js b/server/controllers/wazuh-elastic.js index 632e28c298..2a579c5ce4 100644 --- a/server/controllers/wazuh-elastic.js +++ b/server/controllers/wazuh-elastic.js @@ -88,7 +88,7 @@ export class WazuhElasticCtrl { data: `No template found for ${req.params.pattern}` }); } catch (error) { - log('GET /api/wazuh-elastic/template/{pattern}', error.message || error); + log('GET /elastic/template/{pattern}', error.message || error); return ErrorResponse( `Could not retrieve templates from Elasticsearch due to ${error.message || error}`, @@ -116,7 +116,7 @@ export class WazuhElasticCtrl { message: 'Index pattern not found' }); } catch (error) { - log('GET /api/wazuh-elastic/pattern/{pattern}', error.message || error); + log('GET /elastic/index-patterns/{pattern}', error.message || error); return ErrorResponse( `Something went wrong retrieving index-patterns from Elasticsearch due to ${error.message || error}`, @@ -186,7 +186,7 @@ export class WazuhElasticCtrl { ? reply({ statusCode: 200, data: '' }) : reply({ statusCode: 200, data: data.hits.hits[0]._source }); } catch (error) { - log('GET /api/wazuh-elastic/setup', error.message || error); + log('GET /elastic/setup', error.message || error); return ErrorResponse( `Could not get data from elasticsearch due to ${error.message || error}`, @@ -289,7 +289,7 @@ export class WazuhElasticCtrl { "The Elasticsearch request didn't fetch the expected data" ); } catch (error) { - log('GET /get-list', error.message || error); + log('GET /elastic/index-patterns', error.message || error); return ErrorResponse(error.message || error, 4006, 500, reply); } } @@ -470,7 +470,7 @@ export class WazuhElasticCtrl { return reply({ acknowledge: true, output: output }); } catch (error) { - log('GET /refresh-fields/{pattern}', error.message || error); + log('GET /elastic/known-fields/{pattern}', error.message || error); return ErrorResponse(error.message || error, 4008, 500, reply); } } diff --git a/server/controllers/wazuh-utils.js b/server/controllers/wazuh-utils.js new file mode 100644 index 0000000000..ac1a61faec --- /dev/null +++ b/server/controllers/wazuh-utils.js @@ -0,0 +1,66 @@ +/* + * Wazuh app - Class for Wazuh-API functions + * Copyright (C) 2018 Wazuh, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Find more information about this on the LICENSE file. + */ + +// Require some libraries +import { ErrorResponse } from './error-response'; +import { getConfiguration } from '../lib/get-configuration'; +import { totalmem } from 'os'; +import simpleTail from 'simple-tail'; +import path from 'path'; + +export class WazuhUtilsCtrl { + constructor() { + } + + getConfigurationFile(req, reply) { + try { + const configFile = getConfiguration(); + + return reply({ + statusCode: 200, + error: 0, + data: configFile || {} + }); + } catch (error) { + return ErrorResponse(error.message || error, 3019, 500, reply); + } + } + + async totalRam(req, reply) { + try { + // RAM in MB + const ram = Math.ceil(totalmem() / 1024 / 1024); + return reply({ statusCode: 200, error: 0, ram }); + } catch (error) { + return ErrorResponse(error.message || error, 3033, 500, reply); + } + } + + async getAppLogs(req, reply) { + try { + const lastLogs = await simpleTail( + path.join(__dirname, '../../../../optimize/wazuh-logs/wazuhapp.log'), + 20 + ); + return lastLogs && Array.isArray(lastLogs) + ? reply({ + error: 0, + lastLogs: lastLogs.filter( + item => typeof item === 'string' && item.length + ) + }) + : reply({ error: 0, lastLogs: [] }); + } catch (error) { + return ErrorResponse(error.message || error, 3036, 500, reply); + } + } +} diff --git a/server/routes/wazuh-api-elastic.js b/server/routes/wazuh-api-elastic.js index f1cdaddd05..3cbc3cdc70 100644 --- a/server/routes/wazuh-api-elastic.js +++ b/server/routes/wazuh-api-elastic.js @@ -17,7 +17,7 @@ export function WazuhApiElasticRoutes(server) { // Save the given API into elasticsearch server.route({ method: 'PUT', - path: '/api/wazuh-api/settings', + path: '/elastic/api', handler(req, reply) { return ctrl.saveAPI(req, reply); } @@ -26,7 +26,7 @@ export function WazuhApiElasticRoutes(server) { // Update the given API into elasticsearch server.route({ method: 'PUT', - path: '/api/wazuh-api/update-settings', + path: '/elastic/api-settings', handler(req, reply) { return ctrl.updateFullAPI(req, reply); } @@ -35,7 +35,7 @@ export function WazuhApiElasticRoutes(server) { // Get Wazuh-API entries list (Multimanager) from elasticsearch index server.route({ method: 'GET', - path: '/api/wazuh-api/apiEntries', + path: '/elastic/apis', handler(req, reply) { return ctrl.getAPIEntries(req, reply); } @@ -44,7 +44,7 @@ export function WazuhApiElasticRoutes(server) { // Delete Wazuh-API entry (multimanager) from elasticsearch index server.route({ method: 'DELETE', - path: '/api/wazuh-api/apiEntries/{id}', + path: '/elastic/apis/{id}', handler(req, reply) { return ctrl.deleteAPIEntries(req, reply); } @@ -53,7 +53,7 @@ export function WazuhApiElasticRoutes(server) { // Set Wazuh-API as default (multimanager) on elasticsearch index server.route({ method: 'PUT', - path: '/api/wazuh-api/apiEntries/{id}', + path: '/elastic/apis/{id}', handler(req, reply) { return ctrl.setAPIEntryDefault(req, reply); } @@ -62,7 +62,7 @@ export function WazuhApiElasticRoutes(server) { // Update the API hostname server.route({ method: 'PUT', - path: '/api/wazuh-api/updateApiHostname/{id}', + path: '/elastic/api-hostname/{id}', handler(req, reply) { return ctrl.updateAPIHostname(req, reply); } diff --git a/server/routes/wazuh-api.js b/server/routes/wazuh-api.js index b346bdded9..c254d36aa7 100644 --- a/server/routes/wazuh-api.js +++ b/server/routes/wazuh-api.js @@ -17,7 +17,7 @@ export function WazuhApiRoutes(server) { // Returns if the wazuh-api configuration is working server.route({ method: 'POST', - path: '/api/wazuh-api/checkStoredAPI', + path: '/api/check-stored-api', handler(req, reply) { return ctrl.checkStoredAPI(req, reply); } @@ -27,7 +27,7 @@ export function WazuhApiRoutes(server) { // Returns if the wazuh-api configuration received in the POST body will work server.route({ method: 'POST', - path: '/api/wazuh-api/checkAPI', + path: '/api/check-api', handler(req, reply) { return ctrl.checkAPI(req, reply); } @@ -36,7 +36,7 @@ export function WazuhApiRoutes(server) { // Returns the request result (With error control) server.route({ method: 'POST', - path: '/api/wazuh-api/request', + path: '/api/request', handler(req, reply) { return ctrl.requestApi(req, reply); } @@ -45,7 +45,7 @@ export function WazuhApiRoutes(server) { // Return a PCI requirement description server.route({ method: 'GET', - path: '/api/wazuh-api/pci/{requirement}', + path: '/api/pci/{requirement}', handler(req, reply) { return ctrl.getPciRequirement(req, reply); } @@ -54,7 +54,7 @@ export function WazuhApiRoutes(server) { // Return a GDPR requirement description server.route({ method: 'GET', - path: '/api/wazuh-api/gdpr/{requirement}', + path: '/api/gdpr/{requirement}', handler(req, reply) { return ctrl.getGdprRequirement(req, reply); } @@ -63,54 +63,28 @@ export function WazuhApiRoutes(server) { // Force fetch data to be inserted on wazuh-monitoring indices server.route({ method: 'GET', - path: '/api/wazuh-api/fetchAgents', + path: '/api/monitoring', handler(req, reply) { return ctrl.fetchAgents(req, reply); } }); - // Returns the config.yml file parsed - server.route({ - method: 'GET', - path: '/api/wazuh-api/configuration', - handler(req, reply) { - return ctrl.getConfigurationFile(req, reply); - } - }); - // Returns data from the Wazuh API on CSV readable format server.route({ method: 'POST', - path: '/api/wazuh-api/csv', + path: '/api/csv', handler(req, res) { return ctrl.csv(req, res); } }); - // Returns total RAM available from the current machine where Kibana is being executed - server.route({ - method: 'GET', - path: '/api/wazuh-api/ram', - handler(req, res) { - return ctrl.totalRam(req, res); - } - }); - // Returns unique fields from the agents such OS, agent version ... server.route({ method: 'GET', - path: '/api/wazuh-api/agents-unique/{api}', + path: '/api/agents-unique/{api}', handler(req, res) { return ctrl.getAgentsFieldsUniqueCount(req, res); } }); - // Returns Wazuh app logs ... - server.route({ - method: 'GET', - path: '/api/wazuh-api/logs', - handler(req, res) { - return ctrl.getAppLogs(req, res); - } - }); } diff --git a/server/routes/wazuh-elastic.js b/server/routes/wazuh-elastic.js index 2f267ad51d..6f5bbd7362 100644 --- a/server/routes/wazuh-elastic.js +++ b/server/routes/wazuh-elastic.js @@ -17,7 +17,7 @@ export function WazuhElasticRouter(server) { // Get index patterns list server.route({ method: 'GET', - path: '/get-list', + path: '/elastic/index-patterns', handler(req, res) { return ctrl.getlist(req, res); } @@ -26,7 +26,7 @@ export function WazuhElasticRouter(server) { // Refresh known fields for specific index pattern server.route({ method: 'GET', - path: '/refresh-fields/{pattern}', + path: '/elastic/known-fields/{pattern}', handler(req, res) { return ctrl.refreshIndex(req, res); } @@ -35,14 +35,14 @@ export function WazuhElasticRouter(server) { // Create visualizations specified in 'tab' parameter and applying to 'pattern' server.route({ method: 'GET', - path: '/api/wazuh-elastic/create-vis/{tab}/{pattern}', + path: '/elastic/visualizations/{tab}/{pattern}', handler(req, res) { return ctrl.createVis(req, res); } }); server.route({ method: 'POST', - path: '/api/wazuh-elastic/create-vis/{tab}/{pattern}', + path: '/elastic/visualizations/{tab}/{pattern}', handler(req, res) { return ctrl.createClusterVis(req, res); } @@ -51,7 +51,7 @@ export function WazuhElasticRouter(server) { // Returns whether a correct template is being applied for the index-pattern server.route({ method: 'GET', - path: '/api/wazuh-elastic/template/{pattern}', + path: '/elastic/template/{pattern}', handler(req, res) { return ctrl.getTemplate(req, res); } @@ -60,7 +60,7 @@ export function WazuhElasticRouter(server) { // Returns whether the pattern exists or not server.route({ method: 'GET', - path: '/api/wazuh-elastic/pattern/{pattern}', + path: '/elastic/index-patterns/{pattern}', handler(req, res) { return ctrl.checkPattern(req, res); } @@ -69,7 +69,7 @@ export function WazuhElasticRouter(server) { // Returns the agent with most alerts server.route({ method: 'GET', - path: '/api/wazuh-elastic/top/{mode}/{cluster}/{field}/{pattern}', + path: '/elastic/top/{mode}/{cluster}/{field}/{pattern}', handler(req, res) { return ctrl.getFieldTop(req, res); } @@ -78,7 +78,7 @@ export function WazuhElasticRouter(server) { // Return Wazuh Appsetup info server.route({ method: 'GET', - path: '/api/wazuh-elastic/setup', + path: '/elastic/setup', handler(req, res) { return ctrl.getSetupInfo(req, res); } @@ -87,7 +87,7 @@ export function WazuhElasticRouter(server) { // Useful to check cookie consistence server.route({ method: 'GET', - path: '/api/wazuh-elastic/timestamp', + path: '/elastic/timestamp', handler(req, res) { return ctrl.getTimeStamp(req, res); } diff --git a/server/routes/wazuh-reporting.js b/server/routes/wazuh-reporting.js index 7263c4ae18..9bc7b15717 100644 --- a/server/routes/wazuh-reporting.js +++ b/server/routes/wazuh-reporting.js @@ -17,7 +17,7 @@ export function WazuhReportingRoutes(server) { // Builds a PDF report from multiple PNG images server.route({ method: 'POST', - path: '/api/wazuh-reporting/report', + path: '/reports', handler(req, res) { return ctrl.report(req, res); } @@ -26,7 +26,7 @@ export function WazuhReportingRoutes(server) { // Fetch specific report server.route({ method: 'GET', - path: '/api/wazuh-reporting/report/{name}', + path: '/reports/{name}', handler(req, res) { return ctrl.getReportByName(req, res); } @@ -35,7 +35,7 @@ export function WazuhReportingRoutes(server) { // Delete specific report server.route({ method: 'DELETE', - path: '/api/wazuh-reporting/report/{name}', + path: '/reports/{name}', handler(req, res) { return ctrl.deleteReportByName(req, res); } @@ -44,7 +44,7 @@ export function WazuhReportingRoutes(server) { // Fetch the reports list server.route({ method: 'GET', - path: '/api/wazuh-reporting/reports', + path: '/reports', handler(req, res) { return ctrl.getReports(req, res); } diff --git a/server/routes/wazuh-utils.js b/server/routes/wazuh-utils.js new file mode 100644 index 0000000000..d1602a2b42 --- /dev/null +++ b/server/routes/wazuh-utils.js @@ -0,0 +1,43 @@ +/* + * Wazuh app - Module for Wazuh utils routes + * Copyright (C) 2018 Wazuh, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Find more information about this on the LICENSE file. + */ +import { WazuhUtilsCtrl } from '../controllers'; + +export function WazuhUtilsRoutes(server) { + const ctrl = new WazuhUtilsCtrl(); + + // Returns the config.yml file parsed + server.route({ + method: 'GET', + path: '/utils/configuration', + handler(req, reply) { + return ctrl.getConfigurationFile(req, reply); + } + }); + + // Returns total RAM available from the current machine where Kibana is being executed + server.route({ + method: 'GET', + path: '/utils/memory', + handler(req, res) { + return ctrl.totalRam(req, res); + } + }); + + // Returns Wazuh app logs ... + server.route({ + method: 'GET', + path: '/utils/logs', + handler(req, res) { + return ctrl.getAppLogs(req, res); + } + }); +} diff --git a/test/server/wazuh-api-elastic.js b/test/server/wazuh-api-elastic.js index 3f711e67f6..1c44c05b64 100644 --- a/test/server/wazuh-api-elastic.js +++ b/test/server/wazuh-api-elastic.js @@ -13,7 +13,7 @@ describe('wazuh-api-elastic', () => { before(async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/apiEntries`, + `localhost:5601/elastic/apis`, {}, {} ); @@ -26,10 +26,10 @@ describe('wazuh-api-elastic', () => { API_ID = res.body[0]._id; }); - it('PUT /api/wazuh-api/settings', async () => { + it('PUT /elastic/api', async () => { const res = await needle( 'put', - `localhost:5601/api/wazuh-api/settings`, + `localhost:5601/elastic/api`, { user: 'foo', password: 'bar', @@ -46,17 +46,17 @@ describe('wazuh-api-elastic', () => { res.body.response.result.should.be.eql('created'); const removed = await needle( 'delete', - `localhost:5601/api/wazuh-api/apiEntries/${res.body.response._id}`, + `localhost:5601/elastic/apis/${res.body.response._id}`, {}, headers ); removed.body.result.should.be.eql('deleted'); }); - it('PUT /api/wazuh-api/update-settings', async () => { + it('PUT /elastic/api-settings', async () => { const res = await needle( 'put', - `localhost:5601/api/wazuh-api/settings`, + `localhost:5601/elastic/api`, { user: 'foo', password: 'bar', @@ -72,7 +72,7 @@ describe('wazuh-api-elastic', () => { ); const updated = await needle( 'put', - `localhost:5601/api/wazuh-api/update-settings`, + `localhost:5601/elastic/api-settings`, { user: 'john', password: 'bar', @@ -84,7 +84,7 @@ describe('wazuh-api-elastic', () => { ); await needle( 'delete', - `localhost:5601/api/wazuh-api/apiEntries/${res.body.response._id}`, + `localhost:5601/elastic/apis/${res.body.response._id}`, {}, headers ); @@ -92,10 +92,10 @@ describe('wazuh-api-elastic', () => { updated.body.message.should.be.eql('ok'); }); - it('GET /api/wazuh-api/apiEntries', async () => { + it('GET /elastic/apis', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/apiEntries`, + `localhost:5601/elastic/apis`, {}, headers ); @@ -103,10 +103,10 @@ describe('wazuh-api-elastic', () => { res.body.length.should.be.gt(0); }); - it('DELETE /api/wazuh-api/apiEntries/{id}', async () => { + it('DELETE /elastic/apis/{id}', async () => { const insert = await needle( 'put', - `localhost:5601/api/wazuh-api/settings`, + `localhost:5601/elastic/api`, { user: 'foo', password: 'bar', @@ -122,24 +122,24 @@ describe('wazuh-api-elastic', () => { ); const res = await needle( 'delete', - `localhost:5601/api/wazuh-api/apiEntries/${insert.body.response._id}`, + `localhost:5601/elastic/apis/${insert.body.response._id}`, {}, headers ); res.body.result.should.be.eql('deleted'); }); - /*it('PUT /api/wazuh-api/apiEntries/{id}', async () => { - const res = await needle('put', `localhost:5601/api/wazuh-api/apiEntries/${API_ID}`, {}, headers); + /*it('PUT /elastic/apis/{id}', async () => { + const res = await needle('put', `localhost:5601/elastic/apis/${API_ID}`, {}, headers); console.log(res.body) res.body.statusCode.should.be.eql(200) res.body.message.should.be.eql('ok') })*/ - it('PUT /api/wazuh-api/updateApiHostname/{id}', async () => { + it('PUT /elastic/api-hostname/{id}', async () => { const res = await needle( 'put', - `localhost:5601/api/wazuh-api/updateApiHostname/${API_ID}`, + `localhost:5601/elastic/api-hostname/${API_ID}`, {}, headers ); diff --git a/test/server/wazuh-api.js b/test/server/wazuh-api.js index f8af248f88..584a5002a5 100644 --- a/test/server/wazuh-api.js +++ b/test/server/wazuh-api.js @@ -16,7 +16,7 @@ describe('wazuh-api', () => { before(async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/apiEntries`, + `localhost:5601/elastic/apis`, {}, {} ); @@ -34,20 +34,20 @@ describe('wazuh-api', () => { API_USER = res.body[0]._source.api_user; }); - it('POST /api/wazuh-api/csv', async () => { + it('POST /api/csv', async () => { const res = await needle( 'post', - `localhost:5601/api/wazuh-api/csv`, + `localhost:5601/api/csv`, { path: '/agents', id: API_ID }, headers ); res.body.should.be.a('string'); }); - it('POST /api/wazuh-api/checkAPI', async () => { + it('POST /api/check-api', async () => { const res = await needle( 'post', - `localhost:5601/api/wazuh-api/checkAPI`, + `localhost:5601/api/check-api`, { user: API_USER, url: API_URL, port: API_PORT, id: API_ID }, headers ); @@ -57,10 +57,10 @@ describe('wazuh-api', () => { res.body.status.should.be.a('string'); }); - it('POST /api/wazuh-api/checkStoredAPI', async () => { + it('POST /api/check-stored-api', async () => { const res = await needle( 'post', - `localhost:5601/api/wazuh-api/checkStoredAPI`, + `localhost:5601/api/check-stored-api`, API_ID, headers ); @@ -75,10 +75,10 @@ describe('wazuh-api', () => { res.body.data.cluster_info.should.be.a('object'); }); - it('POST /api/wazuh-api/request', async () => { + it('POST /api/request', async () => { const res = await needle( 'post', - `localhost:5601/api/wazuh-api/request`, + `localhost:5601/api/request`, { method: 'GET', path: '/agents/000', body: {}, id: API_ID }, headers ); @@ -89,10 +89,10 @@ describe('wazuh-api', () => { res.body.data.id.should.be.eql('000'); }); - it('GET /api/wazuh-api/pci/{requirement}', async () => { + it('GET /api/pci/{requirement}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/pci/all`, + `localhost:5601/api/pci/all`, {}, {} ); @@ -102,10 +102,10 @@ describe('wazuh-api', () => { ); }); - it('GET /api/wazuh-api/gdpr/{requirement}', async () => { + it('GET /api/gdpr/{requirement}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/gdpr/all`, + `localhost:5601/api/gdpr/all`, {}, {} ); @@ -115,10 +115,10 @@ describe('wazuh-api', () => { ); }); - it('GET /api/wazuh-api/configuration', async () => { + it('GET /utils/configuration', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/configuration`, + `localhost:5601/utils/configuration`, {}, {} ); @@ -128,17 +128,17 @@ describe('wazuh-api', () => { res.body.data.should.be.a('object'); }); - it('GET /api/wazuh-api/ram', async () => { - const res = await needle('get', `localhost:5601/api/wazuh-api/ram`, {}, {}); + it('GET /utils/memory', async () => { + const res = await needle('get', `localhost:5601/utils/memory`, {}, {}); res.body.should.be.a('object'); res.body.error.should.be.eql(0); res.body.ram.should.be.gt(1); }); - it('GET /api/wazuh-api/agents-unique/{api}', async () => { + it('GET /api/agents-unique/{api}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/agents-unique/${API_ID}`, + `localhost:5601/api/agents-unique/${API_ID}`, {}, {} ); @@ -153,10 +153,10 @@ describe('wazuh-api', () => { res.body.result.summary.should.be.a('object'); }); - it('GET /api/wazuh-api/logs', async () => { + it('GET /utils/logs', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-api/logs`, + `localhost:5601/utils/logs`, {}, {} ); diff --git a/test/server/wazuh-elastic.js b/test/server/wazuh-elastic.js index 53737bc272..5ccee257e0 100644 --- a/test/server/wazuh-elastic.js +++ b/test/server/wazuh-elastic.js @@ -11,8 +11,8 @@ const headers = { describe('wazuh-elastic', () => { describe('Checking index patterns', () => { - it('GET /get-list', async () => { - const res = await needle('get', `localhost:5601/get-list`, {}, headers); + it('GET /elastic/index-patterns', async () => { + const res = await needle('get', `localhost:5601/elastic/index-patterns`, {}, headers); res.body.data.should.be.a('array'); res.body.data.length.should.be.gt(0); res.body.data[0].should.be.a('object'); @@ -20,10 +20,10 @@ describe('wazuh-elastic', () => { res.body.data[0].title.should.be.a('string'); }); - it('GET /refresh-fields/{pattern}', async () => { + it('GET /elastic/known-fields/{pattern}', async () => { const res = await needle( 'get', - `localhost:5601/refresh-fields/wazuh-alerts-3.x-*`, + `localhost:5601/elastic/known-fields/wazuh-alerts-3.x-*`, {}, headers ); @@ -36,10 +36,10 @@ describe('wazuh-elastic', () => { }); describe('Checking visualization composers', () => { - it('GET /api/wazuh-elastic/create-vis/{tab}/{pattern}', async () => { + it('GET /elastic/visualizations/{tab}/{pattern}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-elastic/create-vis/overview-general/wazuh-alerts-3.x-*`, + `localhost:5601/elastic/visualizations/overview-general/wazuh-alerts-3.x-*`, {}, headers ); @@ -51,10 +51,10 @@ describe('wazuh-elastic', () => { res.body.raw[0].id.should.be.a('string'); }); - it('POST /api/wazuh-elastic/create-vis/{tab}/{pattern}', async () => { + it('POST /elastic/visualizations/{tab}/{pattern}', async () => { const res = await needle( 'post', - `localhost:5601/api/wazuh-elastic/create-vis/cluster-monitoring/wazuh-alerts-3.x-*`, + `localhost:5601/elastic/visualizations/cluster-monitoring/wazuh-alerts-3.x-*`, { nodes: { items: [], name: 'node01' } }, headers ); @@ -68,10 +68,10 @@ describe('wazuh-elastic', () => { }); describe('Checking template and index pattern existance', () => { - it('GET /api/wazuh-elastic/template/{pattern}', async () => { + it('GET /elastic/template/{pattern}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-elastic/template/wazuh-alerts-3.x-*`, + `localhost:5601/elastic/template/wazuh-alerts-3.x-*`, {}, headers ); @@ -80,10 +80,10 @@ describe('wazuh-elastic', () => { res.body.data.should.be.eql('Template found for wazuh-alerts-3.x-*'); }); - it('GET /api/wazuh-elastic/pattern/{pattern}', async () => { + it('GET /elastic/index-patterns/{pattern}', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-elastic/pattern/wazuh-alerts-3.x-*`, + `localhost:5601/elastic/index-patterns/wazuh-alerts-3.x-*`, {}, headers ); @@ -93,15 +93,15 @@ describe('wazuh-elastic', () => { }); }); - /*it('GET /api/wazuh-elastic/top/{mode}/{cluster}/{field}/{pattern}', async () => { + /*it('GET /elastic/top/{mode}/{cluster}/{field}/{pattern}', async () => { throw Error('Test not implemented...') })*/ describe('Checking .wazuh-version index', () => { - it('GET /api/wazuh-elastic/setup', async () => { + it('GET /elastic/setup', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-elastic/setup`, + `localhost:5601/elastic/setup`, {}, headers ); @@ -114,10 +114,10 @@ describe('wazuh-elastic', () => { res.body.data.lastRestart.should.be.a('string'); }); - it('GET /api/wazuh-elastic/timestamp', async () => { + it('GET /elastic/timestamp', async () => { const res = await needle( 'get', - `localhost:5601/api/wazuh-elastic/timestamp`, + `localhost:5601/elastic/timestamp`, {}, headers );