Skip to content

Commit

Permalink
Replace the plugin logging system by the provided by the platform (#6161
Browse files Browse the repository at this point in the history
)

* feat(logging): remove plugin logger from start tasks of main plugin

- Enhance the logging messages
- Minor enhancements

* feat(logging): minor fixes to logging messages in the main plugin

* feat(logging): remove custom logger from endpoints of main plugin

* fix(logging): remove parameter of addJobToQueue

* feat(core): replace the loggin service and move services to core plugin

- Replace the logging services
- Move services to core plugin
  - CacheAPIUserAllowRunAs
  - ManageHosts
  - ServerAPIClient (aka api-interceptor)
  - ServerAPIHostEntries (aka )
  - UpdateConfigurationFile
  - UpdateRegistry
- Adapt the usage of services in the main and check updates plugin from
  core plugin
- Remove plugin logger from main and core plugins
- Remove API endpoint
  - GET /utils/logs/ui
- Remove unused code
- Adapt the test suites

* feat(logging): removed constants related to log files path

* fix(dependency): removed winston dependency of plugins and update the yarn.lock files

* fix(logging): removed logs.level plugin setting

* fix(logging): fixed monitoring and statistics backend tasks

* fix(monitoring): manage API host entries

* feat(core): add description to core services classes

* feat(docs): add docs to core plugin

* feat(docs): add description to core services

* test: fix of check updates plugin

* test: fix of check updates plugin

* feat(logging): remove the App logs application

- Remove GET /utils/logs endpoint
  - Remove related tests
- Remove App logs application

* Fix test

---------

Co-authored-by: Ian Yenien Serrano <[email protected]>
Co-authored-by: Ian Yenien Serrano <[email protected]>
  • Loading branch information
3 people authored Dec 27, 2023
1 parent 2a1ebb2 commit ff561c5
Show file tree
Hide file tree
Showing 107 changed files with 3,606 additions and 5,238 deletions.
12 changes: 0 additions & 12 deletions plugins/main/common/config-equivalences.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const configEquivalences = {
'wazuh.monitoring.pattern':
'Default index pattern to use for Wazuh monitoring.',
hideManagerAlerts: 'Hide the alerts of the manager in every dashboard.',
'logs.level': 'Logging level of the App.',
'enrollment.dns':
'Specifies the Wazuh registration server, used for the agent enrollment.',
'enrollment.password':
Expand Down Expand Up @@ -85,7 +84,6 @@ export const nameEquivalence = {
'wazuh.monitoring.creation': 'Index creation',
'wazuh.monitoring.pattern': 'Index pattern',
hideManagerAlerts: 'Hide manager alerts',
'logs.level': 'Log level',
'enrollment.dns': 'Enrollment DNS',
'cron.prefix': 'Cron prefix',
'cron.statistics.status': 'Status',
Expand Down Expand Up @@ -142,7 +140,6 @@ export const categoriesEquivalence = {
'wazuh.monitoring.creation': MONITORING,
'wazuh.monitoring.pattern': MONITORING,
hideManagerAlerts: GENERAL,
'logs.level': GENERAL,
'enrollment.dns': GENERAL,
'cron.prefix': GENERAL,
'cron.statistics.status': STATISTICS,
Expand Down Expand Up @@ -197,15 +194,6 @@ export const formEquivalence = {
},
'wazuh.monitoring.pattern': { type: TEXT },
hideManagerAlerts: { type: BOOLEAN },
'logs.level': {
type: LIST,
params: {
options: [
{ text: 'Info', value: 'info' },
{ text: 'Debug', value: 'debug' },
],
},
},
'enrollment.dns': { type: TEXT },
'cron.prefix': { type: TEXT },
'cron.statistics.status': { type: BOOLEAN },
Expand Down
61 changes: 0 additions & 61 deletions plugins/main/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,6 @@ export const WAZUH_DATA_CONFIG_REGISTRY_PATH = path.join(
'wazuh-registry.json',
);

// Wazuh data path - logs
export const MAX_MB_LOG_FILES = 100;
export const WAZUH_DATA_LOGS_DIRECTORY_PATH = path.join(
WAZUH_DATA_ABSOLUTE_PATH,
'logs',
);
export const WAZUH_DATA_LOGS_PLAIN_FILENAME = 'wazuhapp-plain.log';
export const WAZUH_DATA_LOGS_PLAIN_PATH = path.join(
WAZUH_DATA_LOGS_DIRECTORY_PATH,
WAZUH_DATA_LOGS_PLAIN_FILENAME,
);
export const WAZUH_DATA_LOGS_RAW_FILENAME = 'wazuhapp.log';
export const WAZUH_DATA_LOGS_RAW_PATH = path.join(
WAZUH_DATA_LOGS_DIRECTORY_PATH,
WAZUH_DATA_LOGS_RAW_FILENAME,
);

// Wazuh data path - UI logs
export const WAZUH_UI_LOGS_PLAIN_FILENAME = 'wazuh-ui-plain.log';
export const WAZUH_UI_LOGS_RAW_FILENAME = 'wazuh-ui.log';
export const WAZUH_UI_LOGS_PLAIN_PATH = path.join(
WAZUH_DATA_LOGS_DIRECTORY_PATH,
WAZUH_UI_LOGS_PLAIN_FILENAME,
);
export const WAZUH_UI_LOGS_RAW_PATH = path.join(
WAZUH_DATA_LOGS_DIRECTORY_PATH,
WAZUH_UI_LOGS_RAW_FILENAME,
);

// Wazuh data path - downloads
export const WAZUH_DATA_DOWNLOADS_DIRECTORY_PATH = path.join(
WAZUH_DATA_ABSOLUTE_PATH,
Expand Down Expand Up @@ -1506,38 +1477,6 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
return schema.boolean();
},
},
'logs.level': {
title: 'Log level',
description: 'Logging level of the App.',
category: SettingCategory.GENERAL,
type: EpluginSettingType.select,
options: {
select: [
{
text: 'Info',
value: 'info',
},
{
text: 'Debug',
value: 'debug',
},
],
},
defaultValue: 'info',
isConfigurableFromFile: true,
isConfigurableFromUI: true,
requiresRestartingPluginPlatform: true,
validate: function (value) {
return SettingsValidator.literal(
this.options.select.map(({ value }) => value),
)(value);
},
validateBackend: function (schema) {
return schema.oneOf(
this.options.select.map(({ value }) => schema.literal(value)),
);
},
},
pattern: {
title: 'Index pattern',
description:
Expand Down
3 changes: 0 additions & 3 deletions plugins/main/common/plugin-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ describe('[settings] Input validation', () => {
${'ip.ignore'} | ${['test', 'test#']} | ${'It can\'t contain invalid characters: \\, /, ?, ", <, >, |, ,, #.'}
${'ip.selector'} | ${true} | ${undefined}
${'ip.selector'} | ${''} | ${'It should be a boolean. Allowed values: true or false.'}
${'logs.level'} | ${'info'} | ${undefined}
${'logs.level'} | ${'debug'} | ${undefined}
${'logs.level'} | ${''} | ${'Invalid value. Allowed values: info, debug.'}
${'pattern'} | ${'test'} | ${undefined}
${'pattern'} | ${'test*'} | ${undefined}
${'pattern'} | ${''} | ${'Value can not be empty.'}
Expand Down
1 change: 0 additions & 1 deletion plugins/main/common/wazu-menu/wz-menu-settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum WAZUH_MENU_SETTINGS_SECTIONS_CY_TEST_ID {
MODULES = 'menuSettingsModulesLink',
SAMPLE_DATA = 'menuSettingsSampleDataLink',
CONFIGURATION = 'menuSettingsConfigurationLink',
LOGS = 'menuSettingsLogsLink',
MISCELLANEOUS = 'menuSettingsMiscellaneousLink',
ABOUT = 'menuSettingsAboutLink',
}
1 change: 1 addition & 0 deletions plugins/main/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"opensearchDashboardsUtils",
"opensearchDashboardsLegacy",
"wazuhCheckUpdates",
"wazuhCore",
"wazuhEndpoints"
],
"optionalPlugins": [
Expand Down
5 changes: 2 additions & 3 deletions plugins/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
"react-cookie": "^4.0.3",
"read-last-lines": "^1.7.2",
"timsort": "^0.3.0",
"typescript": "^5.0.4",
"winston": "3.9.0"
"typescript": "^5.0.4"
},
"devDependencies": {
"@types/node-cron": "^2.0.3",
Expand All @@ -89,4 +88,4 @@
"redux-mock-store": "^1.5.4",
"swagger-client": "^3.19.11"
}
}
}
11 changes: 6 additions & 5 deletions plugins/main/public/components/security/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Users } from './users/users';
import { Roles } from './roles/roles';
import { Policies } from './policies/policies';
import { GenericRequest } from '../../react-services/generic-request';
import { API_USER_STATUS_RUN_AS } from '../../../server/lib/cache-api-user-has-run-as';
import { AppState } from '../../react-services/app-state';
import { RolesMapping } from './roles-mapping/roles-mapping';
import {
Expand All @@ -30,6 +29,7 @@ import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/typ
import { getErrorOrchestrator } from '../../react-services/common-services';
import { getPluginDataPath } from '../../../common/plugin';
import { security } from '../../utils/applications';
import { getWazuhCorePlugin } from '../../kibana-services';

const tabs = [
{
Expand Down Expand Up @@ -128,16 +128,16 @@ export const WzSecurity = compose(
const isNotRunAs = allowRunAs => {
let runAsWarningTxt = '';
switch (allowRunAs) {
case API_USER_STATUS_RUN_AS.HOST_DISABLED:
case getWazuhCorePlugin().API_USER_STATUS_RUN_AS.HOST_DISABLED:
runAsWarningTxt = `For the role mapping to take effect, enable run_as in ${getPluginDataPath(
'config/wazuh.yml',
)} configuration file, restart the ${PLUGIN_PLATFORM_NAME} service and clear your browser cache and cookies.`;
break;
case API_USER_STATUS_RUN_AS.USER_NOT_ALLOWED:
case getWazuhCorePlugin().API_USER_STATUS_RUN_AS.USER_NOT_ALLOWED:
runAsWarningTxt =
'The role mapping has no effect because the current Wazuh API user has allow_run_as disabled.';
break;
case API_USER_STATUS_RUN_AS.ALL_DISABLED:
case getWazuhCorePlugin().API_USER_STATUS_RUN_AS.ALL_DISABLED:
runAsWarningTxt = `For the role mapping to take effect, enable run_as in ${getPluginDataPath(
'config/wazuh.yml',
)} configuration file and set the current Wazuh API user allow_run_as to true. Restart the ${PLUGIN_PLATFORM_NAME} service and clear your browser cache and cookies.`;
Expand Down Expand Up @@ -174,7 +174,8 @@ export const WzSecurity = compose(
{selectedTabId === 'roleMapping' && (
<>
{allowRunAs !== undefined &&
allowRunAs !== API_USER_STATUS_RUN_AS.ENABLED &&
allowRunAs !==
getWazuhCorePlugin().API_USER_STATUS_RUN_AS.ENABLED &&
isNotRunAs(allowRunAs)}
<RolesMapping></RolesMapping>
</>
Expand Down
Loading

0 comments on commit ff561c5

Please sign in to comment.