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

Make checks inside Pattern check services #5384

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,13 +46,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',
(appConfig, checkLogger) => checkPluginPlatformSettings(
asteriscos marked this conversation as resolved.
Show resolved Hide resolved
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));
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
) => (appConfig: any) => async (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;
};
};