-
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
[SIEM][Detection Engine] Add rule's notification alert type #60832
[SIEM][Detection Engine] Add rule's notification alert type #60832
Conversation
e9cebc0
to
0cea359
Compare
Pinging @elastic/siem (Team:SIEM) |
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.
Just a few minor comments, nothing seems blocking. One question about a new type and its purpose.
Thank you for adding tests, generalizing types, and just generally leaving things better than you found them!
|
||
class TestError extends Error { | ||
constructor() { | ||
// Pass remaining arguments (including vendor specific ones) to parent constructor |
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.
Is this a TODO?
jest.mock('./build_signals_query'); | ||
|
||
describe('rules_notification_alert_type', () => { | ||
const savedObjectsClient = savedObjectsClientMock.create(); |
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.
I would move these to a beforeEach
if possible. The less shared state, the better.
ruleParams, | ||
}: ScheduleNotificationActions): AlertInstance => | ||
alertInstance | ||
.replaceState({ |
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.
👏
@@ -74,6 +70,9 @@ export type RuleTypeParams = Omit< | |||
'name' | 'enabled' | 'interval' | 'tags' | 'actions' | 'throttle' | |||
>; | |||
|
|||
export type RuleTypeParamsWithName = RuleTypeParams & { |
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.
Why the special casing of name
, here? Is it possible to use it throughout our SIEM alerts, or do we expressly not want it in other alerts?
const action = { | ||
group: 'default', | ||
id: '99403909-ca9b-49ba-9d7a-7e5320e68d05', | ||
params: { message: 'Rule generated {{state.signalsCount}} singals' }, |
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.
params: { message: 'Rule generated {{state.signalsCount}} singals' }, | |
params: { message: 'Rule generated {{state.signalsCount}} signals' }, |
const action = { | ||
group: 'default', | ||
id: '99403909-ca9b-49ba-9d7a-7e5320e68d05', | ||
params: { message: 'Rule generated {{state.signalsCount}} singals' }, |
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.
params: { message: 'Rule generated {{state.signalsCount}} singals' }, | |
params: { message: 'Rule generated {{state.signalsCount}} signals' }, |
{ | ||
group: 'default', | ||
id: '99403909-ca9b-49ba-9d7a-7e5320e68d05', | ||
params: { message: 'Rule generated {{state.signalsCount}} singals' }, |
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.
params: { message: 'Rule generated {{state.signalsCount}} singals' }, | |
params: { message: 'Rule generated {{state.signalsCount}} signals' }, |
{ | ||
actionTypeId: '.slack', | ||
params: { | ||
message: 'Rule generated {{state.signalsCount}} singals\n\n{{rule.name}}\n{{resultsLink}}', |
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.
message: 'Rule generated {{state.signalsCount}} singals\n\n{{rule.name}}\n{{resultsLink}}', | |
message: 'Rule generated {{state.signalsCount}} signals\n\n{{rule.name}}\n{{resultsLink}}', |
name: i18n.translate( | ||
'xpack.siem.detectionEngine.ruleNotificationAlert.actionGroups.default', | ||
{ | ||
defaultMessage: 'Default', | ||
} | ||
), |
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.
I thought there wasn't any i18n
on the server side -- are we able to do this now, and if so, do you know how the locale gets correctly set?
from: previousStartedAt ?? `now-${ruleParams.interval}`, | ||
to: startedAt, |
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.
Not sure if this daterange is the issue or if it's timing from the signals being written, but I'm sometimes seeing mis-match signals counts in the server logs between signalsRulesAlertType
and rulesNotificationsAlertType
, and then the action is not fired.
e.g. here's the server log from when a single rule runs:
server log [17:00:04.302] [info][plugins][siem] Found 55 signals from the indexes of "[apm-*-transaction*, auditbeat-*, endgame-*, filebeat-*, packetbeat-*, winlogbeat-*]" using signal rule name: "Signal Generator 7k", id: "c0880b7e-0bbb-4ef2-9471-056d36741ba0", rule_id: "38bcddb9-8751-40b8-8244-04254c7a818c", pushing signals to index ".siem-signals-spong-default"
server log [17:00:05.267] [info][plugins][siem] Found 0 signals using signal rule name: "Signal Generator 7k", id: "38bcddb9-8751-40b8-8244-04254c7a818c", rule_id: "38bcddb9-8751-40b8-8244-04254c7a818c" in ".siem-signals-spong-default" index
Which does not result in the rule's action being completed (slack message in this instance). No explicit repro steps yet, but I've noticed it mostly when editing an action after a rule has been created, and then this happens the next time the rule runs.
@@ -151,12 +153,24 @@ export class Plugin { | |||
}); | |||
|
|||
if (plugins.alerting != null) { | |||
const type = signalRulesAlertType({ | |||
const { host, port, protocol } = core.http.getServerInfo(); | |||
const kibanaUrl = `${protocol}://${host}:${port}`; |
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.
Not sure if this will work on cloud -- may want to touch base with the platform team to ensure this will be fine there.
|
||
export const createRules = ({ | ||
export const createRules = async ({ | ||
alertsClient, | ||
actionsClient, // TODO: Use this actionsClient once we have actions such as email, etc... |
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.
Is this TODO/prop still necessary?
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.
I'm going to clean up actionsClient
and the comments afterward :)
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.
Checked out, tested locally via UI provided in #59004, and performed a code review. Left a few nits but looks good to me! 👍 Was able to configure slack notifications and receive message when rules were run -- great work here @patrykkopycinski! 🙂🚀
…patrykkopycinski/kibana into feat/siem-rule-notifications-alert-type
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* master: Updating our direct usage of https-proxy-agent to 5.0.0 (elastic#58296) allow users to unset the throttle of an alert (elastic#60964) [Lens] Fix bug in metric config panel (elastic#60982) [SearchProfiler] Minor fixes (elastic#60919) [ML] Renaming ML setup and start contracts (elastic#60980) introduce StartServicesAccessor type for `CoreSetup.getStartServices` (elastic#60748) [SIEM][Detection Engine] Add rule's notification alert type (elastic#60832) [APM] Re-revert "Collect telemetry about data/API performance" (elastic#61030) [NP] Graph: get rid of saved objects class wrapper (elastic#59917) [EPM] merge duplicate fields when creating index patterns (elastic#60957) [Uptime] Ml detection of duration anomalies (elastic#59785) [Alerting] removes unimplemented buttons from Alert Details page (elastic#60934) [skip-ci] Fix CODEOWNERS paths for the Pulse team (elastic#60944) [APM] Threshold alerts (elastic#59566) [ML] Add support for percentiles aggregation to Transform wizard (elastic#60763) Cahgen save object duplicate message (elastic#60901)
## Summary Allow defining notifications that will trigger whenever the rule created new signals. Requires: - #58395 - #58964 - #60832 ![Screenshot 2020-03-02 at 10 19 18](https://user-images.githubusercontent.com/5188868/75662390-4fe8bf00-5c6f-11ea-943f-591367348b91.png) ![Screenshot 2020-03-02 at 10 13 00](https://user-images.githubusercontent.com/5188868/75662421-5e36db00-5c6f-11ea-9317-d158cddf4344.png) ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md) - [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios - [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server) - [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
## Summary Allow defining notifications that will trigger whenever the rule created new signals. Requires: - elastic#58395 - elastic#58964 - elastic#60832 ![Screenshot 2020-03-02 at 10 19 18](https://user-images.githubusercontent.com/5188868/75662390-4fe8bf00-5c6f-11ea-943f-591367348b91.png) ![Screenshot 2020-03-02 at 10 13 00](https://user-images.githubusercontent.com/5188868/75662421-5e36db00-5c6f-11ea-9317-d158cddf4344.png) ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md) - [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios - [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server) - [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
## Summary Allow defining notifications that will trigger whenever the rule created new signals. Requires: - #58395 - #58964 - #60832 ![Screenshot 2020-03-02 at 10 19 18](https://user-images.githubusercontent.com/5188868/75662390-4fe8bf00-5c6f-11ea-943f-591367348b91.png) ![Screenshot 2020-03-02 at 10 13 00](https://user-images.githubusercontent.com/5188868/75662421-5e36db00-5c6f-11ea-9317-d158cddf4344.png) ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md) - [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios - [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server) - [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process) Co-authored-by: patrykkopycinski <[email protected]>
Summary
Part of #59004
SignalRuleAlertType
Checklist
Delete any items that are not applicable to this PR.
For maintainers