From 8c39829fc1744c78ac75dc2e35784f199aa02b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar=20Biset?= <43619595+jbiset@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:14:16 -0300 Subject: [PATCH] Fixed keeping filters between dashboard and inventory using visualizations call to actions (#6448) * Fixed keeping filters between dashboard and inventory using visualizations call to actions * Added CHANGELOG * Fixed to remove auto loaded agent.id filters * Fix CHANGELOG * Fixed hideManagerAlerts filter * Fixed filters order --- CHANGELOG.md | 2 +- .../vulnerability_detector_adapters.tsx | 21 +++++++++++++++++++ .../dashboards/overview/dashboard.tsx | 15 ++++++++++++- .../use_search_bar_configuration.tsx | 20 +++++++++++++++++- .../DIS_Template.json | 10 ++++++++- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8945e1c847..9930154862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added the ability to check if there are available updates from the UI. [#6093](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6093) [#6256](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6256) [#6328](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6328) - Added remember server address check [#5791](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5791) - Added the ssl_agent_ca configuration to the SSL Settings form [#6083](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6083) -- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896) [#6179](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6179) [#6173](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6173) [#6147](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6147) [#6231](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6231) [#6246](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6246) [#6321](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6321) [#6338](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6338) [#6356](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6356) [#6396](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6396) [#6399](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6399) [#6405](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6405) [#6410](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6410) [#6424](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6424) [#6422](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6422) [#6429](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6429) +- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896) [#6179](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6179) [#6173](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6173) [#6147](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6147) [#6231](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6231) [#6246](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6246) [#6321](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6321) [#6338](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6338) [#6356](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6356) [#6396](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6396) [#6399](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6399) [#6405](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6405) [#6410](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6410) [#6424](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6424) [#6422](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6422) [#6429](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6429) [#6448](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6448) - Added an agent selector to the IT Hygiene application [#5840](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5840) - Added query results limit when the search exceed 10000 hits [#6106](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6106) - Added a redirection button to Endpoint Summary from IT Hygiene application [#6176](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6176) diff --git a/plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx b/plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx index c2a6e117c8..b605aff9c4 100644 --- a/plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/common/vulnerability_detector_adapters.tsx @@ -256,3 +256,24 @@ const cleanFilters = ( ); return mappedFilters; }; + +export const updateFiltersStorage = (filters: Filter[]) => { + const storagePreviousFilters = sessionStorage.getItem( + SESSION_STORAGE_FILTERS_NAME, + ); + if (storagePreviousFilters) { + const previousFilters = JSON.parse(storagePreviousFilters); + const previousImplicitFilters = previousFilters.filter( + (filter: Filter) => filter?.$state?.isImplicit, + ); + /* Normal filters added to storagePreviousFilters are added to keep them between dashboard and inventory tab */ + const newFilters = filters.filter( + (filter: Filter) => !filter?.$state?.isImplicit, + ); + + sessionStorage.setItem( + SESSION_STORAGE_FILTERS_NAME, + JSON.stringify([...previousImplicitFilters, ...newFilters]), + ); + } +}; diff --git a/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/dashboard.tsx b/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/dashboard.tsx index fb85ae42a9..d8489e1920 100644 --- a/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/dashboard.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/dashboards/overview/dashboard.tsx @@ -16,6 +16,7 @@ import { vulnerabilityIndexFiltersAdapter, restorePrevIndexFiltersAdapter, onUpdateAdapter, + updateFiltersStorage, } from '../../common/vulnerability_detector_adapters'; import { search } from '../inventory/inventory_service'; import { IndexPattern } from '../../../../../../../../src/plugins/data/common'; @@ -28,6 +29,7 @@ import { compose } from 'redux'; import { withVulnerabilitiesStateDataSource } from '../../common/hocs/validate-vulnerabilities-states-index-pattern'; import { ModuleEnabledCheck } from '../../common/components/check-module-enabled'; import { DataSourceFilterManagerVulnerabilitiesStates } from '../../../../../react-services/data-sources'; +import { DashboardContainerInput } from '../../../../../../../../src/plugins/dashboard/public'; const plugins = getPlugins(); @@ -50,12 +52,20 @@ const DashboardVulsComponent: React.FC = () => { onUnMount: restorePrevIndexFiltersAdapter, }); + /* This function is responsible for updating the storage filters so that the + filters between dashboard and inventory added using visualizations call to actions. + Without this feature, filters added using visualizations call to actions are + not maintained between dashboard and inventory tabs */ + const handleFilterByVisualization = (newInput: DashboardContainerInput) => { + updateFiltersStorage(newInput.filters); + }; + const fetchFilters = DataSourceFilterManagerVulnerabilitiesStates.getFilters( searchBarProps.filters, VULNERABILITIES_INDEX_PATTERN_ID, ); - const { isLoading, filters, query, indexPatterns } = searchBarProps; + const { isLoading, query, indexPatterns } = searchBarProps; const [isSearching, setIsSearching] = useState(false); const [results, setResults] = useState({} as SearchResponse); @@ -128,6 +138,7 @@ const DashboardVulsComponent: React.FC = () => { }, hidePanelTitles: true, }} + onInputUpdated={handleFilterByVisualization} /> { }, hidePanelTitles: true, }} + onInputUpdated={handleFilterByVisualization} /> { }, hidePanelTitles: false, }} + onInputUpdated={handleFilterByVisualization} /> ) : null} diff --git a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx b/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx index 879d1d2916..9bbebabaea 100644 --- a/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx +++ b/plugins/main/public/components/overview/vulnerabilities/search_bar/use_search_bar_configuration.tsx @@ -17,6 +17,10 @@ import { useQueryManager, useTimeFilter, } from '../../../common/hooks'; +import { + AUTHORIZED_AGENTS, + DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER, +} from '../../../../../common/constants'; // Input - types type tUseSearchBarCustomInputs = { @@ -134,7 +138,21 @@ const useSearchBarConfiguration = ( const searchBarProps: Partial = { isLoading, ...(indexPatternSelected && { indexPatterns: [indexPatternSelected] }), // indexPattern cannot be empty or empty [] - filters: filters, + filters: filters + .filter( + (filter: Filter) => + ![ + AUTHORIZED_AGENTS, + DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER, + ].includes(filter?.meta?.controlledBy), // remove auto loaded agent.id filters + ) + .sort((a: Filter, b: Filter) => { + return a?.$state?.isImplicit && !(a?.meta?.key === 'agent.id') + ? -1 + : b?.$state?.isImplicit + ? 1 + : -1; + }), query, timeHistory, dateRangeFrom: timeFilter.from, diff --git a/scripts/vulnerabilities-events-injector/DIS_Template.json b/scripts/vulnerabilities-events-injector/DIS_Template.json index c9cec7e26f..a68baf66e8 100644 --- a/scripts/vulnerabilities-events-injector/DIS_Template.json +++ b/scripts/vulnerabilities-events-injector/DIS_Template.json @@ -239,6 +239,14 @@ } } }, + "manager": { + "properties": { + "name": { + "ignore_above": 1024, + "type": "keyword" + } + } + }, "node": { "properties": { "name": { @@ -262,4 +270,4 @@ "refresh_interval": "2s" } } -} \ No newline at end of file +}