-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution] Add the ability to filter by index pattern to the rules management table #128245
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
[Security Solution] Add the ability to filter by index pattern to the rules management table #128245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,36 +6,54 @@ | |
| */ | ||
|
|
||
| import { INTERNAL_IMMUTABLE_KEY } from '../../../../../common/constants'; | ||
| import { escapeKuery } from '../../../../common/lib/keury'; | ||
| import { FilterOptions } from './types'; | ||
|
|
||
| const SEARCHABLE_RULE_PARAMS = [ | ||
| 'alert.attributes.name', | ||
| 'alert.attributes.params.index', | ||
| 'alert.attributes.params.threat.tactic.id', | ||
| 'alert.attributes.params.threat.tactic.name', | ||
| 'alert.attributes.params.threat.technique.id', | ||
| 'alert.attributes.params.threat.technique.name', | ||
| ]; | ||
|
Comment on lines
+12
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks, @spong! I'll add |
||
|
|
||
| /** | ||
| * Convert rules filter options object to KQL query | ||
| * | ||
| * @param filterOptions desired filters (e.g. filter/sortField/sortOrder) | ||
| * | ||
| * @returns KQL string | ||
| */ | ||
| export const convertRulesFilterToKQL = (filterOptions: FilterOptions): string => { | ||
| const showCustomRuleFilter = filterOptions.showCustomRules | ||
| ? [`alert.attributes.tags: "${INTERNAL_IMMUTABLE_KEY}:false"`] | ||
| : []; | ||
| const showElasticRuleFilter = filterOptions.showElasticRules | ||
| ? [`alert.attributes.tags: "${INTERNAL_IMMUTABLE_KEY}:true"`] | ||
| : []; | ||
| const filtersWithoutTags = [ | ||
| ...(filterOptions.filter.length ? [`alert.attributes.name: ${filterOptions.filter}`] : []), | ||
| ...showCustomRuleFilter, | ||
| ...showElasticRuleFilter, | ||
| ].join(' AND '); | ||
|
|
||
| const tags = filterOptions.tags | ||
| .map((t) => `alert.attributes.tags: "${t.replace(/"/g, '\\"')}"`) | ||
| .join(' AND '); | ||
|
|
||
| const filterString = | ||
| filtersWithoutTags !== '' && tags !== '' | ||
| ? `${filtersWithoutTags} AND (${tags})` | ||
| : filtersWithoutTags + tags; | ||
|
|
||
| return filterString; | ||
| export const convertRulesFilterToKQL = ({ | ||
| showCustomRules, | ||
| showElasticRules, | ||
| filter, | ||
| tags, | ||
| }: FilterOptions): string => { | ||
| const filters: string[] = []; | ||
|
|
||
| if (showCustomRules) { | ||
| filters.push(`alert.attributes.tags: "${INTERNAL_IMMUTABLE_KEY}:false"`); | ||
| } | ||
|
Comment on lines
+34
to
+38
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is far more readable -- thank you @xcrzx! |
||
|
|
||
| if (showElasticRules) { | ||
| filters.push(`alert.attributes.tags: "${INTERNAL_IMMUTABLE_KEY}:true"`); | ||
| } | ||
|
|
||
| if (tags.length > 0) { | ||
| filters.push( | ||
| `alert.attributes.tags:(${tags.map((tag) => `"${escapeKuery(tag)}"`).join(' AND ')})` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ for bringing in the common |
||
| ); | ||
| } | ||
|
|
||
| if (filter.length) { | ||
| const searchQuery = SEARCHABLE_RULE_PARAMS.map( | ||
| (param) => `${param}: "${escapeKuery(filter)}"` | ||
| ).join(' OR '); | ||
|
|
||
| filters.push(`(${searchQuery})`); | ||
| } | ||
|
|
||
| return filters.join(' AND '); | ||
| }; | ||
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.
cc @MadameSheema -- not sure if you're still tracking cypress changes, but here's a few more. Let me know if you'd like to stop receiving these pings! 🙂