Skip to content

Commit a8cf4eb

Browse files
[8.x] [Security Solution] [Attack discovery] Alerts filtering (#205070) (#205137)
# Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution] [Attack discovery] Alerts filtering (#205070)](#205070) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Andrew Macri","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-24T10:49:10Z","message":"[Security Solution] [Attack discovery] Alerts filtering (#205070)\n\n## [Security Solution] [Attack discovery] Alerts filtering\r\n\r\n![00_alerts_filtering](https://github.com/user-attachments/assets/1a81413b-b8f4-4965-a006-25fb529668a6)\r\n\r\nThis PR enhances _Attack discovery_ by providing users additional control over which alerts are included as context to the large language model (LLM).\r\n\r\nUsing the new resizeable _Attack discovery settings flyout_, users may:\r\n\r\n- Filter alerts via a search bar and filters\r\n- Control the time window (previously fixed to `Last 24 hrs`)\r\n\r\n### Before (feature flag disabled)\r\n\r\nPreviously, users could only set the number of alerts sent as context to the LLM via a modal:\r\n\r\n![01_before_full_page](https://github.com/user-attachments/assets/65eaf604-3bdf-41bd-a726-f03ba5d630d5)\r\n\r\n### After (feature flag enabled)\r\n\r\nThe new Attack discovery settings flyout replaces the modal:\r\n\r\n![02_alert_summary_full_page](https://github.com/user-attachments/assets/613c292b-c6ec-4dc6-aea3-b2eddbacd614)\r\n\r\nIt has two tabs, _Alert summary_ and _Alerts preview_.\r\n\r\n### Alert summary\r\n\r\nThe _Alert summary_ Lens embeddable counts the selected field name via an ES|QL query:\r\n\r\n![03_alert_summary_cropped](https://github.com/user-attachments/assets/6f5de0e4-3da6-4937-a3cd-9a0f80df16b6)\r\n\r\nThe Alert summary query is an aggregation. It does NOT display the details of individual alerts.\r\n\r\n### Alerts preview\r\n\r\nThe _Alerts preview_ Lens embeddable shows a preview of the actual alerts that will be sent as context via an ES|QL query:\r\n\r\n![05_alerts_preview_cropped](https://github.com/user-attachments/assets/6db23931-3fe6-46d2-8b9a-6cc7a9d8720c)\r\n\r\nUsers may resize the settings flyout to view all the fields in the Alerts preview.\r\n\r\n### Feature flag\r\n\r\nEnable the `attackDiscoveryAlertFiltering` feature flag via the following setting in `kibana.dev.yml`:\r\n\r\n```yaml\r\nxpack.securitySolution.enableExperimental:\r\n - 'attackDiscoveryAlertFiltering'\r\n```\r\n\r\nEnabling the feature flag:\r\n\r\n- Replaces the `Settings` modal with the `Attack discovery settings` flyout\r\n- Includes additional `start`, `end`, and `filters` parameters in requests to generate Attack discoveries\r\n- Enables new loading messages\r\n\r\n### Details\r\n\r\n#### Loading messages\r\n\r\nThe loading messages displayed when generating Attack discoveries were updated to render three types of date ranges:\r\n\r\n1) The default date range (`Last 24 hours`), which displays the same message seen in previous versions:\r\n\r\n![06_loading_default_date_range](https://github.com/user-attachments/assets/b376a87c-b4b8-42d8-bcbf-ddf79cc82800)\r\n\r\n2) Relative date ranges:\r\n\r\n![07_loading_relative_date_range](https://github.com/user-attachments/assets/d0b6bddd-7722-4181-a99c-7450d07a6624)\r\n\r\n3) Absolute date ranges:\r\n\r\n![08_loading_absolute_date_range](https://github.com/user-attachments/assets/a542a921-eeaa-4ced-9568-25e63a47d42d)\r\n\r\n#### Filtering preferences\r\n\r\nAlert filtering preferences are stored in local storage.\r\n\r\nThis PR adds the following new local storage keys:\r\n\r\n```\r\nelasticAssistantDefault.attackDiscovery.default.end\r\nelasticAssistantDefault.attackDiscovery.default.filters\r\nelasticAssistantDefault.attackDiscovery.default.query\r\nelasticAssistantDefault.attackDiscovery.default.start\r\n```\r\n\r\nUsers may use the `Reset` button in the Attack discovery settings flyout to restore the above to their defaults.\r\n\r\n#### Known limitations\r\n\r\nThe following known limitations in this PR may be mitigated in follow-up PRs:\r\n\r\n#### Table cell hover actions are disabled\r\n\r\nTable cell actions, i.e. `Filter for` and `Filter out` are disabled in the `Alert summary` and `Alerts preview` tables.\r\n\r\nThe actions are disabled because custom cell hover actions registered in `x-pack/solutions/security/plugins/security_solution/public/app/actions/register.ts` do NOT appear to receive field metadata (i.e. the name of the field being hovered over) when the action is triggered. This limitation also appears to apply to ad hoc ES|QL visualizations created via Lens in Kibana's _Dashboard_ app.\r\n\r\n##### Default table sort indicators are hidden\r\n\r\nThe `Alert summary` and `Alerts preview` tables are sorted descending by Count, and Risk score, respectively, via their ES|QL queries.\r\n\r\nThe tables _should_ display default sort indicators, as illustrated by the screenshots below:\r\n\r\n![09_alert_summary_with_sort_indicator](https://github.com/user-attachments/assets/c4e78144-f516-40f8-b6da-7c8c808841c4)\r\n\r\n![10_alerts_preview_with_sort_indicator](https://github.com/user-attachments/assets/c0061134-4734-462f-8eb0-978b2b02fb1e)\r\n\r\nThe default indicators are hidden in this PR as a workaround for an error that occurs in `EuiDataGrid` when switching tabs when the column sort indicators are enabled:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined (reading 'split')\r\n```\r\n\r\nTo re-enable the sort indicators, `DEFAULT_ALERT_SUMMARY_SORT` and `DEFAULT_ALERTS_PREVIEW_SORT` must respectively be passed as the `sorting` prop to the `PreviewTab` in `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/helpers/get_tabs/index.tsx`, as illustrated by the following code:\r\n\r\n```typescript\r\n <PreviewTab\r\n dataTestSubj={ALERT_SUMMARY_TEST_SUBJ}\r\n embeddableId={SUMMARY_TAB_EMBEDDABLE_ID}\r\n end={end}\r\n filters={filters}\r\n getLensAttributes={getAlertSummaryLensAttributes}\r\n getPreviewEsqlQuery={getAlertSummaryEsqlQuery}\r\n maxAlerts={maxAlerts}\r\n query={query}\r\n setTableStackBy0={setAlertSummaryStackBy0}\r\n start={start}\r\n sorting={DEFAULT_ALERT_SUMMARY_SORT} // <-- enables the sort indicator\r\n tableStackBy0={alertSummaryStackBy0}\r\n />\r\n```\r\n\r\n##### Selected date range not persisted\r\n\r\nThe `start` and `end` date range selected when a user starts generation are not (yet) persisted in Elasticsearch. As a result, the loading message always displays the currently configured range, rather than the range selected at the start of generation.","sha":"681d40eee64316bea85d04077f918bd7121988b9","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","Team: SecuritySolution","ci:cloud-deploy","ci:cloud-persist-deployment","Team:Security Generative AI","backport:version","v8.18.0"],"title":"[Security Solution] [Attack discovery] Alerts filtering","number":205070,"url":"https://github.com/elastic/kibana/pull/205070","mergeCommit":{"message":"[Security Solution] [Attack discovery] Alerts filtering (#205070)\n\n## [Security Solution] [Attack discovery] Alerts filtering\r\n\r\n![00_alerts_filtering](https://github.com/user-attachments/assets/1a81413b-b8f4-4965-a006-25fb529668a6)\r\n\r\nThis PR enhances _Attack discovery_ by providing users additional control over which alerts are included as context to the large language model (LLM).\r\n\r\nUsing the new resizeable _Attack discovery settings flyout_, users may:\r\n\r\n- Filter alerts via a search bar and filters\r\n- Control the time window (previously fixed to `Last 24 hrs`)\r\n\r\n### Before (feature flag disabled)\r\n\r\nPreviously, users could only set the number of alerts sent as context to the LLM via a modal:\r\n\r\n![01_before_full_page](https://github.com/user-attachments/assets/65eaf604-3bdf-41bd-a726-f03ba5d630d5)\r\n\r\n### After (feature flag enabled)\r\n\r\nThe new Attack discovery settings flyout replaces the modal:\r\n\r\n![02_alert_summary_full_page](https://github.com/user-attachments/assets/613c292b-c6ec-4dc6-aea3-b2eddbacd614)\r\n\r\nIt has two tabs, _Alert summary_ and _Alerts preview_.\r\n\r\n### Alert summary\r\n\r\nThe _Alert summary_ Lens embeddable counts the selected field name via an ES|QL query:\r\n\r\n![03_alert_summary_cropped](https://github.com/user-attachments/assets/6f5de0e4-3da6-4937-a3cd-9a0f80df16b6)\r\n\r\nThe Alert summary query is an aggregation. It does NOT display the details of individual alerts.\r\n\r\n### Alerts preview\r\n\r\nThe _Alerts preview_ Lens embeddable shows a preview of the actual alerts that will be sent as context via an ES|QL query:\r\n\r\n![05_alerts_preview_cropped](https://github.com/user-attachments/assets/6db23931-3fe6-46d2-8b9a-6cc7a9d8720c)\r\n\r\nUsers may resize the settings flyout to view all the fields in the Alerts preview.\r\n\r\n### Feature flag\r\n\r\nEnable the `attackDiscoveryAlertFiltering` feature flag via the following setting in `kibana.dev.yml`:\r\n\r\n```yaml\r\nxpack.securitySolution.enableExperimental:\r\n - 'attackDiscoveryAlertFiltering'\r\n```\r\n\r\nEnabling the feature flag:\r\n\r\n- Replaces the `Settings` modal with the `Attack discovery settings` flyout\r\n- Includes additional `start`, `end`, and `filters` parameters in requests to generate Attack discoveries\r\n- Enables new loading messages\r\n\r\n### Details\r\n\r\n#### Loading messages\r\n\r\nThe loading messages displayed when generating Attack discoveries were updated to render three types of date ranges:\r\n\r\n1) The default date range (`Last 24 hours`), which displays the same message seen in previous versions:\r\n\r\n![06_loading_default_date_range](https://github.com/user-attachments/assets/b376a87c-b4b8-42d8-bcbf-ddf79cc82800)\r\n\r\n2) Relative date ranges:\r\n\r\n![07_loading_relative_date_range](https://github.com/user-attachments/assets/d0b6bddd-7722-4181-a99c-7450d07a6624)\r\n\r\n3) Absolute date ranges:\r\n\r\n![08_loading_absolute_date_range](https://github.com/user-attachments/assets/a542a921-eeaa-4ced-9568-25e63a47d42d)\r\n\r\n#### Filtering preferences\r\n\r\nAlert filtering preferences are stored in local storage.\r\n\r\nThis PR adds the following new local storage keys:\r\n\r\n```\r\nelasticAssistantDefault.attackDiscovery.default.end\r\nelasticAssistantDefault.attackDiscovery.default.filters\r\nelasticAssistantDefault.attackDiscovery.default.query\r\nelasticAssistantDefault.attackDiscovery.default.start\r\n```\r\n\r\nUsers may use the `Reset` button in the Attack discovery settings flyout to restore the above to their defaults.\r\n\r\n#### Known limitations\r\n\r\nThe following known limitations in this PR may be mitigated in follow-up PRs:\r\n\r\n#### Table cell hover actions are disabled\r\n\r\nTable cell actions, i.e. `Filter for` and `Filter out` are disabled in the `Alert summary` and `Alerts preview` tables.\r\n\r\nThe actions are disabled because custom cell hover actions registered in `x-pack/solutions/security/plugins/security_solution/public/app/actions/register.ts` do NOT appear to receive field metadata (i.e. the name of the field being hovered over) when the action is triggered. This limitation also appears to apply to ad hoc ES|QL visualizations created via Lens in Kibana's _Dashboard_ app.\r\n\r\n##### Default table sort indicators are hidden\r\n\r\nThe `Alert summary` and `Alerts preview` tables are sorted descending by Count, and Risk score, respectively, via their ES|QL queries.\r\n\r\nThe tables _should_ display default sort indicators, as illustrated by the screenshots below:\r\n\r\n![09_alert_summary_with_sort_indicator](https://github.com/user-attachments/assets/c4e78144-f516-40f8-b6da-7c8c808841c4)\r\n\r\n![10_alerts_preview_with_sort_indicator](https://github.com/user-attachments/assets/c0061134-4734-462f-8eb0-978b2b02fb1e)\r\n\r\nThe default indicators are hidden in this PR as a workaround for an error that occurs in `EuiDataGrid` when switching tabs when the column sort indicators are enabled:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined (reading 'split')\r\n```\r\n\r\nTo re-enable the sort indicators, `DEFAULT_ALERT_SUMMARY_SORT` and `DEFAULT_ALERTS_PREVIEW_SORT` must respectively be passed as the `sorting` prop to the `PreviewTab` in `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/helpers/get_tabs/index.tsx`, as illustrated by the following code:\r\n\r\n```typescript\r\n <PreviewTab\r\n dataTestSubj={ALERT_SUMMARY_TEST_SUBJ}\r\n embeddableId={SUMMARY_TAB_EMBEDDABLE_ID}\r\n end={end}\r\n filters={filters}\r\n getLensAttributes={getAlertSummaryLensAttributes}\r\n getPreviewEsqlQuery={getAlertSummaryEsqlQuery}\r\n maxAlerts={maxAlerts}\r\n query={query}\r\n setTableStackBy0={setAlertSummaryStackBy0}\r\n start={start}\r\n sorting={DEFAULT_ALERT_SUMMARY_SORT} // <-- enables the sort indicator\r\n tableStackBy0={alertSummaryStackBy0}\r\n />\r\n```\r\n\r\n##### Selected date range not persisted\r\n\r\nThe `start` and `end` date range selected when a user starts generation are not (yet) persisted in Elasticsearch. As a result, the loading message always displays the currently configured range, rather than the range selected at the start of generation.","sha":"681d40eee64316bea85d04077f918bd7121988b9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205070","number":205070,"mergeCommit":{"message":"[Security Solution] [Attack discovery] Alerts filtering (#205070)\n\n## [Security Solution] [Attack discovery] Alerts filtering\r\n\r\n![00_alerts_filtering](https://github.com/user-attachments/assets/1a81413b-b8f4-4965-a006-25fb529668a6)\r\n\r\nThis PR enhances _Attack discovery_ by providing users additional control over which alerts are included as context to the large language model (LLM).\r\n\r\nUsing the new resizeable _Attack discovery settings flyout_, users may:\r\n\r\n- Filter alerts via a search bar and filters\r\n- Control the time window (previously fixed to `Last 24 hrs`)\r\n\r\n### Before (feature flag disabled)\r\n\r\nPreviously, users could only set the number of alerts sent as context to the LLM via a modal:\r\n\r\n![01_before_full_page](https://github.com/user-attachments/assets/65eaf604-3bdf-41bd-a726-f03ba5d630d5)\r\n\r\n### After (feature flag enabled)\r\n\r\nThe new Attack discovery settings flyout replaces the modal:\r\n\r\n![02_alert_summary_full_page](https://github.com/user-attachments/assets/613c292b-c6ec-4dc6-aea3-b2eddbacd614)\r\n\r\nIt has two tabs, _Alert summary_ and _Alerts preview_.\r\n\r\n### Alert summary\r\n\r\nThe _Alert summary_ Lens embeddable counts the selected field name via an ES|QL query:\r\n\r\n![03_alert_summary_cropped](https://github.com/user-attachments/assets/6f5de0e4-3da6-4937-a3cd-9a0f80df16b6)\r\n\r\nThe Alert summary query is an aggregation. It does NOT display the details of individual alerts.\r\n\r\n### Alerts preview\r\n\r\nThe _Alerts preview_ Lens embeddable shows a preview of the actual alerts that will be sent as context via an ES|QL query:\r\n\r\n![05_alerts_preview_cropped](https://github.com/user-attachments/assets/6db23931-3fe6-46d2-8b9a-6cc7a9d8720c)\r\n\r\nUsers may resize the settings flyout to view all the fields in the Alerts preview.\r\n\r\n### Feature flag\r\n\r\nEnable the `attackDiscoveryAlertFiltering` feature flag via the following setting in `kibana.dev.yml`:\r\n\r\n```yaml\r\nxpack.securitySolution.enableExperimental:\r\n - 'attackDiscoveryAlertFiltering'\r\n```\r\n\r\nEnabling the feature flag:\r\n\r\n- Replaces the `Settings` modal with the `Attack discovery settings` flyout\r\n- Includes additional `start`, `end`, and `filters` parameters in requests to generate Attack discoveries\r\n- Enables new loading messages\r\n\r\n### Details\r\n\r\n#### Loading messages\r\n\r\nThe loading messages displayed when generating Attack discoveries were updated to render three types of date ranges:\r\n\r\n1) The default date range (`Last 24 hours`), which displays the same message seen in previous versions:\r\n\r\n![06_loading_default_date_range](https://github.com/user-attachments/assets/b376a87c-b4b8-42d8-bcbf-ddf79cc82800)\r\n\r\n2) Relative date ranges:\r\n\r\n![07_loading_relative_date_range](https://github.com/user-attachments/assets/d0b6bddd-7722-4181-a99c-7450d07a6624)\r\n\r\n3) Absolute date ranges:\r\n\r\n![08_loading_absolute_date_range](https://github.com/user-attachments/assets/a542a921-eeaa-4ced-9568-25e63a47d42d)\r\n\r\n#### Filtering preferences\r\n\r\nAlert filtering preferences are stored in local storage.\r\n\r\nThis PR adds the following new local storage keys:\r\n\r\n```\r\nelasticAssistantDefault.attackDiscovery.default.end\r\nelasticAssistantDefault.attackDiscovery.default.filters\r\nelasticAssistantDefault.attackDiscovery.default.query\r\nelasticAssistantDefault.attackDiscovery.default.start\r\n```\r\n\r\nUsers may use the `Reset` button in the Attack discovery settings flyout to restore the above to their defaults.\r\n\r\n#### Known limitations\r\n\r\nThe following known limitations in this PR may be mitigated in follow-up PRs:\r\n\r\n#### Table cell hover actions are disabled\r\n\r\nTable cell actions, i.e. `Filter for` and `Filter out` are disabled in the `Alert summary` and `Alerts preview` tables.\r\n\r\nThe actions are disabled because custom cell hover actions registered in `x-pack/solutions/security/plugins/security_solution/public/app/actions/register.ts` do NOT appear to receive field metadata (i.e. the name of the field being hovered over) when the action is triggered. This limitation also appears to apply to ad hoc ES|QL visualizations created via Lens in Kibana's _Dashboard_ app.\r\n\r\n##### Default table sort indicators are hidden\r\n\r\nThe `Alert summary` and `Alerts preview` tables are sorted descending by Count, and Risk score, respectively, via their ES|QL queries.\r\n\r\nThe tables _should_ display default sort indicators, as illustrated by the screenshots below:\r\n\r\n![09_alert_summary_with_sort_indicator](https://github.com/user-attachments/assets/c4e78144-f516-40f8-b6da-7c8c808841c4)\r\n\r\n![10_alerts_preview_with_sort_indicator](https://github.com/user-attachments/assets/c0061134-4734-462f-8eb0-978b2b02fb1e)\r\n\r\nThe default indicators are hidden in this PR as a workaround for an error that occurs in `EuiDataGrid` when switching tabs when the column sort indicators are enabled:\r\n\r\n```\r\nTypeError: Cannot read properties of undefined (reading 'split')\r\n```\r\n\r\nTo re-enable the sort indicators, `DEFAULT_ALERT_SUMMARY_SORT` and `DEFAULT_ALERTS_PREVIEW_SORT` must respectively be passed as the `sorting` prop to the `PreviewTab` in `x-pack/solutions/security/plugins/security_solution/public/attack_discovery/pages/settings_flyout/alert_selection/helpers/get_tabs/index.tsx`, as illustrated by the following code:\r\n\r\n```typescript\r\n <PreviewTab\r\n dataTestSubj={ALERT_SUMMARY_TEST_SUBJ}\r\n embeddableId={SUMMARY_TAB_EMBEDDABLE_ID}\r\n end={end}\r\n filters={filters}\r\n getLensAttributes={getAlertSummaryLensAttributes}\r\n getPreviewEsqlQuery={getAlertSummaryEsqlQuery}\r\n maxAlerts={maxAlerts}\r\n query={query}\r\n setTableStackBy0={setAlertSummaryStackBy0}\r\n start={start}\r\n sorting={DEFAULT_ALERT_SUMMARY_SORT} // <-- enables the sort indicator\r\n tableStackBy0={alertSummaryStackBy0}\r\n />\r\n```\r\n\r\n##### Selected date range not persisted\r\n\r\nThe `start` and `end` date range selected when a user starts generation are not (yet) persisted in Elasticsearch. As a result, the loading message always displays the currently configured range, rather than the range selected at the start of generation.","sha":"681d40eee64316bea85d04077f918bd7121988b9"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Andrew Macri <[email protected]>
1 parent 8642be7 commit a8cf4eb

File tree

61 files changed

+2380
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2380
-77
lines changed

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/alerts/get_open_and_acknowledged_alerts_query/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('getOpenAndAcknowledgedAlertsQuery', () => {
1313
const anonymizationFields = [
1414
{ id: 'field1', field: 'field1', allowed: true, anonymized: false },
1515
{ id: 'field2', field: 'field2', allowed: true, anonymized: false },
16+
{ id: 'field3', field: 'field3', allowed: false, anonymized: false },
1617
];
1718
const size = 10;
1819

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/alerts/get_open_and_acknowledged_alerts_query/index.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@
77

88
import type { AnonymizationFieldResponse } from '../../schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
99

10+
export const DEFAULT_END = 'now';
11+
export const DEFAULT_START = 'now-24h';
12+
13+
interface GetOpenAndAcknowledgedAlertsQuery {
14+
allow_no_indices: boolean;
15+
body: {
16+
fields: Array<{
17+
field: string;
18+
include_unmapped: boolean;
19+
}>;
20+
query: {
21+
bool: {
22+
filter: Array<Record<string, unknown>>;
23+
};
24+
};
25+
runtime_mappings: Record<string, unknown>;
26+
size: number;
27+
sort: Array<{
28+
[key: string]: {
29+
order: string;
30+
};
31+
}>;
32+
_source: boolean;
33+
};
34+
ignore_unavailable: boolean;
35+
index: string[];
36+
}
37+
1038
/**
1139
* This query returns open and acknowledged (non-building block) alerts in the last 24 hours.
1240
*
@@ -15,12 +43,18 @@ import type { AnonymizationFieldResponse } from '../../schemas/anonymization_fie
1543
export const getOpenAndAcknowledgedAlertsQuery = ({
1644
alertsIndexPattern,
1745
anonymizationFields,
46+
end,
47+
filter,
1848
size,
49+
start,
1950
}: {
2051
alertsIndexPattern: string;
2152
anonymizationFields: AnonymizationFieldResponse[];
53+
end?: string | null;
54+
filter?: Record<string, unknown> | null;
2255
size: number;
23-
}) => ({
56+
start?: string | null;
57+
}): GetOpenAndAcknowledgedAlertsQuery => ({
2458
allow_no_indices: true,
2559
body: {
2660
fields: anonymizationFields
@@ -53,11 +87,12 @@ export const getOpenAndAcknowledgedAlertsQuery = ({
5387
minimum_should_match: 1,
5488
},
5589
},
90+
...(filter != null ? [filter] : []),
5691
{
5792
range: {
5893
'@timestamp': {
59-
gte: 'now-24h',
60-
lte: 'now',
94+
gte: start != null ? start : DEFAULT_START,
95+
lte: end != null ? end : DEFAULT_END,
6196
format: 'strict_date_optional_time',
6297
},
6398
},

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/capabilities/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export type AssistantFeatureKey = keyof AssistantFeatures;
2020
*/
2121
export const defaultAssistantFeatures = Object.freeze({
2222
assistantModelEvaluation: false,
23+
attackDiscoveryAlertFiltering: false,
2324
defendInsights: false,
2425
});

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/attack_discovery/post_attack_discovery_route.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ export const AttackDiscoveryPostRequestBody = z.object({
2828
* LLM API configuration.
2929
*/
3030
apiConfig: ApiConfig,
31+
end: z.string().optional(),
32+
filter: z.object({}).catchall(z.unknown()).optional(),
3133
langSmithProject: z.string().optional(),
3234
langSmithApiKey: z.string().optional(),
3335
model: z.string().optional(),
3436
replacements: Replacements.optional(),
3537
size: z.number(),
38+
start: z.string().optional(),
3639
subAction: z.enum(['invokeAI', 'invokeStream']),
3740
});
3841
export type AttackDiscoveryPostRequestBodyInput = z.input<typeof AttackDiscoveryPostRequestBody>;

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/attack_discovery/post_attack_discovery_route.schema.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ paths:
3838
apiConfig:
3939
$ref: '../conversations/common_attributes.schema.yaml#/components/schemas/ApiConfig'
4040
description: LLM API configuration.
41+
end:
42+
type: string
43+
filter:
44+
type: object
45+
additionalProperties: true
4146
langSmithProject:
4247
type: string
4348
langSmithApiKey:
@@ -48,6 +53,8 @@ paths:
4853
$ref: '../conversations/common_attributes.schema.yaml#/components/schemas/Replacements'
4954
size:
5055
type: number
56+
start:
57+
type: string
5158
subAction:
5259
type: string
5360
enum:

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/capabilities/get_capabilities_route.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ import { z } from '@kbn/zod';
1919
export type GetCapabilitiesResponse = z.infer<typeof GetCapabilitiesResponse>;
2020
export const GetCapabilitiesResponse = z.object({
2121
assistantModelEvaluation: z.boolean(),
22+
attackDiscoveryAlertFiltering: z.boolean(),
2223
defendInsights: z.boolean(),
2324
});

x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/schemas/capabilities/get_capabilities_route.schema.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ paths:
2222
properties:
2323
assistantModelEvaluation:
2424
type: boolean
25+
attackDiscoveryAlertFiltering:
26+
type: boolean
2527
defendInsights:
2628
type: boolean
2729
required:
2830
- assistantModelEvaluation
31+
- attackDiscoveryAlertFiltering
2932
- defendInsights
3033
'400':
3134
description: Generic Error

x-pack/platform/packages/shared/kbn-elastic-assistant-common/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ export { getRawDataOrDefault } from './impl/alerts/helpers/get_raw_data_or_defau
4141

4242
/** Return true if the provided size is out of range */
4343
export { sizeIsOutOfRange } from './impl/alerts/helpers/size_is_out_of_range';
44+
45+
export {
46+
/** The default (relative) end of the date range (i.e. `now`) */
47+
DEFAULT_END,
48+
/** The default (relative) start of the date range (i.e. `now-24h`) */
49+
DEFAULT_START,
50+
} from './impl/alerts/get_open_and_acknowledged_alerts_query';

x-pack/platform/packages/shared/kbn-elastic-assistant/impl/assistant_context/constants.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import { KnowledgeBaseConfig } from '../assistant/types';
1010
export const ATTACK_DISCOVERY_STORAGE_KEY = 'attackDiscovery';
1111
export const DEFEND_INSIGHTS_STORAGE_KEY = 'defendInsights';
1212
export const DEFAULT_ASSISTANT_NAMESPACE = 'elasticAssistantDefault';
13+
export const END_LOCAL_STORAGE_KEY = 'end';
1314
export const LAST_CONVERSATION_ID_LOCAL_STORAGE_KEY = 'lastConversationId';
15+
export const FILTERS_LOCAL_STORAGE_KEY = 'filters';
1416
export const MAX_ALERTS_LOCAL_STORAGE_KEY = 'maxAlerts';
1517
export const KNOWLEDGE_BASE_LOCAL_STORAGE_KEY = 'knowledgeBase';
18+
export const QUERY_LOCAL_STORAGE_KEY = 'query';
1619
export const SHOW_SETTINGS_TOUR_LOCAL_STORAGE_KEY = 'showSettingsTour';
20+
export const START_LOCAL_STORAGE_KEY = 'start';
1721
export const STREAMING_LOCAL_STORAGE_KEY = 'streaming';
1822
export const TRACE_OPTIONS_SESSION_STORAGE_KEY = 'traceOptions';
1923
export const CONVERSATION_TABLE_SESSION_STORAGE_KEY = 'conversationTable';

x-pack/platform/packages/shared/kbn-elastic-assistant/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,19 @@ export {
8484
DEFAULT_ATTACK_DISCOVERY_MAX_ALERTS,
8585
DEFAULT_LATEST_ALERTS,
8686
DEFEND_INSIGHTS_STORAGE_KEY,
87+
/** The end of the date range of alerts, sent as context to the LLM */
88+
END_LOCAL_STORAGE_KEY,
89+
/** Search bar filters that apply to the alerts sent as context to the LLM */
90+
FILTERS_LOCAL_STORAGE_KEY,
8791
KNOWLEDGE_BASE_LOCAL_STORAGE_KEY,
8892
/** The local storage key that specifies the maximum number of alerts to send as context */
8993
MAX_ALERTS_LOCAL_STORAGE_KEY,
94+
/** Search bar query that apply to the alerts sent as context to the LLM */
95+
QUERY_LOCAL_STORAGE_KEY,
9096
/** The local storage key that specifies whether the settings tour should be shown */
9197
SHOW_SETTINGS_TOUR_LOCAL_STORAGE_KEY,
98+
/** The start of the date range of alerts, sent as context to the LLM */
99+
START_LOCAL_STORAGE_KEY,
92100
} from './impl/assistant_context/constants';
93101

94102
export { useLoadConnectors } from './impl/connectorland/use_load_connectors';

0 commit comments

Comments
 (0)