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 Threat Hunting module #6486

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2b6e8f0
Migrated visualizations to embeddables
jbiset Mar 6, 2024
07776d3
Added withPinnedAgent HOC
jbiset Mar 7, 2024
ba0e78a
Added dashboard update mechanism depending on whether or not an agent…
jbiset Mar 7, 2024
978d3a5
Pinned agent visualization definitions are migrated and aesthetic adj…
jbiset Mar 8, 2024
871352c
The interaction was added to the KPIs, the links to the lower table w…
jbiset Mar 13, 2024
64e1ce1
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Mar 13, 2024
66af0cf
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Mar 15, 2024
b43f524
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 18, 2024
a0c8360
Integrated new data source on Threat Hunting module
jbiset Apr 18, 2024
3bef252
DiscoverNoResults and LoadingSpinner components are replaced with com…
jbiset Apr 19, 2024
af1bb88
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 22, 2024
5c6ff8b
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 22, 2024
d110c86
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 22, 2024
30d8ffd
Clean code and fixed dashboards conditions
jbiset Apr 22, 2024
b411272
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 23, 2024
e25b059
Improved condition for rendering the dashboard and SampleData message
jbiset Apr 23, 2024
cb4fe29
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 23, 2024
18d7bf6
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
jbiset Apr 24, 2024
198c17a
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
yenienserrano Apr 24, 2024
4ac01ff
Removed unnecessary general/threat hunting in tabFilters in common da…
jbiset Apr 24, 2024
c090a53
Removed unused getImplicitPinnedAgent in modules-helper
jbiset Apr 24, 2024
52da83e
Added dateRange param to fetchData in dashboard useEffect, added wz-d…
jbiset Apr 24, 2024
ffa1282
Deleted unnecessary wz-discover class on SearchBar wrapper
jbiset Apr 24, 2024
05419b9
Changed Threat Hunting columns file name
jbiset Apr 24, 2024
e8611aa
Deleted unused imports in modules-helper
jbiset Apr 24, 2024
19f48ef
Merge branch '4.9.0' into 6478-remove-discover-implement-embeddable-d…
asteriscos Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions plugins/main/public/components/common/modules/modules-defaults.tsx
Expand Up @@ -27,6 +27,7 @@ import {
} from '../wazuh-discover/wz-discover';
import { threatHuntingColumns } from '../wazuh-discover/config/data-grid-columns';
import { vulnerabilitiesColumns } from '../../overview/vulnerabilities/events/vulnerabilities-columns';
import { DashboardThreatHunting } from '../../overview/threat-hunting/dashboard/dashboard';
import React from 'react';
import { dockerColumns } from '../../overview/docker/events/docker-columns';
import { googleCloudColumns } from '../../overview/google-cloud/events/google-cloud-columns';
Expand All @@ -44,7 +45,10 @@ import { mitreAttackColumns } from '../../overview/mitre/events/mitre-attack-col
import { virustotalColumns } from '../../overview/virustotal/events/virustotal-columns';
import { malwareDetectionColumns } from '../../overview/malware-detection/events/malware-detection-columns';
import { WAZUH_VULNERABILITIES_PATTERN } from '../../../../common/constants';
import { AlertsVulnerabilitiesDataSource } from '../data-source';
import {
AlertsDataSource,
jbiset marked this conversation as resolved.
Show resolved Hide resolved
AlertsVulnerabilitiesDataSource,
} from '../data-source';

const ALERTS_INDEX_PATTERN = 'wazuh-alerts-*';
const DEFAULT_INDEX_PATTERN = ALERTS_INDEX_PATTERN;
Expand Down Expand Up @@ -81,8 +85,16 @@ export const ModulesDefaults = {
general: {
init: 'events',
tabs: [
DashboardTab,
renderDiscoverTab(DEFAULT_INDEX_PATTERN, threatHuntingColumns),
{
id: 'dashboard',
name: 'Dashboard',
buttons: [ButtonModuleExploreAgent, ButtonModuleGenerateReport],
component: DashboardThreatHunting,
},
renderDiscoverTab({
tableColumns: threatHuntingColumns,
DataSource: AlertsDataSource,
}),
],
availableFor: ['manager', 'agent'],
},
Expand Down
57 changes: 57 additions & 0 deletions plugins/main/public/components/common/modules/modules-helper.js
Expand Up @@ -2,6 +2,8 @@ import { getAngularModule, getDataPlugin } from '../../../kibana-services';
import { AppState } from '../../../react-services/app-state';
import { FilterHandler } from '../../../utils/filter-handler';
import { VULNERABILITY_IMPLICIT_CLUSTER_MODE_FILTER } from '../../../../common/constants';
import { useFilterManager } from '../hooks';
import { FilterStateStore } from '../../../../../../src/plugins/data/common';
jbiset marked this conversation as resolved.
Show resolved Hide resolved

export class ModulesHelper {
static async getDiscoverScope() {
Expand Down Expand Up @@ -182,4 +184,59 @@ If this case happens, the implicit filters are regenerated and the function is c

return filters;
}

/**
*
* @param {string} indexPattern - Index pattern id being used
* @param {Filter[] | undefined} filters - (Optional) Filter Array in which to search if a pinned agent exists
* @returns
*/
static getImplicitPinnedAgent(indexPattern, filters = []) {
const filterManager = useFilterManager().filterManager;
const initialFilters =
filters?.length > 0 ? filters : filterManager.getFilters();
const pinnedAgentByFilterManager = initialFilters.find(
filter =>
filter?.meta?.key === 'agent.id' && !!filter?.$state?.isImplicit,
);
const url = window.location.href;
const regex = new RegExp('agentId=' + '[^&]*');
const match = url.match(regex);
const isPinnedAgentByUrl = match && match[0];
if (pinnedAgentByFilterManager && isPinnedAgentByUrl) {
return {
...pinnedAgentByFilterManager,
meta: {
...pinnedAgentByFilterManager.meta,
index: indexPattern,
},
$state: { store: FilterStateStore.APP_STATE, isImplicit: true },
};
}

if (isPinnedAgentByUrl) {
const agentId = match[0].split('=')[1];
return {
meta: {
alias: null,
disabled: false,
key: 'agent.id',
negate: false,
params: { query: agentId },
type: 'phrase',
index: indexPattern,
},
query: {
match: {
'agent.id': {
query: agentId,
type: 'phrase',
},
},
},
$state: { store: 'appState', isImplicit: true },
};
}
return undefined;
}
jbiset marked this conversation as resolved.
Show resolved Hide resolved
}
jbiset marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,121 @@
import { EuiDataGridColumn, EuiLink } from '@elastic/eui';
import { tDataGridColumn } from '../../../common/data-grid';
import { getCore } from '../../../../kibana-services';
import React from 'react';
import { RedirectAppLinks } from '../../../../../../../src/plugins/opensearch_dashboards_react/public';

export const MAX_ENTRIES_PER_QUERY = 10000;

export const threatHuntingTableDefaultColumns: tDataGridColumn[] = [
{
id: 'icon',
},
{
id: 'timestamp',
},
{
id: 'agent.id',
render: (value: any) => {
const destURL = getCore().application.getUrlForApp('endpoints-summary', {
path: `#/agents?tab=welcome&agent=${value}`,
});
return (
<RedirectAppLinks application={getCore().application}>
<EuiLink href={destURL} style={{ cursor: 'pointer' }}>
{value}
</EuiLink>
</RedirectAppLinks>
);
},
},
{
id: 'agent.name',
},
{
id: 'rule.mitre.id',
render: (value: any) => {
const destURL = getCore().application.getUrlForApp('mitre-attack', {
path: `#/overview/?tab=mitre&tabView=intelligence&tabRedirect=techniques&idToRedirect=${value}`,
});
return (
<RedirectAppLinks application={getCore().application}>
<EuiLink href={destURL} style={{ cursor: 'pointer' }}>
{value}
</EuiLink>
</RedirectAppLinks>
);
},
},
{
id: 'rule.mitre.tactic',
},
{
id: 'rule.description',
},
{
id: 'rule.level',
},
{
id: 'rule.id',
render: (value: any) => {
const destURL = getCore().application.getUrlForApp('rules', {
path: `manager/?tab=ruleset&redirectRule=${value}`,
});
return (
<RedirectAppLinks application={getCore().application}>
<EuiLink href={destURL} style={{ cursor: 'pointer' }}>
{value}
</EuiLink>
</RedirectAppLinks>
);
},
},
];

export const threatHuntingTableAgentColumns: EuiDataGridColumn[] = [
{
id: 'icon',
},
{
id: 'timestamp',
},
{
id: 'rule.mitre.id',
render: (value: any) => {
const destURL = getCore().application.getUrlForApp('mitre-attack', {
path: `#/overview/?tab=mitre&tabView=intelligence&tabRedirect=techniques&idToRedirect=${value}`,
});
return (
<RedirectAppLinks application={getCore().application}>
<EuiLink href={destURL} style={{ cursor: 'pointer' }}>
{value}
</EuiLink>
</RedirectAppLinks>
);
},
},
{
id: 'rule.mitre.tactic',
},
{
id: 'rule.description',
},
{
id: 'rule.level',
},
{
id: 'rule.id',
render: (value: any) => {
const destURL = getCore().application.getUrlForApp('rules', {
path: `manager/?tab=ruleset&redirectRule=${value}`,
});
return (
<RedirectAppLinks application={getCore().application}>
<EuiLink href={destURL} style={{ cursor: 'pointer' }}>
{value}
</EuiLink>
</RedirectAppLinks>
);
},
},
];