Skip to content

Support import filter expressions #1742

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

Merged
merged 2 commits into from
Jul 9, 2021

Conversation

dominiklohmann
Copy link
Member

@dominiklohmann dominiklohmann commented Jun 23, 2021

📔 Description

We have long advertised this feature in the documentation of the import command, but never gotten around to implementing it. Turns out it really is quite simple to implement with the new filter function on table slices.

Here's how you can use it:

# Do not import Suricata.stats events as they are rather meaningless.
vast import suricata '#type != "suricata.stats"'

# Import only indicators to a matcher whose 'type' field is 'ip' or
# 'ipv6' (requires the proprietary Live Matching plugin).
vast matcher import -t my-ioc csv my-matcher 'type == "ip" || type == "ipv6"'

📝 Checklist

  • All user-facing changes have changelog entries.
  • The changes are reflected on docs.tenzir.com/vast, if necessary.
  • The PR description contains instructions for the reviewer, if necessary.

🎯 Review Instructions

File-by-file. Give it a spin locally.

@dominiklohmann dominiklohmann added the feature New functionality label Jun 23, 2021
@dominiklohmann dominiklohmann requested a review from a team June 23, 2021 20:27
@dominiklohmann dominiklohmann force-pushed the topic/import-filter-expressions branch from 5ff41e4 to 95bc328 Compare July 5, 2021 10:00
We have long advertised this feature in the documentation of the import
command, but never gotten around to implementing it. Turns out it really
is quite simple to implement with the new `filter` function on table
slices.

Here's how you can use it:

```bash
# Do not import Suricata.stats events as they are rather meaningless.
vast import suricata '#type != "suricata.stats"'

# Import only indicators to a matcher that have whose 'type' field is
# 'ip' or 'ipv6' (requires the proprietary Live Matching plugin).
vast matcher import -t my-ioc csv my-matcher 'type == "ip" || type == "ipv6"'
```
@dominiklohmann dominiklohmann force-pushed the topic/import-filter-expressions branch from 95bc328 to ca1940b Compare July 5, 2021 10:02
Copy link
Member

@tobim tobim left a comment

Choose a reason for hiding this comment

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

Looks good, but let's avoid flooding VERBOSE.

Comment on lines 110 to 126
const auto unfiltered_rows = slice.rows();
if (self->state.filter) {
if (auto filtered_slice
= filter(std::move(slice), *self->state.filter)) {
VAST_VERBOSE("{} forwards {}/{} produced {} events after filtering",
self, filtered_slice->rows(), unfiltered_rows,
slice.layout().name());
self->state.mgr->out().push(std::move(*filtered_slice));
} else {
VAST_VERBOSE("{} forwards 0/{} produced {} events after filtering",
self, unfiltered_rows, slice.layout().name());
}
} else {
VAST_VERBOSE("{} forwards {} produced {} events", self,
unfiltered_rows, slice.layout().name());
self->state.mgr->out().push(std::move(slice));
}
Copy link
Member

Choose a reason for hiding this comment

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

The log severity for all of those messages has to be DEBUG.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I also moved the logic to a function in the source state that is used for both source types.

@dominiklohmann dominiklohmann requested a review from tobim July 9, 2021 11:53
@dominiklohmann dominiklohmann merged commit 4070f39 into master Jul 9, 2021
@dominiklohmann dominiklohmann deleted the topic/import-filter-expressions branch July 9, 2021 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants