Skip to content
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

Merged
merged 135 commits into from
Mar 24, 2020

Conversation

patrykkopycinski
Copy link
Contributor

@patrykkopycinski patrykkopycinski commented Mar 2, 2020

Summary

Allow defining notifications that will trigger whenever the rule created new signals.

Requires:

Screenshot 2020-03-02 at 10 19 18

Screenshot 2020-03-02 at 10 13 00

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@patrykkopycinski patrykkopycinski changed the title [SIEM] Add rule notifications [WIP][SIEM] Add rule notifications Mar 2, 2020
@patrykkopycinski patrykkopycinski changed the title [WIP][SIEM] Add rule notifications [SIEM] Add rule notifications Mar 23, 2020
…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
…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),
Copy link
Member

@spong spong Mar 24, 2020

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadActionTypes are not exposed on top-level, but we need that to fetch current action types and then to filter only supported ones. It's a temporary solution, will talk to the alerting team to make sure loadActionTypes is exposed on the top-level
image

@@ -21,7 +21,7 @@ interface GetSignalsCount {
ruleAlertId: string;
ruleId: string;
index: string;
kibanaUrl: string | undefined;
kibanaSiemAppUrl: string | {} | undefined;
Copy link
Member

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?


@@ -30,7 +30,7 @@ export const buildSignalsSearchQuery = ({ ruleId, index, from, to }: BuildSignal
{
range: {
'@timestamp': {
gte: from,
gt: from,
Copy link
Member

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:

is the previousStartedAt (or previous interval if n/a), which is the start of the last rule run, correct?

Copy link
Contributor Author

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' },
Copy link
Member

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.

Suggested change
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()
Copy link
Member

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.

Comment on lines +58 to +60
const kibanaAbsoluteUrl = useMemo(() => application.getUrlForApp('siem', { absolute: true }), [
application,
]);
Copy link
Member

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.

Copy link
Member

@spong spong left a 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! 👍 🚀 🙂

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@spong spong merged commit f9d37b3 into elastic:master Mar 24, 2020
spong pushed a commit to spong/kibana that referenced this pull request Mar 24, 2020
## 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)
@alexfrancoeur
Copy link

🎉 🎉🎉🎉

spong added a commit that referenced this pull request Mar 25, 2020
## 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]>
@patrykkopycinski patrykkopycinski deleted the feat/siem-rule-notifications branch March 26, 2020 11:28
@spong spong mentioned this pull request May 8, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants