Skip to content

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

Merged
andrew-goldstein merged 1 commit intoelastic:8.12from
andrew-goldstein:backport/8.12/pr-173701
Dec 21, 2023
Merged

Conversation

@andrew-goldstein
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.12:

Questions ?

Please refer to the Backport tool documentation

…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
Copy link
Copy Markdown
Contributor Author

This backport was desk tested locally in the 8.12 branch via the Desk testing section of the PR description in #173701 , per the following screenshots:

desk_testing_8_12_alerts_page

desk_testing_backport_8_12_branch

@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

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

cc @andrew-goldstein

Copy link
Copy Markdown
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.

LGTM! Thanks for the screenshots from your desk testing

@andrew-goldstein andrew-goldstein merged commit d01e6b8 into elastic:8.12 Dec 21, 2023
@andrew-goldstein andrew-goldstein deleted the backport/8.12/pr-173701 branch December 21, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants