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

Fix Alerts Summary table truncated results #5131

Merged
merged 5 commits into from
Jan 25, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Changed

- Changed the HTTP verb from `GET` to `POST` in the requests to login to the Wazuh API [#4103](https://github.com/wazuh/wazuh-kibana-app/pull/4103)
- Improved alerts summary performance [#4376](https://github.com/wazuh/wazuh-kibana-app/pull/4376) [#5071](https://github.com/wazuh/wazuh-kibana-app/pull/5071)
- Improved alerts summary performance [#4376](https://github.com/wazuh/wazuh-kibana-app/pull/4376) [#5071](https://github.com/wazuh/wazuh-kibana-app/pull/5071) [#5131](https://github.com/wazuh/wazuh-kibana-app/pull/5131)
- Improved Agents Overview performance [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363) [#5076](https://github.com/wazuh/wazuh-kibana-app/pull/5076)
- Improved the message displayed when there is a versions mismatch between the Wazuh API and the Wazuh APP [#4529](https://github.com/wazuh/wazuh-kibana-app/pull/4529) [#4964](https://github.com/wazuh/wazuh-kibana-app/pull/4964)
- Independently load each dashboard from the `Agents Overview` page [#4363](https://github.com/wazuh/wazuh-kibana-app/pull/4363)
Expand Down
26 changes: 17 additions & 9 deletions server/controllers/wazuh-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ import {
import { createDirectoryIfNotExists, createDataDirectoryIfNotExists } from '../lib/filesystem';
import { agentStatusLabelByAgentStatus } from '../../common/services/wz_agent_status';

interface AgentsFilter {
query: any;
agentsText: string;
}

export class WazuhReportingCtrl {
constructor() {}
/**
* This do format to filters
* @param {String} filters E.g: cluster.name: wazuh AND rule.groups: vulnerability
* @param {String} searchBar search term
*/
private sanitizeKibanaFilters(filters: any, searchBar?: string): [string, string] {
private sanitizeKibanaFilters(filters: any, searchBar?: string): [string, AgentsFilter] {
log('reporting:sanitizeKibanaFilters', `Started to sanitize filters`, 'info');
log(
'reporting:sanitizeKibanaFilters',
Expand All @@ -46,12 +51,14 @@ export class WazuhReportingCtrl {
);
let str = '';

const agentsFilter: any = [];
const agentsFilter: AgentsFilter = { query: {}, agentsText: '' };
const agentsList: string[] = [];

//separate agents filter
filters = filters.filter((filter) => {
if (filter.meta.controlledBy === AUTHORIZED_AGENTS) {
agentsFilter.push(filter);
agentsFilter.query = filter.query;
agentsList.push(filter);
return false;
}
return filter;
Expand Down Expand Up @@ -81,15 +88,15 @@ export class WazuhReportingCtrl {
str += ` AND (${ searchBar})`;
}

const agentsFilterStr = agentsFilter.map((filter) => filter.meta.value).join(',');
agentsFilter.agentsText = agentsList.map((filter) => filter.meta.value).join(',');

log(
'reporting:sanitizeKibanaFilters',
`str: ${str}, agentsFilterStr: ${agentsFilterStr}`,
`str: ${str}, agentsFilterStr: ${agentsFilter.agentsText}`,
'debug'
);

return [str, agentsFilterStr];
return [str, agentsFilter];
}

/**
Expand Down Expand Up @@ -305,7 +312,7 @@ export class WazuhReportingCtrl {

const [sanitizedFilters, agentsFilter] = filters
? this.sanitizeKibanaFilters(filters, searchBar)
: [false, false];
: [false, null];

if (time && sanitizedFilters) {
printer.addTimeRangeAndFilters(from, to, sanitizedFilters, browserTimezone);
Expand All @@ -321,6 +328,7 @@ export class WazuhReportingCtrl {
new Date(from).getTime(),
new Date(to).getTime(),
sanitizedFilters,
agentsFilter,
indexPatternTitle,
agents
);
Expand All @@ -333,8 +341,8 @@ export class WazuhReportingCtrl {
}

//add authorized agents
if (agentsFilter) {
printer.addAgentsFilters(agentsFilter);
if (agentsFilter?.agentsText) {
printer.addAgentsFilters(agentsFilter.agentsText);
}

await printer.print(context.wazuhEndpointParams.pathFilename);
Expand Down
13 changes: 8 additions & 5 deletions server/lib/reporting/audit-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export const getTop3AgentsSudoNonSuccessful = async (
gte,
lte,
filters,
allowedAgentsFilter,
pattern = getSettingDefaultValue('pattern')
) => {
try {
const base = {};

Object.assign(base, Base(pattern, filters, gte, lte));
Object.assign(base, Base(pattern, filters, gte, lte, allowedAgentsFilter));

Object.assign(base.aggs, {
'3': {
Expand Down Expand Up @@ -93,12 +94,13 @@ export const getTop3AgentsFailedSyscalls = async (
gte,
lte,
filters,
allowedAgentsFilter,
pattern = getSettingDefaultValue('pattern')
) => {
try {
const base = {};

Object.assign(base, Base(pattern, filters, gte, lte));
Object.assign(base, Base(pattern, filters, gte, lte, allowedAgentsFilter));

Object.assign(base.aggs, {
'3': {
Expand Down Expand Up @@ -138,7 +140,7 @@ export const getTop3AgentsFailedSyscalls = async (
const { buckets } = response.body.aggregations['3'];

return buckets.map(bucket => {
try{
try {
const agent = bucket.key;
const syscall = {
id: bucket['4'].buckets[0].key,
Expand All @@ -150,7 +152,7 @@ export const getTop3AgentsFailedSyscalls = async (
agent,
syscall
};
}catch(error){
} catch (error) {
return undefined;
}
}).filter(bucket => bucket);
Expand All @@ -172,12 +174,13 @@ export const getTopFailedSyscalls = async (
gte,
lte,
filters,
allowedAgentsFilter,
pattern = getSettingDefaultValue('pattern')
) => {
try {
const base = {};

Object.assign(base, Base(pattern, filters, gte, lte));
Object.assign(base, Base(pattern, filters, gte, lte, allowedAgentsFilter));

Object.assign(base.aggs, {
'2': {
Expand Down
14 changes: 11 additions & 3 deletions server/lib/reporting/base-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
*
* Find more information about this on the LICENSE file.
*/
export function Base(pattern: string, filters: any, gte: number, lte: number) {
return {
export function Base(pattern: string, filters: any, gte: number, lte: number, allowedAgentsFilter: any = null) {
const base = {
// index: pattern,

from: 0,
size: 500,
aggs: {},
Expand Down Expand Up @@ -42,4 +42,12 @@ export function Base(pattern: string, filters: any, gte: number, lte: number) {
}
}
};

//Add allowed agents filter
if(allowedAgentsFilter?.query?.bool){
base.query.bool.minimum_should_match = allowedAgentsFilter.query.bool.minimum_should_match;
base.query.bool.should = allowedAgentsFilter.query.bool.should;
}

return base;
}
Loading