Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 4.5-7.16] Make checks inside Pattern check services #5387

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { AppState, ErrorHandler } from '../../../react-services';
import { useAppConfig, useRootScope } from '../../../components/common/hooks';
import {
checkApiService,
checkPluginPlatformSettings,
checkIndexPatternService,
checkPatternSupportService,
checkSetupService,
Expand All @@ -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 './health-check.scss';
import { getThemeAssetURL, getAssetURL } from '../../../utils/assets';
Expand Down Expand Up @@ -91,33 +82,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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,13 +49,34 @@ 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.`);
};
}
};

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)}`);
}));
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 });
}
}

Expand All @@ -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;
};
};