From 08043420a4ac33f15028501d71b85c6b317026b6 Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 18 Apr 2023 11:52:12 +0200 Subject: [PATCH 1/3] Make checks inside Pattern check services --- .../container/health-check.container.tsx | 27 ----------- .../check-index-pattern.service.ts | 48 +++++++++++++++++-- .../check-plugin-platform-settings.service.ts | 16 ++++--- 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/public/components/health-check/container/health-check.container.tsx b/public/components/health-check/container/health-check.container.tsx index b1d11a5ff2..e869951a31 100644 --- a/public/components/health-check/container/health-check.container.tsx +++ b/public/components/health-check/container/health-check.container.tsx @@ -90,33 +90,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 23ca42fa29..cb30009fb7 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 @@ -16,10 +16,27 @@ import { checkFieldsService } from './check-fields.service'; import { checkIndexPatternObjectService } from './check-index-pattern-object.service'; import { checkTemplateService } from './check-template.service'; -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); @@ -29,9 +46,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.`); }; } @@ -39,3 +56,24 @@ const decoratorHealthCheckRunCheckEnabled = (checkKey, fn) => { const checkTemplate = decoratorHealthCheckRunCheckEnabled('template', checkTemplateService); const checkFields = decoratorHealthCheckRunCheckEnabled('fields', checkFieldsService); + +const checkMaxBuckets = decoratorHealthCheckRunCheckEnabled('maxBuckets', + (appConfig, checkLogger) => checkPluginPlatformSettings( + PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, + WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS + )(appConfig)(checkLogger)); + +const checkMetaFields = decoratorHealthCheckRunCheckEnabled('metaFields', + (appConfig, checkLogger) => checkPluginPlatformSettings( + PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, + WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS + )(appConfig)(checkLogger)); + +const checkTimeFilter = decoratorHealthCheckRunCheckEnabled('timeFilter', + (appConfig, checkLogger) => 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)}`); + })(appConfig)(checkLogger)); 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..ea810b4827 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 +) => (appConfig: any) => async (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; }; }; From 6aca32cd33c20a1528df667cb8e078d250d0722b Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 18 Apr 2023 12:09:47 +0200 Subject: [PATCH 2/3] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ecbe6de7..b7a1d1e1b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,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 From a86db5503380b39576bb185dc07c915a9ab242f4 Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 18 Apr 2023 12:41:53 +0200 Subject: [PATCH 3/3] refactor checkPluginPlatformSettings and code cleaning --- .../container/health-check.container.tsx | 9 --------- .../check-index-pattern.service.ts | 12 ++++++------ .../check-plugin-platform-settings.service.ts | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/public/components/health-check/container/health-check.container.tsx b/public/components/health-check/container/health-check.container.tsx index e869951a31..92733497e6 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'; 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 cb30009fb7..34abf17714 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 @@ -58,22 +58,22 @@ const checkTemplate = decoratorHealthCheckRunCheckEnabled('template', checkTempl const checkFields = decoratorHealthCheckRunCheckEnabled('fields', checkFieldsService); const checkMaxBuckets = decoratorHealthCheckRunCheckEnabled('maxBuckets', - (appConfig, checkLogger) => checkPluginPlatformSettings( + checkPluginPlatformSettings( PLUGIN_PLATFORM_SETTING_NAME_MAX_BUCKETS, WAZUH_PLUGIN_PLATFORM_SETTING_MAX_BUCKETS - )(appConfig)(checkLogger)); + )); const checkMetaFields = decoratorHealthCheckRunCheckEnabled('metaFields', - (appConfig, checkLogger) => checkPluginPlatformSettings( + checkPluginPlatformSettings( PLUGIN_PLATFORM_SETTING_NAME_METAFIELDS, WAZUH_PLUGIN_PLATFORM_SETTING_METAFIELDS - )(appConfig)(checkLogger)); + )); const checkTimeFilter = decoratorHealthCheckRunCheckEnabled('timeFilter', - (appConfig, checkLogger) => checkPluginPlatformSettings( + 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)}`); - })(appConfig)(checkLogger)); + })); 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 ea810b4827..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 @@ -21,7 +21,7 @@ export const checkPluginPlatformSettings = ( pluginPlatformSettingName: string, defaultAppValue: any, callback?: (checkLogger: CheckLogger, options: { defaultAppValue: any }) => void -) => (appConfig: any) => async (checkLogger: CheckLogger) => { +) => async (appConfig: any, checkLogger: CheckLogger) => { checkLogger.info('Getting settings...'); const valuePluginPlatformSetting = getUiSettings().get(pluginPlatformSettingName); const settingsAreDifferent = !_.isEqual(