-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security] Alert Telemetry for the Security app #77200
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e2250a9
Empty recurring task
tsg da753fe
Added processEvents with tests
tsg 6335857
SendIfDue + tests
tsg c302fdd
Connect telemetry in the detection engine
tsg 5e14df8
Respect opt-in status
tsg 7bcf141
test fixes + test for telemetry disabled
tsg 483e3cf
Various type fixes
tsg 0cd31af
Merge branch 'master' into telemetry_events
elasticmachine 65a5078
Add cluster_uuid and cluster_name
tsg fb6b3ea
Filter by endpoint alerts
tsg 2fdc70c
type fixes + tests
tsg 725fc54
mege master
tsg 069147f
fix types
tsg 896ca96
merge master
tsg 0ae4046
Refactor processEvents
tsg 2f31f49
Send events to the telemetry server
tsg f8309c9
Small refactoring
tsg b2df3a8
Add license fields
tsg e6a2d71
Update x-pack/plugins/security_solution/server/lib/detection_engine/s…
tsg 722e68d
Move undefined check in the function to simplify top level code
tsg 5f25435
Correct datastream to data_stream
tsg 1a29cbd
Incorporated Xavier's feedback + add license header
tsg 0dda88c
Test fix + minor changes
tsg 23fbe32
Commented out verbose debug logs
tsg 52390cf
Merge branch 'master' into telemetry_events
elasticmachine d0d52f4
Merge branch 'master' into telemetry_events
elasticmachine e8b364d
Merge branch 'master' into telemetry_events
elasticmachine 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,7 +27,8 @@ | |
| "spaces", | ||
| "usageCollection", | ||
| "lists", | ||
| "home" | ||
| "home", | ||
| "telemetry" | ||
| ], | ||
| "server": true, | ||
| "ui": true, | ||
|
|
||
This file contains hidden or 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 hidden or 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
78 changes: 78 additions & 0 deletions
78
...ugins/security_solution/server/lib/detection_engine/signals/send_telemetry_events.test.ts
This file contains hidden or 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,78 @@ | ||
| /* | ||
| * 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 { selectEvents } from './send_telemetry_events'; | ||
|
|
||
| describe('sendAlertTelemetry', () => { | ||
| it('selectEvents', () => { | ||
| const filteredEvents = { | ||
| took: 0, | ||
| timed_out: false, | ||
| _shards: { | ||
| total: 1, | ||
| successful: 1, | ||
| failed: 0, | ||
| skipped: 0, | ||
| }, | ||
| hits: { | ||
| total: 2, | ||
| max_score: 0, | ||
| hits: [ | ||
| { | ||
| _index: 'x', | ||
| _type: 'x', | ||
| _id: 'x', | ||
| _score: 0, | ||
| _source: { | ||
| '@timestamp': 'x', | ||
| key1: 'hello', | ||
| datastream: { | ||
| dataset: 'endpoint.events', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| _index: 'x', | ||
| _type: 'x', | ||
| _id: 'x', | ||
| _score: 0, | ||
| _source: { | ||
| '@timestamp': 'x', | ||
| key2: 'hello', | ||
| datastream: { | ||
| dataset: 'endpoint.alerts', | ||
| other: 'x', | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| _index: 'x', | ||
| _type: 'x', | ||
| _id: 'x', | ||
| _score: 0, | ||
| _source: { | ||
| '@timestamp': 'x', | ||
| key3: 'hello', | ||
| datastream: {}, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| const sources = selectEvents(filteredEvents); | ||
| expect(sources).toStrictEqual([ | ||
| { | ||
| '@timestamp': 'x', | ||
| key2: 'hello', | ||
| datastream: { | ||
| dataset: 'endpoint.alerts', | ||
| other: 'x', | ||
| }, | ||
| }, | ||
| ]); | ||
| }); | ||
| }); |
44 changes: 44 additions & 0 deletions
44
...ck/plugins/security_solution/server/lib/detection_engine/signals/send_telemetry_events.ts
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * 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 { TelemetryEventsSender, TelemetryEvent } from '../../telemetry/sender'; | ||
| import { RuleTypeParams } from '../types'; | ||
| import { BuildRuleMessage } from './rule_messages'; | ||
| import { SignalSearchResponse, SignalSource } from './types'; | ||
| import { Logger } from '../../../../../../../src/core/server'; | ||
|
|
||
| export interface SearchResultWithSource { | ||
| _source: SignalSource; | ||
| } | ||
|
|
||
| export function selectEvents(filteredEvents: SignalSearchResponse): TelemetryEvent[] { | ||
| const sources = filteredEvents.hits.hits.map(function ( | ||
| obj: SearchResultWithSource | ||
| ): TelemetryEvent { | ||
| return obj._source; | ||
| }); | ||
|
|
||
| return sources.filter(function (obj: TelemetryEvent) { | ||
| // Filter out non-endpoint alerts | ||
| return obj.datastream?.dataset === 'endpoint.alerts'; | ||
| }); | ||
| } | ||
|
|
||
| export function sendAlertTelemetryEvents( | ||
| logger: Logger, | ||
| eventsTelemetry: TelemetryEventsSender, | ||
| filteredEvents: SignalSearchResponse, | ||
| ruleParams: RuleTypeParams, | ||
| buildRuleMessage: BuildRuleMessage | ||
| ) { | ||
| const sources = selectEvents(filteredEvents); | ||
|
|
||
| try { | ||
| eventsTelemetry.queueTelemetryEvents(sources); | ||
| } catch (exc) { | ||
| logger.error(buildRuleMessage(`[-] queing telemetry events failed ${exc}`)); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.