-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][Detections] Handle dupes when processing threshold rules #83062
Merged
Merged
Changes from 25 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7ac4f7d
Fix threshold rule synthetic signal generation
madirey fba2636
Merge branch 'master' of github.com:elastic/kibana into cidr-house-rules
madirey 352a139
Merge branch 'master' of github.com:elastic/kibana into cidr-house-rules
madirey 0c9d5e3
Use top_hits aggregation
madirey 2f61b30
Find signals and aggregate over search terms
madirey 56e558a
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 4610643
Exclude dupes
madirey 3fa0e69
Fixes to algorithm
madirey 0c3c1e7
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 35e2119
Sync timestamps with events/signals
madirey 29641b6
Merge branch 'master' of github.com:elastic/kibana into cidr-house-rules
madirey 5914e99
Add timestampOverride
madirey 26c7c0d
Merge branch 'cidr-house-rules' into threshold-dupes
madirey 7bbd12a
Revert changes in signal creation
madirey 399d886
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 960ed9b
Simplify query, return 10k buckets
madirey 8591886
Account for when threshold.field is not supplied
madirey a90af11
Merge branch 'master' of github.com:elastic/kibana into cidr-house-rules
madirey bf910ab
Ensure we're getting the last event when threshold.field is not provided
madirey 2396190
Merge branch 'cidr-house-rules' into threshold-dupes
madirey 83f81cb
Add missing import
madirey 3052975
Merge branch 'cidr-house-rules' into threshold-dupes
madirey 8d6c81d
Handle case where threshold field not supplied
madirey a087823
Fix type errors
madirey 2e424f1
Merge master
madirey c898480
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 925acc7
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey ae24022
Handle non-ECS fields
madirey 2c8dcfa
Regorganize
madirey 8a7c84a
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 49044a6
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 974a5a3
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 23e4ec3
Address comments
madirey 2bc904f
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 1e8d122
Fix type error
madirey 3a54495
Add unit test for buildBulkBody on threshold results
madirey e5f2593
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 80a582a
Add threshold_count back to mapping (and deprecate)
madirey fe956ad
Merge branch 'master' of github.com:elastic/kibana into threshold-dupes
madirey 2c61c26
Timestamp fixes
madirey a855a19
Merge branch 'master' into threshold-dupes
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
.../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,76 @@ | ||
/* | ||
* 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: bucketByField ?? 'signal.rule.rule_id', | ||
}, | ||
aggs: { | ||
lastSignalTimestamp: { | ||
max: { | ||
field: 'signal.original_time', // timestamp of last event captured by bucket | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const filter = { | ||
term: { | ||
'signal.rule.rule_id': ruleId, | ||
}, | ||
}; | ||
|
||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
bucketByField
is a non-ECS field then it won't be mapped in the signals index - in that case I don't think the aggregation will return any results.Also the
event.*
fields move tooriginal_event.*
in the signals index sobucketByField
will need to go through a translation before being used on the signals index remove duplicates for threshold rules onevent.*
fields.