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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,64 @@ describe('AlertCountsTool', () => {
await tool.func('');

expect(esClient.search).toHaveBeenCalledWith({
aggs: { statusBySeverity: { terms: { field: 'kibana.alert.severity' } } },
aggs: {
kibanaAlertSeverity: {
terms: {
field: 'kibana.alert.severity',
},
aggs: {
kibanaAlertWorkflowStatus: {
terms: {
field: 'kibana.alert.workflow_status',
},
},
},
},
},
index: ['alerts-index'],
query: {
bool: {
filter: [
{
bool: {
filter: [{ match_phrase: { 'kibana.alert.workflow_status': 'open' } }],
must_not: [{ exists: { field: 'kibana.alert.building_block_type' } }],
filter: [
{
bool: {
should: [
{
match_phrase: {
'kibana.alert.workflow_status': 'open',
},
},
{
match_phrase: {
'kibana.alert.workflow_status': 'acknowledged',
},
},
],
minimum_should_match: 1,
},
},
],
should: [],
must: [],
must_not: [
{
exists: {
field: 'kibana.alert.building_block_type',
},
},
],
},
},
{
range: {
'@timestamp': {
gte: 'now-24h',
lte: 'now',
},
},
},
{ range: { '@timestamp': { gte: 'now/d', lte: 'now/d' } } },
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface AlertCountsToolParams extends AssistantToolParams {
alertsIndexPattern: string;
}
export const ALERT_COUNTS_TOOL_DESCRIPTION =
'Call this for the counts of last 24 hours of open alerts in the environment, grouped by their severity';
'Call this for the counts of last 24 hours of open and acknowledged alerts in the environment, grouped by their severity and workflow status.';

export const ALERT_COUNTS_TOOL: AssistantTool = {
id: 'alert-counts-tool',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ describe('getAlertsCountQuery', () => {

expect(query).toEqual({
aggs: {
statusBySeverity: {
kibanaAlertSeverity: {
terms: {
field: 'kibana.alert.severity',
},
aggs: {
kibanaAlertWorkflowStatus: {
terms: {
field: 'kibana.alert.workflow_status',
},
},
},
},
},
index: ['alerts-index-pattern'],
Expand All @@ -26,13 +33,27 @@ describe('getAlertsCountQuery', () => {
filter: [
{
bool: {
must: [],
filter: [
{
match_phrase: {
'kibana.alert.workflow_status': 'open',
bool: {
should: [
{
match_phrase: {
'kibana.alert.workflow_status': 'open',
},
},
{
match_phrase: {
'kibana.alert.workflow_status': 'acknowledged',
},
},
],
minimum_should_match: 1,
},
},
],
should: [],
must_not: [
{
exists: {
Expand All @@ -45,8 +66,8 @@ describe('getAlertsCountQuery', () => {
{
range: {
'@timestamp': {
gte: 'now/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

export const getAlertsCountQuery = (alertsIndexPattern: string) => ({
aggs: {
statusBySeverity: {
kibanaAlertSeverity: {
terms: {
field: 'kibana.alert.severity',
},
aggs: {
kibanaAlertWorkflowStatus: {
terms: {
field: 'kibana.alert.workflow_status',
},
},
},
},
},
index: [alertsIndexPattern],
Expand All @@ -21,25 +28,39 @@ export const getAlertsCountQuery = (alertsIndexPattern: string) => ({
bool: {
filter: [
{
match_phrase: {
'kibana.alert.workflow_status': 'open',
bool: {
should: [
{
match_phrase: {
'kibana.alert.workflow_status': 'open',
},
},
{
match_phrase: {
'kibana.alert.workflow_status': 'acknowledged',
},
},
],
minimum_should_match: 1,
},
},
],
must: [],
must_not: [
{
exists: {
field: 'kibana.alert.building_block_type',
},
},
],
should: [],
},
},
{
range: {
'@timestamp': {
gte: 'now/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('getOpenAndAcknowledgedAlertsQuery', () => {
{
range: {
'@timestamp': {
gte: 'now-1d/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const getOpenAndAcknowledgedAlertsQuery = ({
{
range: {
'@timestamp': {
gte: 'now-1d/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ describe('OpenAndAcknowledgedAlertsTool', () => {
range: {
'@timestamp': {
format: 'strict_date_optional_time',
gte: 'now-1d/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
},
},
},
Expand Down