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 that alerts table is empty when switching pinned agents #3008

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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to the Wazuh app project will be documented in this file.

## Wazuh v4.1.1 - Kibana 7.10.0 , 7.10.2 - Revision 4103

### Fixed

- Fix SCA policy detail showing name and check results about another policy [#3007](https://github.com/wazuh/wazuh-kibana-app/pull/3007)
- Fix pagination in SCA checks table when expand some row [#3018](https://github.com/wazuh/wazuh-kibana-app/pull/3018)
- Fix manager is shown in suggestions in Agents section [#3025](https://github.com/wazuh/wazuh-kibana-app/pull/3025)
- Fix disabled loading on inventory when request fail [#3016](https://github.com/wazuh/wazuh-kibana-app/issues/3016)
- Fix restarting selected cluster instead of all of them [#3032](https://github.com/wazuh/wazuh-kibana-app/pull/3032)
- Fixed that alerts table is empty when switching pinned agents [#3008](https://github.com/wazuh/wazuh-kibana-app/pull/3008)

## Wazuh v4.1.1 - Kibana 7.10.0 , 7.10.2 - Revision 4102

### Added
Expand Down
9 changes: 8 additions & 1 deletion public/components/agents/fim/inventory/fileDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import { getIndexPattern } from '../../../overview/mitre/lib';
import moment from 'moment-timezone';
import { AppNavigate } from '../../../../react-services/app-navigate';
import { TruncateHorizontalComponents } from '../../../common/util';
import { getDataPlugin } from '../../../../kibana-services';
import { getDataPlugin,getUiSettings } from '../../../../kibana-services';
import { RegistryValues } from './registryValues';
import { TimeService } from '../../../../react-services/time-service';
import { FilterManager } from '../../../../../../../src/plugins/data/public/';

export class FileDetails extends Component {
props!: {
Expand Down Expand Up @@ -68,6 +69,8 @@ export class FileDetails extends Component {
</svg>
);
indexPattern!: IIndexPattern;
discoverFilterManager: FilterManager;

constructor(props) {
super(props);

Expand All @@ -76,6 +79,8 @@ export class FileDetails extends Component {
totalHits: 0,
};
this.viewInEvents.bind(this);

this.discoverFilterManager = new FilterManager(getUiSettings());
}

componentDidMount() {
Expand Down Expand Up @@ -475,6 +480,8 @@ export class FileDetails extends Component {
<EuiFlexGroup className="flyout-row">
<EuiFlexItem>
<Discover
kbnSearchBar
shareFilterManager={this.discoverFilterManager}
initialColumns={[
'icon',
'timestamp',
Expand Down
58 changes: 20 additions & 38 deletions public/components/common/modules/discover/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const Discover = compose(
};

KibanaServices: { [key: string]: any };
filterManager: FilterManager;
state: {
sort: object
selectedTechnique: string,
Expand All @@ -87,9 +86,7 @@ export const Discover = compose(
query: { language: "kuery" | "lucene", query: string }
itemIdToExpandedRowMap: any
dateRange: TimeRange
searchBarFilters: []
elasticQuery: object
filters: []
columns: string[]
hover: string
};
Expand All @@ -102,13 +99,12 @@ export const Discover = compose(
updateTotalHits: Function,
includeFilters?: string,
initialColumns: string[],
shareFilterManager: object[],
shareFilterManager: FilterManager,
refreshAngularDiscover?: number
}
constructor(props) {
super(props);
this.KibanaServices = getDataPlugin();
this.filterManager = props.shareFilterManager ? this.KibanaServices.query.filterManager : new FilterManager(getUiSettings());
this.timefilter = this.KibanaServices.query.timefilter.timefilter;
this.state = {
sort: {},
Expand All @@ -127,9 +123,7 @@ export const Discover = compose(
itemIdToExpandedRowMap: {},
dateRange: this.timefilter.getTime(),
query: props.query || { language: "kuery", query: "" },
searchBarFilters: [],
elasticQuery: {},
filters: props.initialFilters,
columns: [],
hover: ""
}
Expand Down Expand Up @@ -168,8 +162,8 @@ export const Discover = compose(
async componentDidMount() {
this._isMount = true;
try {
this.setState({columns: this.getColumns(), searchBarFilters: this.props.shareFilterManager || []}) //initial columns
await this.getIndexPattern();
this.setState({columns: this.getColumns()}) //initial columns
await this.getIndexPattern();
await this.getAlerts();
} catch (err) {
console.log(err);
Expand All @@ -182,25 +176,20 @@ export const Discover = compose(

async componentDidUpdate(prevProps, prevState) {
if (!this._isMount) { return; }
if((!prevProps.currentAgentData.id && this.props.currentAgentData.id) || (prevProps.currentAgentData.id && !this.props.currentAgentData.id)){
if((!prevProps.currentAgentData.id && this.props.currentAgentData.id) || (prevProps.currentAgentData.id && !this.props.currentAgentData.id) || prevProps.currentAgentData.id !== this.props.currentAgentData.id){
this.setState({ columns: this.getColumns() }); // Updates the columns to be rendered if you change the selected agent to none or vice versa
return;
}
if(!_.isEqual(this.props.query,prevProps.query)){
this.setState({ query: {...this.props.query}});
return;
};
if((!_.isEqual(this.props.shareFilterManager, prevProps.shareFilterManager))
|| (this.props.currentAgentData.id !== prevProps.currentAgentData.id)
if((this.props.currentAgentData.id !== prevProps.currentAgentData.id)
|| (!_.isEqual(this.state.query, prevState.query))
|| (!_.isEqual(this.state.searchBarFilters, prevState.searchBarFilters))
|| (!_.isEqual(this.state.dateRange, prevState.dateRange))
|| (this.props.refreshAngularDiscover !== prevProps.refreshAngularDiscover)
){
this.setState({ pageIndex: 0 , tsUpdated: Date.now()});
if(!_.isEqual(this.props.shareFilterManager, this.state.searchBarFilters)){
this.setState({columns: this.getColumns(), searchBarFilters: this.props.shareFilterManager || []}); //initial columns
}
return;
};
if(['pageIndex', 'pageSize', 'sortField', 'sortDirection'].some(field => this.state[field] !== prevState[field]) || (this.state.tsUpdated !== prevState.tsUpdated)){
Expand Down Expand Up @@ -262,10 +251,6 @@ export const Discover = compose(
return result;
}

onFiltersChange = (filters) => {
this.setState({ filters: this.filtersAsArray(filters) });
}

toggleDetails = item => {
const itemIdToExpandedRowMap = { ...this.state.itemIdToExpandedRowMap };
if (itemIdToExpandedRowMap[item._id]) {
Expand All @@ -282,7 +267,6 @@ export const Discover = compose(

buildFilter() {
const dateParse = ds => /\d+-\d+-\d+T\d+:\d+:\d+.\d+Z/.test(ds) ? DateMatch.parse(ds).toDate().getTime() : ds;
const { searchBarFilters } = this.state;
const { query } = this.state;
const { hideManagerAlerts } = this.wazuhConfig.getConfig();
const extraFilters = [];
Expand All @@ -300,12 +284,14 @@ export const Discover = compose(
$state: { store: 'appState' }
});

const shareFilterManager = this.props.shareFilterManager || [];
const filters = this.props.shareFilterManager ? this.props.shareFilterManager.filters : [];
const previousFilters = this.KibanaServices && this.KibanaServices.query.filterManager.filters ? this.KibanaServices.query.filterManager.filters : [];

const elasticQuery =
buildEsQuery(
undefined,
query,
[...searchBarFilters, ...extraFilters, ...shareFilterManager],
[...previousFilters, ...filters, ...extraFilters],
getEsQueryConfig(getUiSettings())
);

Expand Down Expand Up @@ -355,12 +341,12 @@ export const Discover = compose(
}
);
if (this._isMount) {
this.setState({ alerts: alerts.data.hits.hits, total: alerts.data.hits.total.value, isLoading: false, requestFilters: newFilters, filters: newFilters.filters });
this.setState({ alerts: alerts.data.hits.hits, total: alerts.data.hits.total.value, isLoading: false, requestFilters: newFilters});
this.props.updateTotalHits(alerts.data.hits.total.value);
}
} catch (err) {
if (this._isMount) {
this.setState({ alerts: [], total: 0, isLoading: false, requestFilters: newFilters, filters: newFilters.filters });
this.setState({ alerts: [], total: 0, isLoading: false, requestFilters: newFilters});
this.props.updateTotalHits(0);
}
}
Expand Down Expand Up @@ -521,48 +507,44 @@ export const Discover = compose(
* @param filter
*/
addFilterOut(filter) {
const filterManager = this.props.shareFilterManager;
const key = Object.keys(filter)[0];
const value = filter[key];
const valuesArray = Array.isArray(value) ? [...value] : [value];
const filters = this.state.searchBarFilters;
valuesArray.map((item) => {
const formattedFilter = buildPhraseFilter({ name: key, type: "string" }, item, this.indexPattern);
formattedFilter.meta.negate = true;

filters.push(formattedFilter);
filterManager.addFilters(formattedFilter);
})

this.filterManager.setFilters(filters);
if (!this.props.shareFilterManager) this.setState({ searchBarFilters: filters });
this.setState({ pageIndex: 0 , tsUpdated: Date.now()});
}

/**
* Adds a new filter with format { "filter_key" : "filter_value" }, e.g. {"agent.id": "001"}
* @param filter
*/
addFilter(filter) {
const filterManager = this.props.shareFilterManager;
const key = Object.keys(filter)[0];
const value = filter[key];
const valuesArray = Array.isArray(value) ? [...value] : [value];
const filters = []; //this.state.searchBarFilters;
valuesArray.map((item) => {
const formattedFilter = buildPhraseFilter({ name: key, type: "string" }, item, this.indexPattern);
if (formattedFilter.meta.key === 'manager.name' || formattedFilter.meta.key === 'cluster.name') {
formattedFilter.meta["removable"] = false;
}
filters.push(formattedFilter);
filterManager.addFilters(formattedFilter);
})
this.filterManager.addFilters(filters);
if (!this.props.shareFilterManager) this.setState({ searchBarFilters: filters });

this.setState({ pageIndex: 0 , tsUpdated: Date.now()});
}

onQuerySubmit = (payload: { dateRange: TimeRange, query: Query | undefined }) => {
this.setState({...payload, tsUpdated: Date.now()});
}

onFiltersUpdated = (filters: Filter[]) => {
this.setState({ searchBarFilters: filters });
this.setState({ pageIndex: 0 , tsUpdated: Date.now()});
}

closeMitreFlyout = () => {
Expand Down Expand Up @@ -624,9 +606,9 @@ export const Discover = compose(
return (
<div
className='wz-discover hide-filter-control wz-inventory' >
{!this.props.shareFilterManager && <KbnSearchBar
{this.props.kbnSearchBar && <KbnSearchBar
indexPattern={this.indexPattern}
filterManager={this.filterManager}
filterManager={this.props.shareFilterManager}
onQuerySubmit={this.onQuerySubmit}
onFiltersUpdated={this.onFiltersUpdated}
query={query} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
import { Discover } from '../../../../common/modules/discover';
import { AppState } from '../../../../../react-services/app-state';
import { requirementGoal } from '../../requirement-goal';
import { getUiSettings } from '../../../../../kibana-services';
import { FilterManager } from '../../../../../../../../src/plugins/data/public/';



Expand All @@ -41,10 +43,13 @@ export class RequirementFlyout extends Component {
props!: {
};

filterManager: FilterManager;

constructor(props) {
super(props);
this.state = {
}
this.filterManager = new FilterManager(getUiSettings());
}

componentDidMount() {
Expand Down Expand Up @@ -164,7 +169,7 @@ export class RequirementFlyout extends Component {
initialIsOpen={true}>
<EuiFlexGroup className="flyout-row">
<EuiFlexItem>
<Discover initialColumns={["icon", "timestamp", this.props.getRequirementKey(), 'rule.level', 'rule.id', 'rule.description']} implicitFilters={implicitFilters} initialFilters={[]} updateTotalHits={(total) => this.updateTotalHits(total)} />
<Discover kbnSearchBar shareFilterManager={this.filterManager} initialColumns={["icon", "timestamp", this.props.getRequirementKey(), 'rule.level', 'rule.id', 'rule.description']} implicitFilters={implicitFilters} initialFilters={[]} updateTotalHits={(total) => this.updateTotalHits(total)} />
</EuiFlexItem>
</EuiFlexGroup>
</EuiAccordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { WzRequest } from '../../../../../../../react-services/wz-request';
import { AppState } from '../../../../../../../react-services/app-state';
import { AppNavigate } from '../../../../../../../react-services/app-navigate';
import { Discover } from '../../../../../../common/modules/discover';
import { getUiSettings } from '../../../../../../../kibana-services';
import { FilterManager } from '../../../../../../../../../../src/plugins/data/public/';

export class FlyoutTechnique extends Component {
_isMount = false;
Expand All @@ -56,6 +58,8 @@ export class FlyoutTechnique extends Component {
currentTechnique: string
}

filterManager: FilterManager;

constructor(props) {
super(props);
this.state = {
Expand All @@ -64,6 +68,7 @@ export class FlyoutTechnique extends Component {
},
loading: false
}
this.filterManager = new FilterManager(getUiSettings());
}

async componentDidMount() {
Expand Down Expand Up @@ -315,7 +320,7 @@ export class FlyoutTechnique extends Component {
initialIsOpen={true}>
<EuiFlexGroup className="flyout-row">
<EuiFlexItem>
<Discover initialColumns={["icon", "timestamp", 'rule.mitre.id', 'rule.mitre.tactic', 'rule.level', 'rule.id', 'rule.description']} implicitFilters={implicitFilters} initialFilters={[]} updateTotalHits={(total) => this.updateTotalHits(total)}/>
<Discover kbnSearchBar shareFilterManager={this.filterManager} initialColumns={["icon", "timestamp", 'rule.mitre.id', 'rule.mitre.tactic', 'rule.level', 'rule.id', 'rule.description']} implicitFilters={implicitFilters} initialFilters={[]} updateTotalHits={(total) => this.updateTotalHits(total)}/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiAccordion>
Expand Down
2 changes: 1 addition & 1 deletion public/components/visualize/components/security-alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SecurityAlerts = () => {

return (
<Discover
shareFilterManager={[...((filterManager || {}).filters) || []]}
shareFilterManager={filterManager}
query={query}
initialColumns={["icon", "timestamp", 'rule.mitre.id', 'rule.mitre.tactic', 'rule.description', 'rule.level', 'rule.id']}
implicitFilters={[]}
Expand Down
2 changes: 1 addition & 1 deletion public/kibana-integrations/kibana-discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function discoverController(
next: () => {
//Patch empty fields
const filters = filterManager.getAppFilters();
if(filters.filter(item=>item.meta.params.query==='').length){
if(filters.filter(item=> item.meta.params && item.meta.params.query === '').length){
getToasts().add({
color: 'warning',
title: 'Invalid field value',
Expand Down