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

[Security Solution] [Elastic AI Assistant] Include acknowledged alerts in the LangChain AlertCountsTool aggregation #173701

Merged

Conversation

andrew-goldstein
Copy link
Contributor

@andrew-goldstein andrew-goldstein commented Dec 20, 2023

[Security Solution] [Elastic AI Assistant] Include acknowledged alerts in the LangChain AlertCountsTool aggregation

This PR updates the LangChain AlertCountsTool aggregation, which answers questions like How many open alerts do I have?, to include acknowledged alerts. The AlertCountsTool was introduced as part of [Security Solution] [Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts #172542

          "range": {
            "@timestamp": {
              "gte": "now-24h",
              "lte": "now"
            }
          }

Desk testing

To desk test this change:

  • The assistantRagOnAlerts feature flag described in #172542 must be enabled, per the following example:
xpack.securitySolution.enableExperimental: ['assistantRagOnAlerts']
  • The Alerts feature must be enabled in the assistant settings, per the screenshot below:

enable_alerts

  1. Generate alerts with a variety of severity (e.g. low, medium, high, and critical)

  2. After the alerts have been generated, disable all detection rules to keep the counts static during testing

  3. Navigate to Security > Alerts

  4. Select Last 24 hours from the Commonly used section of the global date picker

  5. Click the Treemap button to select the Treemap visualization

  6. In the Treemap's Group by input, enter kibana.alert.severity

  7. Next, in the Treemap's Group by top input, enter kibana.alert.workflow_status

  8. Click the AI Assistant button to open the assistant

  9. Click the X button to clear the conversation

  10. Close the assistant

  11. Add the following two fields as columns to the Alerts page table:

kibana.alert.workflow_status
_id
  1. Sort the Alerts table, first by kibana.alert.risk_score from high to low, and then by @timestamp from new to old, per the screenshot below:

fields_sorted

Expected results

  • The alerts page date range is Last 24 hours
  • The Treemap is selected
  • The treemap is grouped by kibana.alert.severity and then kibana.alert.workflow_status
  • The alerts table has custom sorting and columns, per the screenshot below:

alerts_page_setup

  1. Click the AI Assistant button to open the assistant

  2. Ask the assistant:

How many open alerts do I have?

Expected results

  • The assistant will report on the counts and workflow status of alerts, per the example response and screenshot below:
You have a total of 47 open alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts with medium severity, 7 alerts with high severity, and 4 alerts with critical severity.

assistant_open_alerts

  1. Make note of the counts shown in the assistant, then close the assistant

Expected result:

  • The counts from the assistant match the counts in the treemap legend, per the example screenshot below:

open_alerts_in_treemap

  1. Change the workflow status of an alert in the Alerts table from open to acknowledged

Expected result

  • The treemap and alerts table and include the updated (acknowledged) alert, per the screenshot below:

updated_treemap_and_table

  1. Once again, open the assistant

  2. Once again, ask the (same) question:

How many open alerts do I have?

Expected result

  • The response from the assistant makes reference to the alert who's workflow status was changed from open to acknowledged, per the example response and screenshot below:
Based on the latest data I had received, you have a total of 47 open alerts. Here's the breakdown: 24 alerts are of low severity, 12 alerts are of medium severity, 7 alerts are of high severity, and 4 alerts are of critical severity (Note: One of the critical severity alerts has been acknowledged).

with_acknowledged_alerts

…alerts in the LangChain `AlertCountsTool` aggregation

This PR updates the LangChain `AlertCountsTool` aggregation, which answers questions like `How many open alerts do I have?`, to include `acknowledged` alerts. The `AlertCountsTool` was introduced as part of [[Security Solution] [Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts elastic#172542](elastic#172542)

- This PR is similar to <elastic#173121>, where `acknowledged` alerts were added to the `OpenAndAcknowledgedAlertsTool`, which returns the _details_ of alerts
  - In contrast to [elastic#173121](elastic#173121), this PR is focused on the alert counts _aggregation_

- This PR also updates the `range` of **both** the `AlertCountsTool` and the `OpenAndAcknowledgedAlertsTool` queries to standardize on the following syntax, which aligns with the `Last 24 hours` option in the _Commonly used_ section of the Kibana date picker:

```json
          "range": {
            "@timestamp": {
              "gte": "now-24h",
              "lte": "now"
            }
          }
```

### Desk testing

To desk test this change:

- The `assistantRagOnAlerts` feature flag described in [elastic#172542](elastic#172542) must be enabled, per the following example:

```
xpack.securitySolution.enableExperimental: ['assistantRagOnAlerts']
```

- The `Alerts` feature must be enabled in the assistant settings, per the screenshot below:

 ![enable_alerts](https://github.com/elastic/kibana/assets/4459398/f6a3077d-5815-4225-9a8e-7f5b51d5f2d4)

1) Generate alerts with a variety of severity (e.g. `low`, `medium`, `high`, and `critical`)

2) After the alerts have been generated, disable all detection rules to keep the counts static during testing

3) Navigate to Security > Alerts

4) Select `Last 24 hours` from the _Commonly used_ section of the global date picker

5) Click the `Treemap` button to select the Treemap visualization

6) In the Treemap's `Group by` input, enter `kibana.alert.severity`

