Skip to content

Add Elasticsearch output plugin (#374)#923

Merged
max-vogler merged 2 commits into
google:masterfrom
micrictor:master
Apr 26, 2021
Merged

Add Elasticsearch output plugin (#374)#923
max-vogler merged 2 commits into
google:masterfrom
micrictor:master

Conversation

@micrictor
Copy link
Copy Markdown
Contributor

Creates an Elasticsearch output plugin using the _bulk API.

In the config file, the GRR Admin sets:

  • url - Required; the Elasticsearch endpoint to index the documents at
  • token - Optional; The authentication token to include with the indexing requests
  • verify_https - Optional; Whether to validate the server certificate. Includes a disclaimer on why this is a bad idea
  • index - Optional; The elasticsearch index to place the flow results into; Default "grr-flows"

When executing the flow, the operator can specify:

  • tags - Arbitrary tags placed on the flow document(s)
  • index - Destination index for the documents, if desired to override the configured index

Note that, as a collateral change, I had to add an optional indent parameter to the json.Dump method to avoid messing up the line-delimited nature of the Elasticsearch API.

This resolves #374

@max-vogler max-vogler self-requested a review April 9, 2021 11:29
Copy link
Copy Markdown
Member

@max-vogler max-vogler left a comment

Choose a reason for hiding this comment

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

Thank you for this amazing pull request! I'm pre-approving, because there are only minor code health changes to be made and I am out of office next week. One of my teammates can merge next week or I can merge the week after when I'm back.

Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin_test.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin_test.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin.py Outdated
@micrictor
Copy link
Copy Markdown
Contributor Author

micrictor commented Apr 9, 2021 via email

@micrictor micrictor closed this Apr 12, 2021
@micrictor micrictor reopened this Apr 12, 2021
Copy link
Copy Markdown
Member

@panhania panhania left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request! I left some comments in addition to the @max-vogler's review.

Comment thread grr/core/grr_response_core/config/output_plugins.py Outdated
Comment thread grr/core/grr_response_core/lib/util/compat/json.py
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin_test.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin_test.py Outdated
Comment thread grr/server/grr_response_server/output_plugins/elasticsearch_plugin_test.py Outdated
Comment on lines +61 to +57
if patcher is None:
patcher = mock.patch.object(requests, 'post')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can look into the responses package (used for example here).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably going to leave this alone for now, unless you think it should be blocking.

@micrictor
Copy link
Copy Markdown
Contributor Author

Pushed in the updates discussed above - mostly removing python2 compatibility stuff, adding docs for the new indent parameter, and other minor formatting fixes.

As noted above, I didn't port the tests to use responses, and don't really intend on doing so. If that's blocking, this PR will likely stay open for quite some time before I circle back to that (or someone else picks it up)

@max-vogler
Copy link
Copy Markdown
Member

I suggest merging without the responses test refactoring in order to merge this functionality. The test is very close to splunk_plugin_test.py, which uses the same mocking. In the future, one change can refactor both tests. @panhania WDYT?

@panhania
Copy link
Copy Markdown
Member

Sounds reasonable to me.

@max-vogler max-vogler merged commit 6942fa3 into google:master Apr 26, 2021
@max-vogler
Copy link
Copy Markdown
Member

Thanks a lot for your contribution @micrictor, well done! If you like, send me a PR that adds your name and email to ACKNOWLEDGEMENTS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement elasticsearch output plugin

3 participants