-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Detections] Handle dupes when processing threshol…
…d rules (#83062) * Fix threshold rule synthetic signal generation * Use top_hits aggregation * Find signals and aggregate over search terms * Exclude dupes * Fixes to algorithm * Sync timestamps with events/signals * Add timestampOverride * Revert changes in signal creation * Simplify query, return 10k buckets * Account for when threshold.field is not supplied * Ensure we're getting the last event when threshold.field is not provided * Add missing import * Handle case where threshold field not supplied * Fix type errors * Handle non-ECS fields * Regorganize * Address comments * Fix type error * Add unit test for buildBulkBody on threshold results * Add threshold_count back to mapping (and deprecate) * Timestamp fixes Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
d21e4f5
commit bdf7b88
Showing
12 changed files
with
296 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
.../security_solution/server/lib/detection_engine/signals/find_previous_threshold_signals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TimestampOverrideOrUndefined } from '../../../../common/detection_engine/schemas/common/schemas'; | ||
import { singleSearchAfter } from './single_search_after'; | ||
|
||
import { AlertServices } from '../../../../../alerts/server'; | ||
import { Logger } from '../../../../../../../src/core/server'; | ||
import { SignalSearchResponse } from './types'; | ||
import { BuildRuleMessage } from './rule_messages'; | ||
|
||
interface FindPreviousThresholdSignalsParams { | ||
from: string; | ||
to: string; | ||
indexPattern: string[]; | ||
services: AlertServices; | ||
logger: Logger; | ||
ruleId: string; | ||
bucketByField: string; | ||
timestampOverride: TimestampOverrideOrUndefined; | ||
buildRuleMessage: BuildRuleMessage; | ||
} | ||
|
||
export const findPreviousThresholdSignals = async ({ | ||
from, | ||
to, | ||
indexPattern, | ||
services, | ||
logger, | ||
ruleId, | ||
bucketByField, | ||
timestampOverride, | ||
buildRuleMessage, | ||
}: FindPreviousThresholdSignalsParams): Promise<{ | ||
searchResult: SignalSearchResponse; | ||
searchDuration: string; | ||
searchErrors: string[]; | ||
}> => { | ||
const aggregations = { | ||
threshold: { | ||
terms: { | ||
field: 'signal.threshold_result.value', | ||
}, | ||
aggs: { | ||
lastSignalTimestamp: { | ||
max: { | ||
field: 'signal.original_time', // timestamp of last event captured by bucket | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const filter = { | ||
bool: { | ||
must: [ | ||
{ | ||
term: { | ||
'signal.rule.rule_id': ruleId, | ||
}, | ||
}, | ||
{ | ||
term: { | ||
'signal.rule.threshold.field': bucketByField, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
return singleSearchAfter({ | ||
aggregations, | ||
searchAfterSortId: undefined, | ||
timestampOverride, | ||
index: indexPattern, | ||
from, | ||
to, | ||
services, | ||
logger, | ||
filter, | ||
pageSize: 0, | ||
buildRuleMessage, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.