7) Next, in the Treemap's `Group by top` input, enter `kibana.alert.workflow_status`

8) Click the `AI Assistant` button to open the assistant

9) Click the `X` button to clear the conversation

10) Close the assistant

11) Add the following two fields as columns to the Alerts page table:

```
kibana.alert.workflow_status
_id
```

12) Sort the Alerts table, first by `kibana.alert.risk_score` from high to low, and then by `@timestamp` from new to old, per the screenshot below:

![fields_sorted](https://github.com/elastic/kibana/assets/4459398/e84f06d4-790d-4227-afbf-a233d4848178)

**Expected results**

- The alerts page date range is `Last 24 hours`
- The `Treemap` is selected
- The treemap is grouped by `kibana.alert.severity` and then `kibana.alert.workflow_status`
- The alerts table has custom sorting and columns, per the screenshot below:

![alerts_page_setup](https://github.com/elastic/kibana/assets/4459398/f4700abc-b2ca-483e-92d8-5a186142e1fb)

13) Click the `AI Assistant` button to open the assistant

14) Ask the assistant:

```
How many open alerts do I have?
```

**Expected results**

- The assistant will report on the counts and workflow status of alerts, per the example response and screenshot below:

```
You have a total of 47 open alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts with medium severity, 7 alerts with high severity, and 4 alerts with critical severity.
```

![assistant_open_alerts](https://github.com/elastic/kibana/assets/4459398/45740c07-9317-42e6-943d-fc346b8106e5)

15) Make note of the counts shown in the assistant, then close the assistant

Expected result:

- The counts from the assistant match the counts in the treemap legend, per the example screenshot below:

![open_alerts_in_treemap](https://github.com/elastic/kibana/assets/4459398/368fb707-9faf-4b9b-a0b3-81fab4d680b2)

16) Change the workflow status of an alert in the Alerts table from `open` to `acknowledged`

**Expected result**

- The treemap and alerts table and include the updated (`acknowledged`) alert, per the screenshot below:

![updated_treemap_and_table](https://github.com/elastic/kibana/assets/4459398/0b8bedb7-aed7-41f1-abcd-f79a79480739)

17) Once again, open the assistant

18) Once again, ask the (same) question:

```
How many open alerts do I have?
```

**Expected result**

- The response from the assistant makes reference to the alert who's workflow status was changed from `open` to `acknowledged`, per the example response and screenshot below:

```
Based on the latest data I had received, you have a total of 47 open alerts. Here's the breakdown: 24 alerts are of low severity, 12 alerts are of medium severity, 7 alerts are of high severity, and 4 alerts are of critical severity (Note: One of the critical severity alerts has been acknowledged).
```

![with_acknowledged_alerts](https://github.com/elastic/kibana/assets/4459398/4a8961f2-80eb-457f-b16b-8ea48c5d5c38)
@andrew-goldstein andrew-goldstein added bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Investigations Security Solution Investigations Team Feature:Security Assistant Security Assistant v8.12.0 v8.13.0 labels Dec 20, 2023
@andrew-goldstein andrew-goldstein self-assigned this Dec 20, 2023
@andrew-goldstein andrew-goldstein requested a review from a team as a code owner December 20, 2023 00:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @andrew-goldstein

Copy link
Contributor

@stephmilovic stephmilovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and desk testing LGTM!

As discussed offline, we noticed a discrepancy between the time being selected and the time being searched in both Security Solution and Discover. It seems something in the date picker converts relative dates to absolute. This may be a hit to performance and caching, even if it was searching the correct time. Relative is more performant in ES. It gets worse - not only is the time absolute, but the time picker rounds down to the hour. So if you searched the last 24 hours at 9:59 today, it would give you a range of Tues 9:00 - Wed 9:59. A 25 hour period. We are not sure when this started, but we will research and see if this is a bug as we suspect.

Screenshot 2023-12-20 at 11 28 37 AM

In regards to this PR, I think we are good going forward with now-24h for this query and investigating the issue with the date picker separately.

@andrew-goldstein
Copy link
Contributor Author

Code review and desk testing LGTM!

As discussed offline, we noticed a discrepancy between the time being selected and the time being searched in both Security Solution and Discover. It seems something in the date picker converts relative dates to absolute. This may be a hit to performance and caching, even if it was searching the correct time. Relative is more performant in ES. It gets worse - not only is the time absolute, but the time picker rounds down to the hour. So if you searched the last 24 hours at 9:59 today, it would give you a range of Tues 9:00 - Wed 9:59. A 25 hour period. We are not sure when this started, but we will research and see if this is a bug as we suspect.

Screenshot 2023-12-20 at 11 28 37 AM In regards to this PR, I think we are good going forward with now-24h for this query and investigating the issue with the date picker separately.

Thanks for sharing this observation @stephmilovic!

I happened to have an 7.10.2 release (late 2020) running for comparision, and observed that, in summary:

  • In 7.10.2, Discover appears to use absolute datetimes in the query when Last 24 hours is selected in the global date picker (similar to main)
  • In 7.10.2, Discover appears to use a different absolute datetime representation of Last 24 hours (different, compared to the screenshot from main)

For example, gte appears to be rounded to 2023-12-19T16:00:00.0000Z in the screenshot from main, but in 7.10.2, both the gte and lte query values are relative to the time the query was invoked:

          "range": {
            "@timestamp": {
              "gte": "2023-12-20T03:40:28.149Z",
              "lte": "2023-12-21T03:40:28.149Z",
              "format": "strict_date_optional_time"
            }

discover_url_7_10_2

Above: Discover's URL encoding of Last 24 hours is a relative date range in 7.10.2, i.e. from:now-24h,to:now

discover_7_10_query

Above: Discover's query encoding of Last 24 hours is an absolute date range in 7.10.2 (via the query inspector) i.e. "gte": "2023-12-20T03:40:28.149Z" "lte": "2023-12-21T03:40:28.149Z", but the range appears to be represented differently compared to the screenshot from main

@andrew-goldstein andrew-goldstein merged commit 081f52b into elastic:main Dec 21, 2023
@andrew-goldstein andrew-goldstein deleted the update_alerts_count_query branch December 21, 2023 04:41
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.12 Backport failed because of merge conflicts

You might need to backport the following PRs to 8.12:
- Update platform security modules (main) (#173232)

Manual backport

To create the backport manually run:

node scripts/backport --pr 173701

Questions ?

Please refer to the Backport tool documentation

@andrew-goldstein
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

andrew-goldstein added a commit to andrew-goldstein/kibana that referenced this pull request Dec 21, 2023
…rts in the LangChain `AlertCountsTool` aggregation (elastic#173701)

This PR updates the LangChain `AlertCountsTool` aggregation, which answers questions like `How many open alerts do I have?`, to include `acknowledged` alerts. The `AlertCountsTool` was introduced as part of [[Security Solution] [Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts elastic#172542](elastic#172542)

- This PR is similar to <elastic#173121>, where `acknowledged` alerts were added to the `OpenAndAcknowledgedAlertsTool`, which returns the _details_ of alerts
  - In contrast to [elastic#173121](elastic#173121), this PR is focused on the alert counts _aggregation_

- This PR also updates the `range` of **both** the `AlertCountsTool` and the `OpenAndAcknowledgedAlertsTool` queries to standardize on the following syntax, which aligns with the `Last 24 hours` option in the _Commonly used_ section of the Kibana date picker:

```json
          "range": {
            "@timestamp": {
              "gte": "now-24h",
              "lte": "now"
            }
          }
```

To desk test this change:

- The `assistantRagOnAlerts` feature flag described in [elastic#172542](elastic#172542) must be enabled, per the following example:

```
xpack.securitySolution.enableExperimental: ['assistantRagOnAlerts']
```

- The `Alerts` feature must be enabled in the assistant settings, per the screenshot below:

 ![enable_alerts](https://github.com/elastic/kibana/assets/4459398/f6a3077d-5815-4225-9a8e-7f5b51d5f2d4)

1) Generate alerts with a variety of severity (e.g. `low`, `medium`, `high`, and `critical`)

2) After the alerts have been generated, disable all detection rules to keep the counts static during testing

3) Navigate to Security > Alerts

4) Select `Last 24 hours` from the _Commonly used_ section of the global date picker

5) Click the `Treemap` button to select the Treemap visualization

6) In the Treemap's `Group by` input, enter `kibana.alert.severity`

7) Next, in the Treemap's `Group by top` input, enter `kibana.alert.workflow_status`

8) Click the `AI Assistant` button to open the assistant

9) Click the `X` button to clear the conversation

