diff --git a/plugins/main/public/types.ts b/plugins/main/public/types.ts
index d4edcbb66a..647791058f 100644
--- a/plugins/main/public/types.ts
+++ b/plugins/main/public/types.ts
@@ -5,13 +5,20 @@ import {
VisualizationsSetup,
VisualizationsStart,
} from '../../../src/plugins/visualizations/public';
-import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../src/plugins/data/public';
+import {
+ DataPublicPluginSetup,
+ DataPublicPluginStart,
+} from '../../../src/plugins/data/public';
import { NavigationPublicPluginStart } from '../../../src/plugins/navigation/public';
import { UiActionsSetup } from '../../../src/plugins/ui_actions/public';
import { SecurityOssPluginStart } from '../../../src/plugins/security_oss/public/';
import { SavedObjectsStart } from '../../../src/plugins/saved_objects/public';
-import { TelemetryPluginStart, TelemetryPluginSetup } from '../../../src/plugins/telemetry/public';
+import {
+ TelemetryPluginStart,
+ TelemetryPluginSetup,
+} from '../../../src/plugins/telemetry/public';
import { WazuhCheckUpdatesPluginStart } from '../../wazuh-check-updates/public';
+import { WazuhCorePluginStart } from '../../wazuh-core/public';
import { WazuhEndpointsPluginStart } from '../../wazuh-endpoints/public';
import { DashboardStart } from '../../../src/plugins/dashboard/public';
@@ -25,6 +32,7 @@ export interface AppPluginStartDependencies {
savedObjects: SavedObjectsStart;
telemetry: TelemetryPluginStart;
wazuhCheckUpdates: WazuhCheckUpdatesPluginStart;
+ wazuhCore: WazuhCorePluginStart;
wazuhEndpoints: WazuhEndpointsPluginStart;
dashboard: DashboardStart;
}
diff --git a/plugins/main/public/utils/applications.ts b/plugins/main/public/utils/applications.ts
index aa675cd06b..bbf791d96b 100644
--- a/plugins/main/public/utils/applications.ts
+++ b/plugins/main/public/utils/applications.ts
@@ -713,22 +713,6 @@ export const appSettings = {
redirectTo: () => '/settings?tab=configuration',
};
-const appLogs = {
- category: 'management',
- id: 'app-logs',
- title: i18n.translate('wz-app-app-logs-title', {
- defaultMessage: 'App Logs',
- }),
- description: i18n.translate('wz-app-app-logs-description', {
- defaultMessage: 'Explore the logs related to the applications.',
- }),
- euiIconType: 'indexRollupApp',
- order: 8904,
- showInOverviewApp: false,
- showInAgentMenu: false,
- redirectTo: () => '/settings?tab=logs',
-};
-
const about = {
category: 'management',
id: 'about',
@@ -782,7 +766,6 @@ export const Applications = [
serverApis,
sampleData,
appSettings,
- appLogs,
about,
].sort((a, b) => {
// Sort applications by order
diff --git a/plugins/main/server/controllers/wazuh-api.ts b/plugins/main/server/controllers/wazuh-api.ts
index cc7bf6cf69..0f366841ed 100644
--- a/plugins/main/server/controllers/wazuh-api.ts
+++ b/plugins/main/server/controllers/wazuh-api.ts
@@ -13,7 +13,6 @@
// Require some libraries
import { ErrorResponse } from '../lib/error-response';
import { Parser } from 'json2csv';
-import { log } from '../lib/logger';
import { KeyEquivalence } from '../../common/csv-key-equivalence';
import { ApiErrorEquivalence } from '../lib/api-errors-equivalence';
import apiRequestList from '../../common/api-info/endpoints';
@@ -21,31 +20,17 @@ import { HTTP_STATUS_CODES } from '../../common/constants';
import { getCustomizationSetting } from '../../common/services/settings';
import { addJobToQueue } from '../start/queue';
import fs from 'fs';
-import { ManageHosts } from '../lib/manage-hosts';
-import { UpdateRegistry } from '../lib/update-registry';
import jwtDecode from 'jwt-decode';
import {
OpenSearchDashboardsRequest,
RequestHandlerContext,
OpenSearchDashboardsResponseFactory,
} from 'src/core/server';
-import {
- APIUserAllowRunAs,
- CacheInMemoryAPIUserAllowRunAs,
- API_USER_STATUS_RUN_AS,
-} from '../lib/cache-api-user-has-run-as';
import { getCookieValueByName } from '../lib/cookie';
-import { SecurityObj } from '../lib/security-factory';
import { getConfiguration } from '../lib/get-configuration';
export class WazuhApiCtrl {
- manageHosts: ManageHosts;
- updateRegistry: UpdateRegistry;
-
- constructor() {
- this.manageHosts = new ManageHosts();
- this.updateRegistry = new UpdateRegistry();
- }
+ constructor() {}
async getToken(
context: RequestHandlerContext,
@@ -82,14 +67,16 @@ export class WazuhApiCtrl {
});
}
} catch (error) {
- log('wazuh-api:getToken', error.message || error);
+ context.wazuh.logger.error(
+ `Error decoding the API host entry token: ${error.message}`,
+ );
}
}
}
let token;
if (
- (await APIUserAllowRunAs.canUse(idHost)) ==
- API_USER_STATUS_RUN_AS.ENABLED
+ (await context.wazuh_core.cacheAPIUserAllowRunAs.canUse(idHost)) ===
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS.ENABLED
) {
token = await context.wazuh.api.client.asCurrentUser.authenticate(
idHost,
@@ -116,11 +103,12 @@ export class WazuhApiCtrl {
body: { token },
});
} catch (error) {
- const errorMessage =
- ((error.response || {}).data || {}).detail || error.message || error;
- log('wazuh-api:getToken', errorMessage);
+ const errorMessage = `Error getting the authorization token: ${
+ ((error.response || {}).data || {}).detail || error.message || error
+ }`;
+ context.wazuh.logger.error(errorMessage);
return ErrorResponse(
- `Error getting the authorization token: ${errorMessage}`,
+ errorMessage,
3000,
error?.response?.status || HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR,
response,
@@ -143,13 +131,17 @@ export class WazuhApiCtrl {
try {
// Get config from wazuh.yml
const id = request.body.id;
- const api = await this.manageHosts.getHostById(id);
+ context.wazuh.logger.debug(`Getting server API host by ID: ${id}`);
+ const api = await context.wazuh_core.manageHosts.getHostById(id);
+ context.wazuh.logger.debug(
+ `Server API host data: ${JSON.stringify(api)}`,
+ );
// Check Manage Hosts
if (!Object.keys(api).length) {
- throw new Error('Could not find Wazuh API entry on wazuh.yml');
+ throw new Error('Could not find server API entry in the configuration');
}
- log('wazuh-api:checkStoredAPI', `${id} exists`, 'debug');
+ context.wazuh.logger.debug(`${id} exists`);
// Fetch needed information about the cluster and the manager itself
const responseManagerInfo =
@@ -161,7 +153,7 @@ export class WazuhApiCtrl {
);
// Look for socket-related errors
- if (this.checkResponseIsDown(responseManagerInfo)) {
+ if (this.checkResponseIsDown(context, responseManagerInfo)) {
return ErrorResponse(
`ERROR3099 - ${
responseManagerInfo.data.detail || 'Wazuh not ready yet'
@@ -240,7 +232,10 @@ export class WazuhApiCtrl {
if (api.cluster_info) {
// Update cluster information in the wazuh-registry.json
- await this.updateRegistry.updateClusterInfo(id, api.cluster_info);
+ await context.wazuh_core.updateRegistry.updateClusterInfo(
+ id,
+ api.cluster_info,
+ );
// Hide Wazuh API secret, username, password
const copied = { ...api };
@@ -280,7 +275,7 @@ export class WazuhApiCtrl {
});
} else {
try {
- const apis = await this.manageHosts.getHosts();
+ const apis = await context.wazuh_core.manageHosts.getHosts();
for (const api of apis) {
try {
const id = Object.keys(api)[0];
@@ -293,7 +288,7 @@ export class WazuhApiCtrl {
{ apiHostID: id },
);
- if (this.checkResponseIsDown(responseManagerInfo)) {
+ if (this.checkResponseIsDown(context, responseManagerInfo)) {
return ErrorResponse(
`ERROR3099 - ${
response.data.detail || 'Wazuh not ready yet'
@@ -311,7 +306,7 @@ export class WazuhApiCtrl {
} catch (error) {} // eslint-disable-line
}
} catch (error) {
- log('wazuh-api:checkStoredAPI', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || error,
3020,
@@ -319,7 +314,7 @@ export class WazuhApiCtrl {
response,
);
}
- log('wazuh-api:checkStoredAPI', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || error,
3002,
@@ -374,15 +369,18 @@ export class WazuhApiCtrl {
let apiAvailable = null;
// const notValid = this.validateCheckApiParams(request.body);
// if (notValid) return ErrorResponse(notValid, 3003, HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR, response);
- log('wazuh-api:checkAPI', `${request.body.id} is valid`, 'debug');
+ context.wazuh.logger.debug(`${request.body.id} is valid`);
// Check if a Wazuh API id is given (already stored API)
- const data = await this.manageHosts.getHostById(request.body.id);
+ const data = await context.wazuh_core.manageHosts.getHostById(
+ request.body.id,
+ );
if (data) {
apiAvailable = data;
} else {
- log('wazuh-api:checkAPI', `API ${request.body.id} not found`);
+ const errorMessage = `The server API host entry with ID ${request.body.id} was not found`;
+ context.wazuh.logger.debug(errorMessage);
return ErrorResponse(
- `The API ${request.body.id} was not found`,
+ errorMessage,
3029,
HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR,
response,
@@ -411,12 +409,7 @@ export class WazuhApiCtrl {
response,
);
}
-
- log(
- 'wazuh-api:checkAPI',
- `${request.body.id} credentials are valid`,
- 'debug',
- );
+ context.wazuh.logger.debug(`${request.body.id} credentials are valid`);
if (
responseManagerInfo.status === HTTP_STATUS_CODES.OK &&
responseManagerInfo.data
@@ -442,7 +435,9 @@ export class WazuhApiCtrl {
);
// Check the run_as for the API user and update it
- let apiUserAllowRunAs = API_USER_STATUS_RUN_AS.ALL_DISABLED;
+ let apiUserAllowRunAs =
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS
+ .ALL_DISABLED;
const responseApiUserAllowRunAs =
await context.wazuh.api.client.asInternalUser.request(
'GET',
@@ -457,29 +452,33 @@ export class WazuhApiCtrl {
if (allow_run_as && apiAvailable && apiAvailable.run_as)
// HOST AND USER ENABLED
- apiUserAllowRunAs = API_USER_STATUS_RUN_AS.ENABLED;
+ apiUserAllowRunAs =
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS
+ .ENABLED;
else if (!allow_run_as && apiAvailable && apiAvailable.run_as)
// HOST ENABLED AND USER DISABLED
- apiUserAllowRunAs = API_USER_STATUS_RUN_AS.USER_NOT_ALLOWED;
+ apiUserAllowRunAs =
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS
+ .USER_NOT_ALLOWED;
else if (allow_run_as && (!apiAvailable || !apiAvailable.run_as))
// USER ENABLED AND HOST DISABLED
- apiUserAllowRunAs = API_USER_STATUS_RUN_AS.HOST_DISABLED;
+ apiUserAllowRunAs =
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS
+ .HOST_DISABLED;
else if (!allow_run_as && (!apiAvailable || !apiAvailable.run_as))
// HOST AND USER DISABLED
- apiUserAllowRunAs = API_USER_STATUS_RUN_AS.ALL_DISABLED;
+ apiUserAllowRunAs =
+ context.wazuh_core.cacheAPIUserAllowRunAs.API_USER_STATUS_RUN_AS
+ .ALL_DISABLED;
}
- CacheInMemoryAPIUserAllowRunAs.set(
+ context.wazuh_core.cacheAPIUserAllowRunAs.set(
request.body.id,
apiAvailable.username,
apiUserAllowRunAs,
);
if (responseCluster.status === HTTP_STATUS_CODES.OK) {
- log(
- 'wazuh-api:checkStoredAPI',
- `Wazuh API response is valid`,
- 'debug',
- );
+ context.wazuh.logger.debug('Wazuh API response is valid');
if (responseCluster.data.data.enabled === 'yes') {
// If cluster mode is active
let responseClusterLocal =
@@ -517,7 +516,7 @@ export class WazuhApiCtrl {
}
}
} catch (error) {
- log('wazuh-api:checkAPI', error.message || error);
+ context.wazuh.logger.warn(error.message || error);
if (
error &&
@@ -561,7 +560,7 @@ export class WazuhApiCtrl {
}
}
- checkResponseIsDown(response) {
+ checkResponseIsDown(context, response) {
if (response.status !== HTTP_STATUS_CODES.OK) {
// Avoid "Error communicating with socket" like errors
const socketErrorCodes = [1013, 1014, 1017, 1018, 1019];
@@ -569,8 +568,7 @@ export class WazuhApiCtrl {
const isDown = socketErrorCodes.includes(status);
isDown &&
- log(
- 'wazuh-api:makeRequest',
+ context.wazuh.logger.error(
'Wazuh API is online but Wazuh is not ready yet',
);
@@ -612,7 +610,7 @@ export class WazuhApiCtrl {
const isValid = execd && modulesd && wazuhdb && clusterd;
- isValid && log('wazuh-api:checkDaemons', `Wazuh is ready`, 'debug');
+ isValid && context.wazuh.logger.debug('Wazuh is ready');
if (path === '/ping') {
return { isValid };
@@ -622,7 +620,7 @@ export class WazuhApiCtrl {
throw new Error('Wazuh not ready yet');
}
} catch (error) {
- log('wazuh-api:checkDaemons', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return Promise.reject(error);
}
}
@@ -667,13 +665,13 @@ export class WazuhApiCtrl {
async makeRequest(context, method, path, data, id, response) {
const devTools = !!(data || {}).devTools;
try {
- const api = await this.manageHosts.getHostById(id);
+ const api = await context.wazuh_core.manageHosts.getHostById(id);
if (devTools) {
delete data.devTools;
}
if (!Object.keys(api).length) {
- log('wazuh-api:makeRequest', 'Could not get host credentials');
+ context.wazuh.logger.error('Could not get host credentials');
//Can not get credentials from wazuh-hosts
return ErrorResponse(
'Could not get host credentials',
@@ -723,7 +721,7 @@ export class WazuhApiCtrl {
if (delay) {
addJobToQueue({
startAt: new Date(Date.now() + delay),
- run: async () => {
+ run: async contextJob => {
try {
await context.wazuh.api.client.asCurrentUser.request(
method,
@@ -732,8 +730,7 @@ export class WazuhApiCtrl {
options,
);
} catch (error) {
- log(
- 'queue:delayApiRequest',
+ contextJob.wazuh.logger.error(
`An error ocurred in the delayed request: "${method} ${path}": ${
error.message || error
}`,
@@ -753,8 +750,7 @@ export class WazuhApiCtrl {
} catch (error) {
const isDown = (error || {}).code === 'ECONNREFUSED';
if (!isDown) {
- log(
- 'wazuh-api:makeRequest',
+ context.wazuh.logger.error(
'Wazuh API is online but Wazuh is not ready yet',
);
return ErrorResponse(
@@ -767,7 +763,7 @@ export class WazuhApiCtrl {
}
}
- log('wazuh-api:makeRequest', `${method} ${path}`, 'debug');
+ context.wazuh.logger.debug(`${method} ${path}`);
// Extract keys from parameters
const dataProperties = Object.keys(data);
@@ -790,7 +786,7 @@ export class WazuhApiCtrl {
data,
options,
);
- const responseIsDown = this.checkResponseIsDown(responseToken);
+ const responseIsDown = this.checkResponseIsDown(context, responseToken);
if (responseIsDown) {
return ErrorResponse(
`ERROR3099 - ${response.body.message || 'Wazuh not ready yet'}`,
@@ -841,7 +837,7 @@ export class WazuhApiCtrl {
);
}
const errorMsg = (error.response || {}).data || error.message;
- log('wazuh-api:makeRequest', errorMsg || error);
+ context.wazuh.logger.error(errorMsg || error);
if (devTools) {
return response.ok({
body: { error: '3013', message: errorMsg || error },
@@ -890,7 +886,7 @@ export class WazuhApiCtrl {
response,
);
} else if (!request.body.method.match(/^(?:GET|PUT|POST|DELETE)$/)) {
- log('wazuh-api:makeRequest', 'Request method is not valid.');
+ context.wazuh.logger.error('Request method is not valid.');
//Method is not a valid HTTP request method
return ErrorResponse(
'Request method is not valid.',
@@ -906,7 +902,7 @@ export class WazuhApiCtrl {
response,
);
} else if (!request.body.path.startsWith('/')) {
- log('wazuh-api:makeRequest', 'Request path is not valid.');
+ context.wazuh.logger.error('Request path is not valid.');
//Path doesn't start with '/'
return ErrorResponse(
'Request path is not valid.',
@@ -955,7 +951,7 @@ export class WazuhApiCtrl {
if (!tmpPath) throw new Error('An error occurred parsing path field');
- log('wazuh-api:csv', `Report ${tmpPath}`, 'debug');
+ context.wazuh.logger.debug(`Report ${tmpPath}`);
// Real limit, regardless the user query
const params = { limit: 500 };
@@ -1088,7 +1084,7 @@ export class WazuhApiCtrl {
);
}
} catch (error) {
- log('wazuh-api:csv', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || error,
3034,
@@ -1124,13 +1120,11 @@ export class WazuhApiCtrl {
) {
try {
const source = JSON.parse(
- fs.readFileSync(this.updateRegistry.file, 'utf8'),
+ fs.readFileSync(context.wazuh_core.updateRegistry.file, 'utf8'),
);
if (source.installationDate && source.lastRestart) {
- log(
- 'wazuh-api:getTimeStamp',
+ context.wazuh.logger.debug(
`Installation date: ${source.installationDate}. Last restart: ${source.lastRestart}`,
- 'debug',
);
return response.ok({
body: {
@@ -1142,7 +1136,7 @@ export class WazuhApiCtrl {
throw new Error('Could not fetch wazuh-version registry');
}
} catch (error) {
- log('wazuh-api:getTimeStamp', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || 'Could not fetch wazuh-version registry',
4001,
@@ -1166,7 +1160,7 @@ export class WazuhApiCtrl {
) {
try {
const source = JSON.parse(
- fs.readFileSync(this.updateRegistry.file, 'utf8'),
+ fs.readFileSync(context.wazuh_core.updateRegistry.file, 'utf8'),
);
return response.ok({
body: {
@@ -1175,7 +1169,7 @@ export class WazuhApiCtrl {
},
});
} catch (error) {
- log('wazuh-api:getSetupInfo', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
`Could not get data from wazuh-version registry due to ${
error.message || error
@@ -1242,7 +1236,7 @@ export class WazuhApiCtrl {
body: syscollector,
});
} catch (error) {
- log('wazuh-api:getSyscollector', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || error,
3035,
@@ -1280,7 +1274,7 @@ export class WazuhApiCtrl {
body: { logos },
});
} catch (error) {
- log('wazuh-api:getAppLogos', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
error.message || error,
3035,
diff --git a/plugins/main/server/controllers/wazuh-elastic.ts b/plugins/main/server/controllers/wazuh-elastic.ts
index cdcfb23d41..63550e4900 100644
--- a/plugins/main/server/controllers/wazuh-elastic.ts
+++ b/plugins/main/server/controllers/wazuh-elastic.ts
@@ -10,7 +10,6 @@
* Find more information about this on the LICENSE file.
*/
import { ErrorResponse } from '../lib/error-response';
-import { log } from '../lib/logger';
import { getConfiguration } from '../lib/get-configuration';
import {
AgentsVisualizations,
@@ -25,13 +24,10 @@ import {
WAZUH_SAMPLE_ALERTS_INDEX_REPLICAS,
} from '../../common/constants';
import jwtDecode from 'jwt-decode';
-import { ManageHosts } from '../lib/manage-hosts';
import {
OpenSearchDashboardsRequest,
RequestHandlerContext,
OpenSearchDashboardsResponseFactory,
- SavedObject,
- SavedObjectsFindResponse,
} from 'src/core/server';
import { getCookieValueByName } from '../lib/cookie';
import {
@@ -43,10 +39,8 @@ import { WAZUH_INDEXER_NAME } from '../../common/constants';
export class WazuhElasticCtrl {
wzSampleAlertsIndexPrefix: string;
- manageHosts: ManageHosts;
constructor() {
this.wzSampleAlertsIndexPrefix = this.getSampleAlertPrefix();
- this.manageHosts = new ManageHosts();
}
/**
@@ -125,14 +119,12 @@ export class WazuhElasticCtrl {
item = lastChar === '*' ? item.slice(0, -1) : item;
return item.includes(pattern) || pattern.includes(item);
});
- log(
- 'wazuh-elastic:getTemplate',
+ context.wazuh.logger.debug(
`Template is valid: ${
isIncluded && Array.isArray(isIncluded) && isIncluded.length
? 'yes'
: 'no'
}`,
- 'debug',
);
return isIncluded && Array.isArray(isIncluded) && isIncluded.length
? response.ok({
@@ -150,7 +142,7 @@ export class WazuhElasticCtrl {
},
});
} catch (error) {
- log('wazuh-elastic:getTemplate', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(
`Could not retrieve templates from ${WAZUH_INDEXER_NAME} due to ${
error.message || error
@@ -254,7 +246,7 @@ export class WazuhElasticCtrl {
},
});
} catch (error) {
- log('wazuh-elastic:getFieldTop', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(error.message || error, 4004, 500, response);
}
}
@@ -333,7 +325,7 @@ export class WazuhElasticCtrl {
},
});
} catch (error) {
- log('wazuh-elastic:getCurrentPlatform', error.message || error);
+ context.wazuh.logger.error(error.message || error);
return ErrorResponse(error.message || error, 4011, 500, response);
}
}
@@ -343,85 +335,68 @@ export class WazuhElasticCtrl {
* @param {Array