Skip to content

Made index pattern selector appear without refreshing page #3598

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

Open
wants to merge 4 commits into
base: 4.2-7.10
Choose a base branch
from
Open
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
@@ -58,6 +58,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed Wazuh main menu and breadcrumb render issues [#3347](https://github.com/wazuh/wazuh-kibana-app/pull/3347)
- Fixed generation of huge logs from backend errors [#3397](https://github.com/wazuh/wazuh-kibana-app/pull/3397)
- Fixed vulnerabilities flyout not showing alerts if the vulnerability had a field missing [#3593](https://github.com/wazuh/wazuh-kibana-app/pull/3593)
- Fixed index pattern selector not showing whithout refreshing when new index patterns are created [#3598](https://github.com/wazuh/wazuh-kibana-app/pull/3598)

## Wazuh v4.2.0 - Kibana 7.10.2 , 7.11.2 - Revision 4201

Original file line number Diff line number Diff line change
@@ -15,46 +15,54 @@ import { AppState, SavedObject } from '../../../../react-services';
import { getDataPlugin } from '../../../../kibana-services';
import { HEALTH_CHECK } from '../../../../../common/constants';
import { CheckLogger } from '../../types/check_logger';
import { PatternHandler } from '../../../../react-services/pattern-handler';

export const checkIndexPatternObjectService = async (appConfig, checkLogger: CheckLogger) => {
export const checkIndexPatternObjectService = async (appConfig, checkLogger: CheckLogger) => {
const patternId: string = AppState.getCurrentPattern();
const defaultPatternId: string = appConfig.data['pattern'];
const shouldCreateIndex: boolean = appConfig.data['checks.pattern'];
checkLogger.info(`Index pattern id in cookie: ${patternId ? `yes [${patternId}]` : 'no'}`);

const defaultIndexPatterns: string[] = [
defaultPatternId,
...(patternId && patternId !== defaultPatternId ? [patternId] : [])
...(patternId && patternId !== defaultPatternId ? [patternId] : []),
];
checkLogger.info(`Getting list of valid index patterns...`);
let listValidIndexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns(defaultIndexPatterns, HEALTH_CHECK);
let listValidIndexPatterns = await PatternHandler.getPatternList(HEALTH_CHECK);
checkLogger.info(`Valid index patterns found: ${listValidIndexPatterns.length || 0}`);

const indexPatternDefaultFound = listValidIndexPatterns.find((indexPattern) => indexPattern.title === defaultPatternId);
checkLogger.info(`Found default index pattern with title [${defaultPatternId}]: ${indexPatternDefaultFound ? 'yes' : 'no'}`);
const indexPatternDefaultFound = listValidIndexPatterns.find(
(indexPattern) => indexPattern.title === defaultPatternId
);
checkLogger.info(
`Found default index pattern with title [${defaultPatternId}]: ${
indexPatternDefaultFound ? 'yes' : 'no'
}`
);

if (!indexPatternDefaultFound && defaultPatternId) {
// if no valid index patterns are found we try to create the wazuh-alerts-*
try {
checkLogger.info(`Checking if index pattern [${defaultPatternId}] exists...`);
const existDefaultIndexPattern = await SavedObject.getExistingIndexPattern(defaultPatternId);
checkLogger.info(`Index pattern id [${defaultPatternId}] exists: ${existDefaultIndexPattern ? 'yes' : 'no'}`);
checkLogger.info(
`Index pattern id [${defaultPatternId}] exists: ${existDefaultIndexPattern ? 'yes' : 'no'}`
);
if (existDefaultIndexPattern) {
checkLogger.info(`Refreshing index pattern fields [${defaultPatternId}]...`);
await SavedObject.refreshIndexPattern(defaultPatternId);
checkLogger.action(`Refreshed index pattern fields [${defaultPatternId}]`);
} else if(shouldCreateIndex) {
} else if (shouldCreateIndex) {
checkLogger.info(`Creating index pattern [${defaultPatternId}]...`);
await SavedObject.createWazuhIndexPattern(defaultPatternId);
checkLogger.action(`Created index pattern [${defaultPatternId}]`);
}else{
} else {
// show error
checkLogger.error(`Default index pattern not found`);
}
checkLogger.info(`Getting list of valid index patterns [${patternId}]...`);
listValidIndexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns(defaultIndexPatterns, HEALTH_CHECK);
listValidIndexPatterns = await PatternHandler.getPatternList(HEALTH_CHECK);
checkLogger.info(`Valid index patterns found: ${listValidIndexPatterns.length || 0}`);
if(!AppState.getCurrentPattern()){
if (!AppState.getCurrentPattern()) {
AppState.setCurrentPattern(defaultPatternId);
checkLogger.info(`Index pattern set in cookie: [${defaultPatternId}]`);
}
@@ -67,30 +75,43 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
}

if (AppState.getCurrentPattern() && listValidIndexPatterns.length) {
const indexPatternToSelect = listValidIndexPatterns.find(item => item.id === AppState.getCurrentPattern());
if (!indexPatternToSelect){
const indexPatternToSelect = listValidIndexPatterns.find(
(item) => item.id === AppState.getCurrentPattern()
);
if (!indexPatternToSelect) {
AppState.setCurrentPattern(indexPatternToSelect.id);
checkLogger.action(`Set index pattern id in cookie: [${indexPatternToSelect.id}]`);
}
}
checkLogger.info(`Checking the app default pattern exists: id [${defaultPatternId}]...`);

checkLogger.info(`Checking the app default pattern exists: id [${defaultPatternId}]...`);
const existsDefaultPattern = await SavedObject.existsIndexPattern(defaultPatternId);
checkLogger.info(`Default pattern with id [${defaultPatternId}] exists: ${existsDefaultPattern.status ? 'yes' : 'no'}`);

existsDefaultPattern.status
&& getDataPlugin().indexPatterns.setDefault(defaultPatternId, true)
&& checkLogger.action(`Default pattern id [${defaultPatternId}] set as default index pattern`);
checkLogger.info(
`Default pattern with id [${defaultPatternId}] exists: ${
existsDefaultPattern.status ? 'yes' : 'no'
}`
);

existsDefaultPattern.status &&
getDataPlugin().indexPatterns.setDefault(defaultPatternId, true) &&
checkLogger.action(`Default pattern id [${defaultPatternId}] set as default index pattern`);

patternId && checkLogger.info(`Checking the index pattern id [${patternId}] exists...`);
const patternData = patternId ? (await SavedObject.existsIndexPattern(patternId)) || {} : {} ;
patternId && checkLogger.info(`Index pattern id exists [${patternId}]: ${patternData.status ? 'yes': 'no'}`);
const patternData = patternId ? (await SavedObject.existsIndexPattern(patternId)) || {} : {};
patternId &&
checkLogger.info(
`Index pattern id exists [${patternId}]: ${patternData.status ? 'yes' : 'no'}`
);

if (!patternData.status) {
if (listValidIndexPatterns.length) {
const indexPatternDefaultFound = listValidIndexPatterns.find((indexPattern) => indexPattern.title === defaultPatternId);
checkLogger.info(`Index pattern id exists [${defaultPatternId}]: ${indexPatternDefaultFound ? 'yes': 'no'}`);
if(indexPatternDefaultFound){
const indexPatternDefaultFound = listValidIndexPatterns.find(
(indexPattern) => indexPattern.title === defaultPatternId
);
checkLogger.info(
`Index pattern id exists [${defaultPatternId}]: ${indexPatternDefaultFound ? 'yes' : 'no'}`
);
if (indexPatternDefaultFound) {
AppState.setCurrentPattern(indexPatternDefaultFound.id);
checkLogger.action(`Index pattern set in cookie: [${indexPatternDefaultFound.id}]`);
}
1,752 changes: 901 additions & 851 deletions public/components/wz-menu/wz-menu.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions public/react-services/pattern-handler.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@ import { SavedObject } from './saved-objects';
import { getDataPlugin, getToasts, getHttp } from '../kibana-services';
import { WazuhConfig } from '../react-services/wazuh-config';
import { HEALTH_CHECK } from '../../common/constants';
import store from '../redux/store';
import { updateIndexPatterns } from '../redux/actions/appStateActions';
import _ from 'lodash';

export class PatternHandler {
/**
@@ -29,6 +32,9 @@ export class PatternHandler {
if (selectedPattern && selectedPattern !== pattern) defaultPatterns.push(selectedPattern);
let patternList = await SavedObject.getListOfWazuhValidIndexPatterns(defaultPatterns, origin);

if (!_.isEqual(patternList, store.getState().appStateReducers.indexPatterns)) {
store.dispatch(updateIndexPatterns(patternList));
}
return patternList;
} catch (error) {
console.error('getPatternList', error);
95 changes: 50 additions & 45 deletions public/redux/actions/appStateActions.js
Original file line number Diff line number Diff line change
@@ -14,47 +14,56 @@
* Updates CurrentAPI in the appState store
* @param currentAPI
*/
export const updateCurrentApi = currentAPI => {
export const updateCurrentApi = (currentAPI) => {
return {
type: 'UPDATE_CURRENT_API',
currentAPI: currentAPI
currentAPI: currentAPI,
};
};

/**
* Updates IndexPatterns in the appState store
* @param indexPatterns
*/
export const updateIndexPatterns = (indexPatterns) => {
return {
type: 'UPDATE_INDEX_PATTERNS',
indexPatterns,
};
};
/**
* Updates ShowMenu in the appState store
* @param showMenu
*/
export const updateShowMenu = showMenu => {
export const updateShowMenu = (showMenu) => {
return {
type: 'SHOW_MENU',
showMenu: showMenu
showMenu: showMenu,
};
};

/**
* Updates WazuhNotReadyYet in the appState store
* @param wazuhNotReadyYet
*/
export const updateWazuhNotReadyYet = wazuhNotReadyYet => {
export const updateWazuhNotReadyYet = (wazuhNotReadyYet) => {
return {
type: 'UPDATE_WAZUH_NOT_READY_YET',
wazuhNotReadyYet: wazuhNotReadyYet
wazuhNotReadyYet: wazuhNotReadyYet,
};
};

/**
* Updates currentTab in the appState store
* @param currentTab
*/
export const updateCurrentTab = currentTab => {
export const updateCurrentTab = (currentTab) => {
return {
type: 'UPDATE_WAZUH_CURRENT_TAB',
currentTab: currentTab
currentTab: currentTab,
};
};


/**
* Updates extensions in the appState store
* @param extensions
@@ -64,109 +73,106 @@ export const updateExtensions = (id, extensions) => {
tmpExtensions[id] = extensions;
return {
type: 'UPDATE_EXTENSIONS',
extensions: tmpExtensions
extensions: tmpExtensions,
};
};

/**
* Updates currentPlatform in the appState store
* @param extensions
*/
export const updateCurrentPlatform = currentPlatform => {
export const updateCurrentPlatform = (currentPlatform) => {
return {
type: 'UPDATE_CURRENT_PLATFORM',
currentPlatform
currentPlatform,
};
};


/**
* Updates currentAgentData in the appState store
* @param extensions
*/
export const updateCurrentAgentData = (data) => {
return {
type: 'UPDATE_SELECTED_AGENT_DATA',
currentAgentData: data
currentAgentData: data,
};
};


/**
* Updates showExploreAgentModal in the appState store
* @param extensions
*/
export const showExploreAgentModal = (shouldShow) => {
return {
type: 'SHOW_EXPLORE_AGENT_MODAL',
showExploreAgentModal: shouldShow
showExploreAgentModal: shouldShow,
};
};


/**
* Updates showExploreAgentModalGlobal in the appState store
* @param extensions
*/
export const showExploreAgentModalGlobal = (shouldShow) => {
return {
type: 'SHOW_EXPLORE_AGENT_MODAL_GLOBAL',
showExploreAgentModalGlobal: shouldShow
showExploreAgentModalGlobal: shouldShow,
};
};

/**
* Updates userRoles in the appState store
* @param extensions
*/
export const updateUserRoles = userRoles => {
export const updateUserRoles = (userRoles) => {
return {
type: 'UPDATE_USER_ROLES',
userRoles
userRoles,
};
};

/**
* Updates userPermissions in the appState store
* @param extensions
*/
export const updateUserPermissions = userPermissions => {
export const updateUserPermissions = (userPermissions) => {
return {
type: 'UPDATE_USER_PERMISSIONS',
userPermissions
userPermissions,
};
};

/**
* Updates selectedSettingsSection in the appState store
* @param selected_settings_section
*/
export const updateSelectedSettingsSection = selected_settings_section => {
return {
type: 'UPDATE_SELECTED_SETTINGS_SECTION',
selected_settings_section
};
* Updates selectedSettingsSection in the appState store
* @param selected_settings_section
*/
export const updateSelectedSettingsSection = (selected_settings_section) => {
return {
type: 'UPDATE_SELECTED_SETTINGS_SECTION',
selected_settings_section,
};
};

/**
* Updates selectedToolsSection in the appState store
* @param selected_tools_section
*/
export const updateSelectedToolsSection = selected_tools_section => {
export const updateSelectedToolsSection = (selected_tools_section) => {
return {
type: 'UPDATE_SELECTED_TOOLS_SECTION',
selected_tools_section
selected_tools_section,
};
};

/**
* Updates toastNotification in the appState store
* @param toastNotification
*/
export const updateToastNotificationsModal = toastNotification => {
* Updates toastNotification in the appState store
* @param toastNotification
*/
export const updateToastNotificationsModal = (toastNotification) => {
return {
type: 'UPDATE_TOAST_NOTIFICATIONS_MODAL',
toastNotification
toastNotification,
};
};

@@ -188,7 +194,7 @@ export const updateClusterStatus = (clusterStatus) => {
export const showFlyoutLogtest = (showFlyout) => {
return {
type: 'SHOW_FLYOUT_LOGTEST',
showFlyoutLogtest: showFlyout
showFlyoutLogtest: showFlyout,
};
};

@@ -199,7 +205,7 @@ export const showFlyoutLogtest = (showFlyout) => {
export const updateDockedLogtest = (dockedFlyout) => {
return {
type: 'UPDATE_DOCKED_LOGTEST',
dockedFlyoutLogtest: dockedFlyout
dockedFlyoutLogtest: dockedFlyout,
};
};

@@ -210,19 +216,18 @@ export const updateDockedLogtest = (dockedFlyout) => {
export const updateWithUserLogged = (withUserLogged) => {
return {
type: 'UPDATE_WITH_USER_LOGGED',
withUserLogged,
withUserLogged,
};
};


/**
* Updates allowedAgents in the appState store
* @param allowedAgents
*/
export const updateAllowedAgents = allowedAgents => {
export const updateAllowedAgents = (allowedAgents) => {
return {
type: 'GET_ALLOWED_AGENTS',
allowedAgents
allowedAgents,
};
};

@@ -233,6 +238,6 @@ export const updateAllowedAgents = allowedAgents => {
export const updateLogtestToken = (logtestToken) => {
return {
type: 'UPDATE_LOGTEST_TOKEN',
logtestToken: logtestToken
logtestToken: logtestToken,
};
};
};
45 changes: 25 additions & 20 deletions public/redux/reducers/appStateReducers.js
Original file line number Diff line number Diff line change
@@ -31,99 +31,104 @@ const initialState = {
withUserLogged: false,
allowedAgents: [],
logtestToken: '',
indexPatterns: [],
};

const appStateReducers = (state = initialState, action) => {
if (action.type === 'UPDATE_INDEX_PATTERNS') {
return {
...state,
indexPatterns: action.indexPatterns,
};
}
if (action.type === 'UPDATE_CURRENT_API') {
return {
...state,
currentAPI: action.currentAPI
currentAPI: action.currentAPI,
};
}

if (action.type === 'SHOW_MENU') {
return {
...state,
showMenu: action.showMenu
showMenu: action.showMenu,
};
}

if (action.type === 'UPDATE_WAZUH_NOT_READY_YET') {
return {
...state,
wazuhNotReadyYet: action.wazuhNotReadyYet
wazuhNotReadyYet: action.wazuhNotReadyYet,
};
}

if (action.type === 'UPDATE_WAZUH_CURRENT_TAB') {
return {
...state,
currentTab: action.currentTab
currentTab: action.currentTab,
};
}

if (action.type === 'UPDATE_EXTENSIONS') {
return {
...state,
extensions: action.extensions
extensions: action.extensions,
};
}

if (action.type === 'UPDATE_CURRENT_PLATFORM') {
return {
...state,
currentPlatform: action.currentPlatform
currentPlatform: action.currentPlatform,
};
}

if (action.type === 'UPDATE_SELECTED_AGENT_DATA') {
return {
...state,
currentAgentData: action.currentAgentData
currentAgentData: action.currentAgentData,
};
}


if (action.type === 'SHOW_EXPLORE_AGENT_MODAL') {
return {
...state,
showExploreAgentModal: action.showExploreAgentModal
showExploreAgentModal: action.showExploreAgentModal,
};
}


if (action.type === 'SHOW_EXPLORE_AGENT_MODAL_GLOBAL') {
return {
...state,
showExploreAgentModalGlobal: action.showExploreAgentModalGlobal
showExploreAgentModalGlobal: action.showExploreAgentModalGlobal,
};
}

if (action.type === 'UPDATE_USER_ROLES') {
return {
...state,
userRoles: action.userRoles
userRoles: action.userRoles,
};
}

if (action.type === 'UPDATE_USER_PERMISSIONS') {
return {
...state,
userPermissions: action.userPermissions
userPermissions: action.userPermissions,
};
}

if (action.type === 'UPDATE_SELECTED_SETTINGS_SECTION') {
return {
...state,
selected_settings_section: action.selected_settings_section
selected_settings_section: action.selected_settings_section,
};
}

if (action.type === 'UPDATE_TOAST_NOTIFICATIONS_MODAL') {
return {
...state,
toastNotification: action.toastNotification
toastNotification: action.toastNotification,
};
}

@@ -137,21 +142,21 @@ const appStateReducers = (state = initialState, action) => {
if (action.type === 'UPDATE_WITH_USER_LOGGED') {
return {
...state,
withUserLogged: action.withUserLogged,
withUserLogged: action.withUserLogged,
};
}
}

if (action.type === 'GET_ALLOWED_AGENTS') {
return {
...state,
allowedAgents: action.allowedAgents
allowedAgents: action.allowedAgents,
};
}

if (action.type === 'UPDATE_LOGTEST_TOKEN') {
return {
...state,
logtestToken: action.logtestToken
logtestToken: action.logtestToken,
};
}