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

Remove discover implement embeddable dashboard on aws module #6494

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f67de9b
Migrated visualization to embeddables
yenienserrano Mar 8, 2024
10faa83
Remove old visualizations aws
yenienserrano Mar 8, 2024
fd0a62c
Remove overview-aws imports
yenienserrano Mar 8, 2024
695e9ae
Add Date Picker
yenienserrano Mar 11, 2024
64b4760
Add aws agent dashboard
yenienserrano Mar 11, 2024
357bae1
Remove old aws agent dashboard
yenienserrano Mar 11, 2024
30958e2
revert
yenienserrano Mar 11, 2024
41aaed0
Revert "Remove overview-aws imports"
yenienserrano Mar 11, 2024
bae0309
Revert "Remove old aws agent dashboard"
yenienserrano Mar 11, 2024
4ec23ea
Remove prop unnecessary
yenienserrano Mar 11, 2024
6de29bd
Change legend position
yenienserrano Mar 11, 2024
8743363
Add loading spinner, no result, sample data warning
yenienserrano Mar 14, 2024
fa297c5
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 10, 2024
646568f
feat(aws): use data source on Dashboard and Events tabs
yenienserrano Apr 10, 2024
872634b
render of overview or agent dashboard
yenienserrano Apr 11, 2024
cd60022
Add unsubscribe use-data-source
yenienserrano Apr 11, 2024
5034c0d
Fix DiscoverNoResults render with date change
yenienserrano Apr 11, 2024
22cfc37
Change imports
yenienserrano Apr 16, 2024
ceb8031
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 19, 2024
86db0c5
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 22, 2024
b5374f5
Update dashboard.tsx
yenienserrano Apr 24, 2024
a374f48
Removed unnecessary aws in tabFilters in common-data.js
yenienserrano Apr 24, 2024
9fd58ae
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 25, 2024
4d06f30
Conditional rendering sampledatawarning
yenienserrano Apr 25, 2024
83523d6
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 25, 2024
714d0cf
Conditional rendering sampledatawarning
yenienserrano Apr 25, 2024
6bb0e39
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 25, 2024
23f8962
Update styles.scss
yenienserrano Apr 26, 2024
ec02b1c
Merge branch '4.9.0' into 6493-remove-discover-implement-embeddable-d…
yenienserrano Apr 26, 2024
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 plugins/main/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const DATA_SOURCE_FILTER_CONTROLLED_PINNED_AGENT = 'pinned-agent';
export const DATA_SOURCE_FILTER_CONTROLLED_CLUSTER_MANAGER = 'cluster-manager';
export const DATA_SOURCE_FILTER_CONTROLLED_VULNERABILITIES_RULE_GROUP =
'vulnerabilities-rule-group';
export const DATA_SOURCE_FILTER_CONTROLLED_AWS_RULE_GROUP = 'aws-rule-group';
export const DATA_SOURCE_FILTER_CONTROLLED_VIRUSTOTAL_RULE_GROUP =
'virustotal-rule-group';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,138 +1,152 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState } from 'react';
import {
IDataSourceFactoryConstructor,
tDataSource,
tDataSourceRepository,
tFilter,
tSearchParams,
PatternDataSourceSelector,
PatternDataSourceFactory,
PatternDataSource,
tParsedIndexPattern,
PatternDataSourceFilterManager,
tFilterManager
IDataSourceFactoryConstructor,
tDataSource,
tDataSourceRepository,
tFilter,
tSearchParams,
PatternDataSourceSelector,
PatternDataSourceFactory,
PatternDataSource,
tParsedIndexPattern,
PatternDataSourceFilterManager,
tFilterManager,
} from '../index';

type tUseDataSourceProps<T extends object, K extends PatternDataSource> = {
DataSource: IDataSourceFactoryConstructor<K>;
repository: tDataSourceRepository<T>;
factory?: PatternDataSourceFactory;
filterManager?: tFilterManager;
filters?: tFilter[];
}
DataSource: IDataSourceFactoryConstructor<K>;
repository: tDataSourceRepository<T>;
factory?: PatternDataSourceFactory;
filterManager?: tFilterManager;
filters?: tFilter[];
};

type tUseDataSourceLoadedReturns<K> = {
isLoading: boolean;
dataSource: K;
filters: tFilter[];
fetchFilters: tFilter[];
fixedFilters: tFilter[];
fetchData: (params: Omit<tSearchParams, 'filters'>) => Promise<any>;
setFilters: (filters: tFilter[]) => void;
filterManager: PatternDataSourceFilterManager;
}
isLoading: boolean;
dataSource: K;
filters: tFilter[];
fetchFilters: tFilter[];
fixedFilters: tFilter[];
fetchData: (params: Omit<tSearchParams, 'filters'>) => Promise<any>;
setFilters: (filters: tFilter[]) => void;
filterManager: PatternDataSourceFilterManager;
};

