[SIEM][Detection Engine] Add rule's notification alert type#60832
Conversation
e9cebc0 to
0cea359
Compare
|
Pinging @elastic/siem (Team:SIEM) |
rylnd
left a comment
There was a problem hiding this comment.
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 |
| jest.mock('./build_signals_query'); | ||
|
|
||
| describe('rules_notification_alert_type', () => { | ||
| const savedObjectsClient = savedObjectsClientMock.create(); |
There was a problem hiding this comment.
I would move these to a beforeEach if possible. The less shared state, the better.
| ruleParams, | ||
| }: ScheduleNotificationActions): AlertInstance => | ||
| alertInstance | ||
| .replaceState({ |
| 'name' | 'enabled' | 'interval' | 'tags' | 'actions' | 'throttle' | ||
| >; | ||
|
|
||
| export type RuleTypeParamsWithName = RuleTypeParams & { |
There was a problem hiding this comment.
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.
| 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.
| 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.
| 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.
| 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.
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.
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.
| 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.
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.
Is this TODO/prop still necessary?
There was a problem hiding this comment.
I'm going to clean up actionsClient and the comments afterward :)
spong
left a comment
There was a problem hiding this comment.
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   ### 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   ### 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   ### 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 <patryk.kopycinski@elastic.co>
Summary
Part of #59004
SignalRuleAlertTypeChecklist
Delete any items that are not applicable to this PR.
For maintainers