10) Close the assistant

11) Add the following two fields as columns to the Alerts page table:

```
kibana.alert.workflow_status
_id
```

12) Sort the Alerts table, first by `kibana.alert.risk_score` from high to low, and then by `@timestamp` from new to old, per the screenshot below:

![fields_sorted](https://github.com/elastic/kibana/assets/4459398/e84f06d4-790d-4227-afbf-a233d4848178)

**Expected results**

- The alerts page date range is `Last 24 hours`
- The `Treemap` is selected
- The treemap is grouped by `kibana.alert.severity` and then `kibana.alert.workflow_status`
- The alerts table has custom sorting and columns, per the screenshot below:

![alerts_page_setup](https://github.com/elastic/kibana/assets/4459398/f4700abc-b2ca-483e-92d8-5a186142e1fb)

13) Click the `AI Assistant` button to open the assistant

14) Ask the assistant:

```
How many open alerts do I have?
```

**Expected results**

- The assistant will report on the counts and workflow status of alerts, per the example response and screenshot below:

```
You have a total of 47 open alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts with medium severity, 7 alerts with high severity, and 4 alerts with critical severity.
```

![assistant_open_alerts](https://github.com/elastic/kibana/assets/4459398/45740c07-9317-42e6-943d-fc346b8106e5)

15) Make note of the counts shown in the assistant, then close the assistant

Expected result:

- The counts from the assistant match the counts in the treemap legend, per the example screenshot below:

![open_alerts_in_treemap](https://github.com/elastic/kibana/assets/4459398/368fb707-9faf-4b9b-a0b3-81fab4d680b2)

16) Change the workflow status of an alert in the Alerts table from `open` to `acknowledged`

**Expected result**

- The treemap and alerts table and include the updated (`acknowledged`) alert, per the screenshot below:

![updated_treemap_and_table](https://github.com/elastic/kibana/assets/4459398/0b8bedb7-aed7-41f1-abcd-f79a79480739)

17) Once again, open the assistant

18) Once again, ask the (same) question:

```
How many open alerts do I have?
```

**Expected result**

- The response from the assistant makes reference to the alert who's workflow status was changed from `open` to `acknowledged`, per the example response and screenshot below:

```
Based on the latest data I had received, you have a total of 47 open alerts. Here's the breakdown: 24 alerts are of low severity, 12 alerts are of medium severity, 7 alerts are of high severity, and 4 alerts are of critical severity (Note: One of the critical severity alerts has been acknowledged).
```

