diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d7625f0d..bca048975d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Changed - Changed of regular expression in RBAC. [#5201](https://github.com/wazuh/wazuh-kibana-app/pull/5201) +- Migrate the timeFilter, metaFields, maxBuckets health checks inside the pattern check. [#5384](https://github.com/wazuh/wazuh-kibana-app/pull/5384) ### Fixed diff --git a/public/components/health-check/container/health-check.container.tsx b/public/components/health-check/container/health-check.container.tsx index c3eeca4956..204b90067a 100644 --- a/public/components/health-check/container/health-check.container.tsx +++ b/public/components/health-check/container/health-check.container.tsx @@ -27,7 +27,6 @@ import { AppState, ErrorHandler } from '../../../react-services'; import { useAppConfig, useRootScope } from '../../../components/common/hooks'; import { checkApiService, - checkPluginPlatformSettings, checkIndexPatternService, checkPatternSupportService, checkSetupService, @@ -37,18 +36,10 @@ import { withErrorBoundary, withReduxProvider } from '../../common/hocs'; import { getHttp } from '../../../kibana-services'; import { HEALTH_CHECK_REDIRECTION_TIME, - PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, - PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, - PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER, WAZUH_INDEX_TYPE_MONITORING, WAZUH_INDEX_TYPE_STATISTICS, - WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS, - WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS, - WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER, } from '../../../../common/constants'; -import { getDataPlugin } from '../../../kibana-services'; -import { CheckLogger } from '../types/check_logger'; import { compose } from 'redux'; import { getThemeAssetURL, getAssetURL } from '../../../utils/assets'; @@ -90,33 +81,6 @@ const checks = { shouldCheck: true, canRetry: true, }, - maxBuckets: { - title: `Check ${PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS} setting`, - label: `${PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS} setting`, - validator: checkPluginPlatformSettings(PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS), - awaitFor: [], - canRetry: true, - }, - metaFields: { - title: `Check ${PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS} setting`, - label: `${PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS} setting`, - validator: checkPluginPlatformSettings(PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS), - awaitFor: [], - canRetry: true, - }, - timeFilter: { - title: `Check ${PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER} setting`, - label: `${PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER} setting`, - validator: checkPluginPlatformSettings( - PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER, - JSON.stringify(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER), - (checkLogger: CheckLogger, options: { defaultAppValue: any }) => { - getDataPlugin().query.timefilter.timefilter.setTime(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER) - && checkLogger.action(`Timefilter set to ${JSON.stringify(options.defaultAppValue)}`); - }), - awaitFor: [], - canRetry: true, - } }; function HealthCheckComponent() { diff --git a/public/components/health-check/services/check-index-pattern/check-index-pattern.service.ts b/public/components/health-check/services/check-index-pattern/check-index-pattern.service.ts index 8225e3efc5..af54469ed6 100644 --- a/public/components/health-check/services/check-index-pattern/check-index-pattern.service.ts +++ b/public/components/health-check/services/check-index-pattern/check-index-pattern.service.ts @@ -17,10 +17,27 @@ import { checkIndexPatternObjectService } from './check-index-pattern-object.ser import { checkTemplateService } from './check-template.service'; import { satisfyPluginPlatformVersion } from '../../../../../common/semver'; -export const checkIndexPatternService = (appConfig) => async (checkLogger: CheckLogger) => await checkPattern(appConfig, checkLogger); +import { checkPluginPlatformSettings } from '../../services'; +import { + PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, + PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, + PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER, + WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS, + WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS, + WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER, +} from '../../../../../common/constants'; -const checkPattern = async (appConfig, checkLogger: CheckLogger) => { - if(!appConfig.data['checks.pattern']){ +import { getDataPlugin } from '../../../../kibana-services'; + +export const checkIndexPatternService = (appConfig) => async (checkLogger: CheckLogger) => { + await checkPattern(appConfig, checkLogger); + await checkMaxBuckets(appConfig, checkLogger); + await checkMetaFields(appConfig, checkLogger); + await checkTimeFilter(appConfig, checkLogger); +}; + +const checkPattern = async (appConfig, checkLogger: CheckLogger) => { + if (!appConfig.data['checks.pattern']) { checkLogger.info('Check [pattern]: disabled. Some minimal tasks will be done.'); }; await checkIndexPatternObjectService(appConfig, checkLogger); @@ -32,9 +49,9 @@ const checkPattern = async (appConfig, checkLogger: CheckLogger) => { const decoratorHealthCheckRunCheckEnabled = (checkKey, fn) => { return async (appConfig: any, checkLogger: CheckLogger) => { - if(appConfig.data[`checks.${checkKey}`]){ + if (appConfig.data[`checks.${checkKey}`]) { await fn(appConfig, checkLogger); - }else{ + } else { checkLogger.info(`Check [${checkKey}]: disabled. Skipped.`); }; } @@ -42,3 +59,24 @@ const decoratorHealthCheckRunCheckEnabled = (checkKey, fn) => { const checkTemplate = decoratorHealthCheckRunCheckEnabled('template', checkTemplateService); const checkFields = decoratorHealthCheckRunCheckEnabled('fields', checkFieldsService); + +const checkMaxBuckets = decoratorHealthCheckRunCheckEnabled('maxBuckets', + checkPluginPlatformSettings( + PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, + WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS + )); + +const checkMetaFields = decoratorHealthCheckRunCheckEnabled('metaFields', + checkPluginPlatformSettings( + PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, + WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS + )); + +const checkTimeFilter = decoratorHealthCheckRunCheckEnabled('timeFilter', + checkPluginPlatformSettings( + PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER, + JSON.stringify(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER), + (checkLogger: CheckLogger, options: { defaultAppValue: any }) => { + getDataPlugin().query.timefilter.timefilter.setTime(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER) + && checkLogger.action(`Timefilter set to ${JSON.stringify(options.defaultAppValue)}`); + })); diff --git a/public/components/health-check/services/check-plugin-platform-settings.service.ts b/public/components/health-check/services/check-plugin-platform-settings.service.ts index 3bef304b56..4adc35c8cd 100644 --- a/public/components/health-check/services/check-plugin-platform-settings.service.ts +++ b/public/components/health-check/services/check-plugin-platform-settings.service.ts @@ -17,7 +17,11 @@ import _ from 'lodash'; import { getUiSettings } from '../../../kibana-services'; import { PLUGIN_PLATFORM_NAME } from '../../../../common/constants'; -export const checkPluginPlatformSettings = (pluginPlatformSettingName: string, defaultAppValue: any, callback?: (checkLogger: CheckLogger, options: {defaultAppValue: any}) => void) => (appConfig: any) => async (checkLogger: CheckLogger) => { +export const checkPluginPlatformSettings = ( + pluginPlatformSettingName: string, + defaultAppValue: any, + callback?: (checkLogger: CheckLogger, options: { defaultAppValue: any }) => void +) => async (appConfig: any, checkLogger: CheckLogger) => { checkLogger.info('Getting settings...'); const valuePluginPlatformSetting = getUiSettings().get(pluginPlatformSettingName); const settingsAreDifferent = !_.isEqual( @@ -27,11 +31,11 @@ export const checkPluginPlatformSettings = (pluginPlatformSettingName: string, d checkLogger.info(`Check ${PLUGIN_PLATFORM_NAME} setting [${pluginPlatformSettingName}]: ${stringifySetting(valuePluginPlatformSetting)}`); checkLogger.info(`App setting [${pluginPlatformSettingName}]: ${stringifySetting(defaultAppValue)}`); checkLogger.info(`Settings mismatch [${pluginPlatformSettingName}]: ${settingsAreDifferent ? 'yes' : 'no'}`); - if ( !valuePluginPlatformSetting || settingsAreDifferent ){ + if (!valuePluginPlatformSetting || settingsAreDifferent) { checkLogger.info(`Updating [${pluginPlatformSettingName}] setting...`); await updateSetting(pluginPlatformSettingName, defaultAppValue); checkLogger.action(`Updated [${pluginPlatformSettingName}] setting to: ${stringifySetting(defaultAppValue)}`); - callback && callback(checkLogger,{ defaultAppValue }); + callback && callback(checkLogger, { defaultAppValue }); } } @@ -46,10 +50,10 @@ async function updateSetting(pluginPlatformSettingName, defaultAppValue, retries }); } -function stringifySetting(setting: any){ - try{ +function stringifySetting(setting: any) { + try { return JSON.stringify(setting); - }catch(error){ + } catch (error) { return setting; }; };