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

Fixed kibana settings conflict on health check #3678

Merged
merged 4 commits into from
Nov 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed interative register windows agent screen error [#3654](https://github.com/wazuh/wazuh-kibana-app/pull/3654)
- Fixed breadcrumbs style compatibility for Kibana 7.14.2 [#3668](https://github.com/wazuh/wazuh-kibana-app/pull/3668)
- Fixed Wazuh token is not removed after logout in Kibana 7.13 [#3670](https://github.com/wazuh/wazuh-kibana-app/pull/3670)
- Fixed error conflict setting kibana settings from the health check [#3678](https://github.com/wazuh/wazuh-kibana-app/pull/3678)

## Wazuh v4.2.4 - Kibana 7.10.2, 7.11.2, 7.12.1 - Revision 4205

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@
*
*/

import { AxiosResponse } from 'axios';
import { GenericRequest } from '../../../react-services';
import { CheckLogger } from '../types/check_logger';
import _ from 'lodash';

type userValue<T> = { userValue: T };

type kbnSettings = {
buildNum: userValue<number>;
maxBuckets?: userValue<number>;
metaFields?: userValue<string[]>;
timeFilter?: userValue<string[]>;
};

type responseKbnSettings = { settings: kbnSettings };
import { getUiSettings } from '../../../kibana-services';

export const checkKibanaSettings = (kibanaSettingName: string, defaultAppValue: any, callback?: (checkLogger: CheckLogger, options: {defaultAppValue: any}) => void) => (appConfig: any) => async (checkLogger: CheckLogger) => {
checkLogger.info('Getting settings...');
const kibanaSettingsResponse: AxiosResponse<responseKbnSettings> = await GenericRequest.request('GET', '/api/kibana/settings');
checkLogger.info('Got Kibana settings');
const valueKibanaSetting = kibanaSettingsResponse.data?.settings?.[kibanaSettingName]?.userValue;
const settingsAreDifferent = !_.isEqual(valueKibanaSetting, defaultAppValue);
const valueKibanaSetting = getUiSettings().get(kibanaSettingName);
const settingsAreDifferent = !_.isEqual(
typeof defaultAppValue === 'string' ? stringifySetting(valueKibanaSetting) : valueKibanaSetting,
defaultAppValue
);
checkLogger.info(`Check Kibana setting [${kibanaSettingName}]: ${stringifySetting(valueKibanaSetting)}`);
checkLogger.info(`App setting [${kibanaSettingName}]: ${stringifySetting(defaultAppValue)}`);
checkLogger.info(`Settings mismatch [${kibanaSettingName}]: ${settingsAreDifferent ? 'yes' : 'no'}`);
if ( !valueKibanaSetting && settingsAreDifferent ){
if ( !valueKibanaSetting || settingsAreDifferent ){
checkLogger.info(`Updating [${kibanaSettingName}] setting...`);
await GenericRequest.request('POST', '/api/kibana/settings', { changes: { [kibanaSettingName]: defaultAppValue } });
await updateSetting(kibanaSettingName, defaultAppValue);
checkLogger.action(`Updated [${kibanaSettingName}] setting to: ${stringifySetting(defaultAppValue)}`);
callback && callback(checkLogger,{ defaultAppValue });
}
}

async function updateSetting(kibanaSettingName, defaultAppValue, retries = 3) {
return await getUiSettings()
.set(kibanaSettingName, null)
.catch(async (error) => {
if (retries > 0) {
console.log("retry", retries)
frankeros marked this conversation as resolved.
Show resolved Hide resolved
return await updateSetting(kibanaSettingName, defaultAppValue, --retries);
}
throw error;
});
}

function stringifySetting(setting: any){
try{
return JSON.stringify(setting);
Expand Down