type tUseDataSourceNotLoadedReturns = {
isLoading: boolean;
dataSource: undefined;
filters: [];
fetchFilters: [];
fixedFilters: [];
fetchData: (params: Omit<tSearchParams, 'filters'>) => Promise<any>;
setFilters: (filters: tFilter[]) => void;
filterManager: null;
}
isLoading: boolean;
dataSource: undefined;
filters: [];
fetchFilters: [];
fixedFilters: [];
fetchData: (params: Omit<tSearchParams, 'filters'>) => Promise<any>;
setFilters: (filters: tFilter[]) => void;
filterManager: null;
};

export function useDataSource<T extends tParsedIndexPattern, K extends PatternDataSource>(props: tUseDataSourceProps<T, K>): tUseDataSourceLoadedReturns<K> | tUseDataSourceNotLoadedReturns {
const {
filters: defaultFilters = [],
DataSource: DataSourceConstructor,
repository,
factory: injectedFactory,
} = props;
export function useDataSource<
T extends tParsedIndexPattern,
K extends PatternDataSource,
>(
props: tUseDataSourceProps<T, K>,
): tUseDataSourceLoadedReturns<K> | tUseDataSourceNotLoadedReturns {
const {
filters: defaultFilters = [],
DataSource: DataSourceConstructor,
repository,
factory: injectedFactory,
} = props;

if (!repository || !DataSourceConstructor) {
throw new Error('DataSource and repository are required');
}
if (!repository || !DataSourceConstructor) {
throw new Error('DataSource and repository are required');
}

const [dataSource, setDataSource] = useState<tDataSource>();
const [dataSourceFilterManager, setDataSourceFilterManager] = useState<PatternDataSourceFilterManager | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [fetchFilters, setFetchFilters] = useState<tFilter[]>([]);
const [allFilters, setAllFilters] = useState<tFilter[]>([]);
const [dataSource, setDataSource] = useState<tDataSource>();
const [dataSourceFilterManager, setDataSourceFilterManager] =
useState<PatternDataSourceFilterManager | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [fetchFilters, setFetchFilters] = useState<tFilter[]>([]);
const [allFilters, setAllFilters] = useState<tFilter[]>([]);

const setFilters = (filters: tFilter[]) => {
if (!dataSourceFilterManager) {
return;
}
dataSourceFilterManager?.setFilters(filters);
setAllFilters(dataSourceFilterManager?.getFilters() || []);
setFetchFilters(dataSourceFilterManager?.getFetchFilters() || []);
const setFilters = (filters: tFilter[]) => {
if (!dataSourceFilterManager) {
return;
}
dataSourceFilterManager?.setFilters(filters);
setAllFilters(dataSourceFilterManager?.getFilters() || []);
setFetchFilters(dataSourceFilterManager?.getFetchFilters() || []);
};

const fetchData = async (params: Omit<tSearchParams, 'filters'>) => {
if (!dataSourceFilterManager) {
return
}
return await dataSourceFilterManager?.fetch(params);
const fetchData = async (params: Omit<tSearchParams, 'filters'>) => {
if (!dataSourceFilterManager) {
return;
}
return await dataSourceFilterManager?.fetch(params);
};

useEffect(() => {
init();
}, [])
useEffect(() => {
let subscription;
(async () => {
setIsLoading(true);
const factory = injectedFactory || new PatternDataSourceFactory();
const patternsData = await repository.getAll();
const dataSources = await factory.createAll(
DataSourceConstructor,
patternsData,
);
const selector = new PatternDataSourceSelector(dataSources, repository);
const dataSource = await selector.getSelectedDataSource();
if (!dataSource) {
throw new Error('No valid data source found');
}
setDataSource(dataSource);
const dataSourceFilterManager = new PatternDataSourceFilterManager(
dataSource,
defaultFilters,
);
if (!dataSourceFilterManager) {
throw new Error('Error creating filter manager');
}

const init = async () => {
setIsLoading(true);
const factory = injectedFactory || new PatternDataSourceFactory();
const patternsData = await repository.getAll();
const dataSources = await factory.createAll(DataSourceConstructor, patternsData);
const selector = new PatternDataSourceSelector(dataSources, repository);
const dataSource = await selector.getSelectedDataSource();
if (!dataSource) {
throw new Error('No valid data source found');
}
setDataSource(dataSource);
const dataSourceFilterManager = new PatternDataSourceFilterManager(dataSource, defaultFilters);
if (!dataSourceFilterManager) {
throw new Error('Error creating filter manager');
}
// what the filters update
subscription = dataSourceFilterManager.getUpdates$().subscribe({
next: () => {
// this is necessary to remove the hidden filters from the filter manager and not show them in the search bar
dataSourceFilterManager.setFilters(
dataSourceFilterManager.getFilters(),
);
setAllFilters(dataSourceFilterManager.getFilters());
setFetchFilters(dataSourceFilterManager.getFetchFilters());
},
});
setAllFilters(dataSourceFilterManager.getFilters());
setFetchFilters(dataSourceFilterManager.getFetchFilters());
setDataSourceFilterManager(dataSourceFilterManager);
setIsLoading(false);
})();
return () => subscription.unsubscribe();
}, []);

// what the filters update
dataSourceFilterManager.getUpdates$().subscribe({
next: () => {
// this is necessary to remove the hidden filters from the filter manager and not show them in the search bar
dataSourceFilterManager.setFilters(dataSourceFilterManager.getFilters());
setAllFilters(dataSourceFilterManager.getFilters());
setFetchFilters(dataSourceFilterManager.getFetchFilters());
},
});
setAllFilters(dataSourceFilterManager.getFilters());
setFetchFilters(dataSourceFilterManager.getFetchFilters());
setDataSourceFilterManager(dataSourceFilterManager);
setIsLoading(false);
}

if (isLoading) {
return {
isLoading: true,
dataSource: undefined,
filters: [],
fetchFilters: [],
fixedFilters: [],
fetchData,
setFilters,
filterManager: null
}
}else{
return {
isLoading: false,
dataSource: dataSource as K,
filters: allFilters,
fetchFilters,
fixedFilters: dataSourceFilterManager?.getFixedFilters() || [],
fetchData,
setFilters,
filterManager: dataSourceFilterManager as PatternDataSourceFilterManager
}
}
}
if (isLoading) {
return {
isLoading: true,
dataSource: undefined,
filters: [],
fetchFilters: [],
fixedFilters: [],
fetchData,
setFilters,
filterManager: null,
};
} else {
return {
isLoading: false,
dataSource: dataSource as K,
filters: allFilters,
fetchFilters,
fixedFilters: dataSourceFilterManager?.getFixedFilters() || [],
fetchData,
setFilters,
filterManager: dataSourceFilterManager as PatternDataSourceFilterManager,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { tFilter } from '../../../index';
import { DATA_SOURCE_FILTER_CONTROLLED_AWS_RULE_GROUP } from '../../../../../../../common/constants';
import { AlertsDataSource } from '../alerts-data-source';

const AWS_GROUP_KEY = 'rule.groups';
const AWS_GROUP_VALUE = 'amazon';

export class AlertsAWSDataSource extends AlertsDataSource {
constructor(id: string, title: string) {
super(id, title);
}

getRuleGroupsFilter() {
return super.getRuleGroupsFilter(
AWS_GROUP_KEY,
AWS_GROUP_VALUE,
DATA_SOURCE_FILTER_CONTROLLED_AWS_RULE_GROUP,
);
}

getFixedFilters(): tFilter[] {
return [...this.getRuleGroupsFilter(), ...super.getFixedFilters()];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './alerts-aws-data-source';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './alerts-vulnerabilities';
export * from './alerts-data-source-repository';
export * from './alerts-data-source';
export * from './alerts-aws';
export * from './alerts-virustotal';
14 changes: 12 additions & 2 deletions plugins/main/public/components/common/modules/modules-defaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
import { Dashboard } from './dashboard';
import { MainSca } from '../../agents/sca';
import { DashboardAWS } from '../../overview/amazon-web-services/dashboards';
import { MainMitre } from './main-mitre';
import { MainFim } from '../../agents/fim';
import { ModuleMitreAttackIntelligence } from '../../overview/mitre_attack_intelligence';
Expand Down Expand Up @@ -50,6 +51,7 @@ import {
AlertsDataSource,
AlertsVulnerabilitiesDataSource,
AlertsVirustotalDataSource,
AlertsAWSDataSource,
} from '../data-source';

const ALERTS_INDEX_PATTERN = 'wazuh-alerts-*';
Expand Down Expand Up @@ -117,8 +119,16 @@ export const ModulesDefaults = {
aws: {
init: 'dashboard',
tabs: [
DashboardTab,
renderDiscoverTab(DEFAULT_INDEX_PATTERN, amazonWebServicesColumns),
{
id: 'dashboard',
name: 'Dashboard',
buttons: [ButtonModuleExploreAgent, ButtonModuleGenerateReport],
component: DashboardAWS,
},
renderDiscoverTab({
tableColumns: amazonWebServicesColumns,
DataSource: AlertsAWSDataSource,
}),
],
availableFor: ['manager', 'agent'],
},
Expand Down
Loading
Loading