-
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] Add rule notifications #59004
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.
@@ -21,7 +21,7 @@ interface GetSignalsCount { | |||
ruleAlertId: string; | |||
ruleId: string; | |||
index: string; | |||
kibanaUrl: string | undefined; | |||
kibanaSiemAppUrl: string | {} | undefined; |
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.
This can't actually be an object
, but rather is a byproduct of the typing of meta
correct?
meta: Record<string, {} | string> | undefined | null; |
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?
Line 50 in 7e82730
kibanaSiemAppUrl: ruleAlertParams.meta?.kibanaSiemAppUrl, |
kibana/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts
Line 223 in b9c8291
kibanaSiemAppUrl: meta.kibanaSiemAppUrl, |
@@ -30,7 +30,7 @@ export const buildSignalsSearchQuery = ({ ruleId, index, from, to }: BuildSignal | |||
{ | |||
range: { | |||
'@timestamp': { | |||
gte: from, | |||
gt: from, |
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 commenting to verify the switch from gte
to gt
as the timestamp supplied to this query:
Line 46 in 7e82730
from: previousStartedAt ?? `now-${ruleParams.interval}`, |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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' }, |
@@ -15,6 +15,17 @@ import { stepAboutDefaultValue } from './default_value'; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 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 <[email protected]>
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