[SIEM] Add rule notifications#59004
Conversation
|
Pinging @elastic/siem (Team:SIEM) |
…e-notifications # Conflicts: # x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/helpers.tsx # x-pack/legacy/plugins/siem/public/shared_imports.ts
…patrykkopycinski/kibana into feat/siem-rule-notifications-alert-type
…patrykkopycinski/kibana into feat/siem-rule-notifications # Conflicts: # x-pack/legacy/plugins/siem/common/constants.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/create_notifications.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/get_signals_count.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/read_notifications.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/rules_notification_alert_type.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/schedule_notification_actions.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/types.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/update_notifications.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/routes/__mocks__/request_responses.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts # x-pack/legacy/plugins/siem/server/plugin.ts
…riables, snakecase for rule params
…e-notifications # Conflicts: # x-pack/legacy/plugins/siem/common/constants.ts # x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/build_signals_query.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/build_signals_query.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/get_signals_count.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/rules_notification_alert_type.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/schedule_notification_actions.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/utils.test.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/notifications/utils.ts # x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts
| group: t.string, | ||
| id: t.string, | ||
| action_type_id: t.string, | ||
| params: t.record(t.string, t.any), |
There was a problem hiding this comment.
t.any is deprecated it looks like and t.unknown is recommended instead. However I think we may be able to just use UnknownRecord ala params: t.UnknownRecord, -- thoughts?
PS: Thanks for the comment above pointing to the action templates 👍
| import React, { useCallback, useEffect, useState } from 'react'; | ||
| import deepMerge from 'deepmerge'; | ||
|
|
||
| // eslint-disable-next-line @kbn/eslint/no-restricted-paths |
There was a problem hiding this comment.
Any context as to why it's okay to import these even though they're coming from a restricted path? Should they not be restricted?
| ruleId: string; | ||
| index: string; | ||
| kibanaUrl: string | undefined; | ||
| kibanaSiemAppUrl: string | {} | undefined; |
There was a problem hiding this comment.
This can't actually be an object, but rather is a byproduct of the typing of meta correct?
If this indeed can only ever be a string, might be best to keep it as such and narrow the type coming from meta in these two files? Thoughts?
| range: { | ||
| '@timestamp': { | ||
| gte: from, | ||
| gt: from, |
There was a problem hiding this comment.
Just commenting to verify the switch from gte to gt as the timestamp supplied to this query:
is the previousStartedAt (or previous interval if n/a), which is the start of the last rule run, correct?
There was a problem hiding this comment.
correct :)
| const mockAction = { | ||
| group: 'default', | ||
| id: '99403909-ca9b-49ba-9d7a-7e5320e68d05', | ||
| params: { message: 'ML Rule generated {{state.signalsCount}} signals' }, |
There was a problem hiding this comment.
I believe this is the old count field as I was not seeing count come through when testing with the default message.
| params: { message: 'ML Rule generated {{state.signalsCount}} signals' }, | |
| params: { message: 'ML Rule generated {{state.signals_count}} signals' }, |
| const theme = () => ({ eui: euiDarkVars, darkMode: true }); | ||
|
|
||
| /* eslint-disable no-console */ | ||
| // Silence until enzyme fixed to use ReactTestUtils.act() |
There was a problem hiding this comment.
Thank you for commenting -- sad to see this come back, but so it goes.
| const kibanaAbsoluteUrl = useMemo(() => application.getUrlForApp('siem', { absolute: true }), [ | ||
| application, | ||
| ]); |
There was a problem hiding this comment.
Thanks for this fix -- I believe this should be fine for cloud, and shouldn't have any effect with CCS since this functionality is specific to rules/saved objects.
spong
left a comment
There was a problem hiding this comment.
Checked out, tested locally and was receiving notifications for signals as expected, and also performed code review. Left a few comments but overall this is fantastic @patrykkopycinski! Thanks for the clean implementation, additional tests, and great feature here! LGMT! 👍 🚀 🙂
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
## 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
Allow defining notifications that will trigger whenever the rule created new signals.
Requires:
Checklist
Delete any items that are not applicable to this PR.
For maintainers