Skip to content
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 @@ -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 @@ -45,18 +45,64 @@ describe('getAlertCountsTool', () => {
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 @@ -15,7 +15,7 @@ import { requestHasRequiredAnonymizationParams } from '../../helpers';
import type { RequestBody } from '../../types';

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 getAlertCountsTool = ({
alertsIndexPattern,
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 @@ -95,8 +95,8 @@ describe('getOpenAndAcknowledgedAlertsTool', () => {
range: {
'@timestamp': {
format: 'strict_date_optional_time',
gte: 'now-1d/d',
lte: 'now/d',
gte: 'now-24h',
lte: 'now',
},
},
},
Expand Down