![with_acknowledged_alerts](https://github.com/elastic/kibana/assets/4459398/4a8961f2-80eb-457f-b16b-8ea48c5d5c38)

(cherry picked from commit 081f52b)
andrew-goldstein added a commit that referenced this pull request Dec 21, 2023
…ed` alerts in the LangChain `AlertCountsTool` aggregation (#173701) (#173801)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Security Solution] [Elastic AI Assistant] Include `acknowledged`
alerts in the LangChain `AlertCountsTool` aggregation
(#173701)](#173701)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Andrew
Macri","email":"andrew.macri@elastic.co"},"sourceCommit":{"committedDate":"2023-12-21T04:41:11Z","message":"[Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation (#173701)\n\n## [Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation\r\n\r\nThis PR updates the
LangChain `AlertCountsTool` aggregation, which answers questions like
`How many open alerts do I have?`, to include `acknowledged` alerts. The
`AlertCountsTool` was introduced as part of [[Security Solution]
[Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts
#172542](https://github.com/elastic/kibana/pull/172542)\r\n\r\n- This PR
is similar to <#173121>, where
`acknowledged` alerts were added to the `OpenAndAcknowledgedAlertsTool`,
which returns the _details_ of alerts\r\n - In contrast to
[#173121](#173121), this PR is
focused on the alert counts _aggregation_\r\n\r\n- This PR also updates
the `range` of **both** the `AlertCountsTool` and the
`OpenAndAcknowledgedAlertsTool` queries to standardize on the following
syntax, which aligns with the `Last 24 hours` option in the _Commonly
used_ section of the Kibana date picker:\r\n\r\n```json\r\n \"range\":
{\r\n \"@timestamp\": {\r\n \"gte\": \"now-24h\",\r\n \"lte\":
\"now\"\r\n }\r\n }\r\n```\r\n\r\n### Desk testing\r\n\r\nTo desk test
this change:\r\n\r\n- The `assistantRagOnAlerts` feature flag described
in [#172542](#172542) must be
enabled, per the following
example:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantRagOnAlerts']\r\n```\r\n\r\n- The `Alerts` feature must be
enabled in the assistant settings, per the screenshot below:\r\n\r\n
![enable_alerts](https://github.com/elastic/kibana/assets/4459398/f6a3077d-5815-4225-9a8e-7f5b51d5f2d4)\r\n\r\n1)
Generate alerts with a variety of severity (e.g. `low`, `medium`,
`high`, and `critical`)\r\n\r\n2) After the alerts have been generated,
disable all detection rules to keep the counts static during
testing\r\n\r\n3) Navigate to Security > Alerts\r\n\r\n4) Select `Last
24 hours` from the _Commonly used_ section of the global date
picker\r\n\r\n5) Click the `Treemap` button to select the Treemap
visualization\r\n\r\n6) In the Treemap's `Group by` input, enter
`kibana.alert.severity`\r\n\r\n7) Next, in the Treemap's `Group by top`
input, enter `kibana.alert.workflow_status`\r\n\r\n8) Click the `AI
Assistant` button to open the assistant\r\n\r\n9) Click the `X` button
to clear the conversation\r\n\r\n10) Close the assistant\r\n\r\n11) Add
the following two fields as columns to the Alerts page
table:\r\n\r\n```\r\nkibana.alert.workflow_status\r\n_id\r\n```\r\n\r\n12)
Sort the Alerts table, first by `kibana.alert.risk_score` from high to
low, and then by `@timestamp` from new to old, per the screenshot
below:\r\n\r\n![fields_sorted](https://github.com/elastic/kibana/assets/4459398/e84f06d4-790d-4227-afbf-a233d4848178)\r\n\r\n**Expected
results**\r\n\r\n- The alerts page date range is `Last 24 hours`\r\n-
The `Treemap` is selected\r\n- The treemap is grouped by
`kibana.alert.severity` and then `kibana.alert.workflow_status`\r\n- The
alerts table has custom sorting and columns, per the screenshot
below:\r\n\r\n![alerts_page_setup](https://github.com/elastic/kibana/assets/4459398/f4700abc-b2ca-483e-92d8-5a186142e1fb)\r\n\r\n13)
Click the `AI Assistant` button to open the assistant\r\n\r\n14) Ask the
assistant:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected results**\r\n\r\n- The assistant will
report on the counts and workflow status of alerts, per the example
response and screenshot below:\r\n\r\n```\r\nYou have a total of 47 open
alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts
with medium severity, 7 alerts with high severity, and 4 alerts with
critical
severity.\r\n```\r\n\r\n![assistant_open_alerts](https://github.com/elastic/kibana/assets/4459398/45740c07-9317-42e6-943d-fc346b8106e5)\r\n\r\n15)
Make note of the counts shown in the assistant, then close the
assistant\r\n\r\nExpected result:\r\n\r\n- The counts from the assistant
match the counts in the treemap legend, per the example screenshot
below:\r\n\r\n![open_alerts_in_treemap](https://github.com/elastic/kibana/assets/4459398/368fb707-9faf-4b9b-a0b3-81fab4d680b2)\r\n\r\n16)
Change the workflow status of an alert in the Alerts table from `open`
to `acknowledged`\r\n\r\n**Expected result**\r\n\r\n- The treemap and
alerts table and include the updated (`acknowledged`) alert, per the
screenshot
below:\r\n\r\n![updated_treemap_and_table](https://github.com/elastic/kibana/assets/4459398/0b8bedb7-aed7-41f1-abcd-f79a79480739)\r\n\r\n17)
Once again, open the assistant\r\n\r\n18) Once again, ask the (same)
question:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected result**\r\n\r\n- The response from the
assistant makes reference to the alert who's workflow status was changed
from `open` to `acknowledged`, per the example response and screenshot
below:\r\n\r\n```\r\nBased on the latest data I had received, you have a
total of 47 open alerts. Here's the breakdown: 24 alerts are of low
severity, 12 alerts are of medium severity, 7 alerts are of high
severity, and 4 alerts are of critical severity (Note: One of the
critical severity alerts has been
acknowledged).\r\n```\r\n\r\n![with_acknowledged_alerts](https://github.com/elastic/kibana/assets/4459398/4a8961f2-80eb-457f-b16b-8ea48c5d5c38)","sha":"081f52bfe3fbbaf5bb9476c656c308f7f9430df2","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:
SecuritySolution","Team:Threat Hunting:Investigations","Feature:Elastic
AI
Assistant","v8.12.0","v8.13.0"],"number":173701,"url":"https://github.com/elastic/kibana/pull/173701","mergeCommit":{"message":"[Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation (#173701)\n\n## [Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation\r\n\r\nThis PR updates the
LangChain `AlertCountsTool` aggregation, which answers questions like
`How many open alerts do I have?`, to include `acknowledged` alerts. The
`AlertCountsTool` was introduced as part of [[Security Solution]
[Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts
#172542](https://github.com/elastic/kibana/pull/172542)\r\n\r\n- This PR
is similar to <#173121>, where
`acknowledged` alerts were added to the `OpenAndAcknowledgedAlertsTool`,
which returns the _details_ of alerts\r\n - In contrast to
[#173121](#173121), this PR is
focused on the alert counts _aggregation_\r\n\r\n- This PR also updates
the `range` of **both** the `AlertCountsTool` and the
`OpenAndAcknowledgedAlertsTool` queries to standardize on the following
syntax, which aligns with the `Last 24 hours` option in the _Commonly
used_ section of the Kibana date picker:\r\n\r\n```json\r\n \"range\":
{\r\n \"@timestamp\": {\r\n \"gte\": \"now-24h\",\r\n \"lte\":
\"now\"\r\n }\r\n }\r\n```\r\n\r\n### Desk testing\r\n\r\nTo desk test
this change:\r\n\r\n- The `assistantRagOnAlerts` feature flag described
in [#172542](#172542) must be
enabled, per the following
example:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantRagOnAlerts']\r\n```\r\n\r\n- The `Alerts` feature must be
enabled in the assistant settings, per the screenshot below:\r\n\r\n
![enable_alerts](https://github.com/elastic/kibana/assets/4459398/f6a3077d-5815-4225-9a8e-7f5b51d5f2d4)\r\n\r\n1)
Generate alerts with a variety of severity (e.g. `low`, `medium`,
`high`, and `critical`)\r\n\r\n2) After the alerts have been generated,
disable all detection rules to keep the counts static during
testing\r\n\r\n3) Navigate to Security > Alerts\r\n\r\n4) Select `Last
24 hours` from the _Commonly used_ section of the global date
picker\r\n\r\n5) Click the `Treemap` button to select the Treemap
visualization\r\n\r\n6) In the Treemap's `Group by` input, enter
`kibana.alert.severity`\r\n\r\n7) Next, in the Treemap's `Group by top`
input, enter `kibana.alert.workflow_status`\r\n\r\n8) Click the `AI
Assistant` button to open the assistant\r\n\r\n9) Click the `X` button
to clear the conversation\r\n\r\n10) Close the assistant\r\n\r\n11) Add
the following two fields as columns to the Alerts page
table:\r\n\r\n```\r\nkibana.alert.workflow_status\r\n_id\r\n```\r\n\r\n12)
Sort the Alerts table, first by `kibana.alert.risk_score` from high to
low, and then by `@timestamp` from new to old, per the screenshot
below:\r\n\r\n![fields_sorted](https://github.com/elastic/kibana/assets/4459398/e84f06d4-790d-4227-afbf-a233d4848178)\r\n\r\n**Expected
results**\r\n\r\n- The alerts page date range is `Last 24 hours`\r\n-
The `Treemap` is selected\r\n- The treemap is grouped by
`kibana.alert.severity` and then `kibana.alert.workflow_status`\r\n- The
alerts table has custom sorting and columns, per the screenshot
below:\r\n\r\n![alerts_page_setup](https://github.com/elastic/kibana/assets/4459398/f4700abc-b2ca-483e-92d8-5a186142e1fb)\r\n\r\n13)
Click the `AI Assistant` button to open the assistant\r\n\r\n14) Ask the
assistant:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected results**\r\n\r\n- The assistant will
report on the counts and workflow status of alerts, per the example
response and screenshot below:\r\n\r\n```\r\nYou have a total of 47 open
alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts
with medium severity, 7 alerts with high severity, and 4 alerts with
critical
severity.\r\n```\r\n\r\n![assistant_open_alerts](https://github.com/elastic/kibana/assets/4459398/45740c07-9317-42e6-943d-fc346b8106e5)\r\n\r\n15)
Make note of the counts shown in the assistant, then close the
assistant\r\n\r\nExpected result:\r\n\r\n- The counts from the assistant
match the counts in the treemap legend, per the example screenshot
below:\r\n\r\n![open_alerts_in_treemap](https://github.com/elastic/kibana/assets/4459398/368fb707-9faf-4b9b-a0b3-81fab4d680b2)\r\n\r\n16)
Change the workflow status of an alert in the Alerts table from `open`
to `acknowledged`\r\n\r\n**Expected result**\r\n\r\n- The treemap and
alerts table and include the updated (`acknowledged`) alert, per the
screenshot
below:\r\n\r\n![updated_treemap_and_table](https://github.com/elastic/kibana/assets/4459398/0b8bedb7-aed7-41f1-abcd-f79a79480739)\r\n\r\n17)
Once again, open the assistant\r\n\r\n18) Once again, ask the (same)
question:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected result**\r\n\r\n- The response from the
assistant makes reference to the alert who's workflow status was changed
from `open` to `acknowledged`, per the example response and screenshot
below:\r\n\r\n```\r\nBased on the latest data I had received, you have a
total of 47 open alerts. Here's the breakdown: 24 alerts are of low
severity, 12 alerts are of medium severity, 7 alerts are of high
severity, and 4 alerts are of critical severity (Note: One of the
critical severity alerts has been
acknowledged).\r\n```\r\n\r\n![with_acknowledged_alerts](https://github.com/elastic/kibana/assets/4459398/4a8961f2-80eb-457f-b16b-8ea48c5d5c38)","sha":"081f52bfe3fbbaf5bb9476c656c308f7f9430df2"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173701","number":173701,"mergeCommit":{"message":"[Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation (#173701)\n\n## [Security
Solution] [Elastic AI Assistant] Include `acknowledged` alerts in the
LangChain `AlertCountsTool` aggregation\r\n\r\nThis PR updates the
LangChain `AlertCountsTool` aggregation, which answers questions like
`How many open alerts do I have?`, to include `acknowledged` alerts. The
`AlertCountsTool` was introduced as part of [[Security Solution]
[Elastic AI Assistant] Retrieval Augmented Generation (RAG) for Alerts
#172542](https://github.com/elastic/kibana/pull/172542)\r\n\r\n- This PR
is similar to <#173121>, where
`acknowledged` alerts were added to the `OpenAndAcknowledgedAlertsTool`,
which returns the _details_ of alerts\r\n - In contrast to
[#173121](#173121), this PR is
focused on the alert counts _aggregation_\r\n\r\n- This PR also updates
the `range` of **both** the `AlertCountsTool` and the
`OpenAndAcknowledgedAlertsTool` queries to standardize on the following
syntax, which aligns with the `Last 24 hours` option in the _Commonly
used_ section of the Kibana date picker:\r\n\r\n```json\r\n \"range\":
{\r\n \"@timestamp\": {\r\n \"gte\": \"now-24h\",\r\n \"lte\":
\"now\"\r\n }\r\n }\r\n```\r\n\r\n### Desk testing\r\n\r\nTo desk test
this change:\r\n\r\n- The `assistantRagOnAlerts` feature flag described
in [#172542](#172542) must be
enabled, per the following
example:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantRagOnAlerts']\r\n```\r\n\r\n- The `Alerts` feature must be
enabled in the assistant settings, per the screenshot below:\r\n\r\n
![enable_alerts](https://github.com/elastic/kibana/assets/4459398/f6a3077d-5815-4225-9a8e-7f5b51d5f2d4)\r\n\r\n1)
Generate alerts with a variety of severity (e.g. `low`, `medium`,
`high`, and `critical`)\r\n\r\n2) After the alerts have been generated,
disable all detection rules to keep the counts static during
testing\r\n\r\n3) Navigate to Security > Alerts\r\n\r\n4) Select `Last
24 hours` from the _Commonly used_ section of the global date
picker\r\n\r\n5) Click the `Treemap` button to select the Treemap
visualization\r\n\r\n6) In the Treemap's `Group by` input, enter
`kibana.alert.severity`\r\n\r\n7) Next, in the Treemap's `Group by top`
input, enter `kibana.alert.workflow_status`\r\n\r\n8) Click the `AI
Assistant` button to open the assistant\r\n\r\n9) Click the `X` button
to clear the conversation\r\n\r\n10) Close the assistant\r\n\r\n11) Add
the following two fields as columns to the Alerts page
table:\r\n\r\n```\r\nkibana.alert.workflow_status\r\n_id\r\n```\r\n\r\n12)
Sort the Alerts table, first by `kibana.alert.risk_score` from high to
low, and then by `@timestamp` from new to old, per the screenshot
below:\r\n\r\n![fields_sorted](https://github.com/elastic/kibana/assets/4459398/e84f06d4-790d-4227-afbf-a233d4848178)\r\n\r\n**Expected
results**\r\n\r\n- The alerts page date range is `Last 24 hours`\r\n-
The `Treemap` is selected\r\n- The treemap is grouped by
`kibana.alert.severity` and then `kibana.alert.workflow_status`\r\n- The
alerts table has custom sorting and columns, per the screenshot
below:\r\n\r\n![alerts_page_setup](https://github.com/elastic/kibana/assets/4459398/f4700abc-b2ca-483e-92d8-5a186142e1fb)\r\n\r\n13)
Click the `AI Assistant` button to open the assistant\r\n\r\n14) Ask the
assistant:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected results**\r\n\r\n- The assistant will
report on the counts and workflow status of alerts, per the example
response and screenshot below:\r\n\r\n```\r\nYou have a total of 47 open
alerts. Here's the breakdown: 24 alerts with low severity, 12 alerts
with medium severity, 7 alerts with high severity, and 4 alerts with
critical
severity.\r\n```\r\n\r\n![assistant_open_alerts](https://github.com/elastic/kibana/assets/4459398/45740c07-9317-42e6-943d-fc346b8106e5)\r\n\r\n15)
Make note of the counts shown in the assistant, then close the
assistant\r\n\r\nExpected result:\r\n\r\n- The counts from the assistant
match the counts in the treemap legend, per the example screenshot
below:\r\n\r\n![open_alerts_in_treemap](https://github.com/elastic/kibana/assets/4459398/368fb707-9faf-4b9b-a0b3-81fab4d680b2)\r\n\r\n16)
Change the workflow status of an alert in the Alerts table from `open`
to `acknowledged`\r\n\r\n**Expected result**\r\n\r\n- The treemap and
alerts table and include the updated (`acknowledged`) alert, per the
screenshot
below:\r\n\r\n![updated_treemap_and_table](https://github.com/elastic/kibana/assets/4459398/0b8bedb7-aed7-41f1-abcd-f79a79480739)\r\n\r\n17)
Once again, open the assistant\r\n\r\n18) Once again, ask the (same)
question:\r\n\r\n```\r\nHow many open alerts do I
have?\r\n```\r\n\r\n**Expected result**\r\n\r\n- The response from the
assistant makes reference to the alert who's workflow status was changed
from `open` to `acknowledged`, per the example response and screenshot
below:\r\n\r\n```\r\nBased on the latest data I had received, you have a
total of 47 open alerts. Here's the breakdown: 24 alerts are of low
severity, 12 alerts are of medium severity, 7 alerts are of high
severity, and 4 alerts are of critical severity (Note: One of the
critical severity alerts has been
acknowledged).\r\n```\r\n\r\n![with_acknowledged_alerts](https://github.com/elastic/kibana/assets/4459398/4a8961f2-80eb-457f-b16b-8ea48c5d5c38)","sha":"081f52bfe3fbbaf5bb9476c656c308f7f9430df2"}}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Security Assistant Security Assistant release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Investigations Security Solution Investigations Team v8.12.0 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants