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

Added import stream object for more flexible data upload #1004

Merged
merged 35 commits into from
Oct 29, 2019

Conversation

kiddinn
Copy link
Contributor

@kiddinn kiddinn commented Oct 23, 2019

Adding an import stream object that has the ability to:

  • To upload pandas data frames, python dict, JSON and Excel sheets.
  • Allowing streaming results from external parsers to TS.

Other features:

  • Changed the API to allow appending data to an index
  • Changed the AIP to allow for only indexing newly added data, and no analyzer runs
  • Added the ability to kick start auto analyzers on an index to the API.
  • Minor bugfixes in the API and the API client

@kiddinn
Copy link
Contributor Author

kiddinn commented Oct 23, 2019

This is still WIP, just uploading to demonstrate a bit where I was going with this.

Still need to test it (haven't tested it once), which will most likely results in some unit tests being added as well as major or minor changes to the actual code.

@kiddinn kiddinn changed the title Added more upload options to API client Added import stream object to the client API for more flexible data upload Oct 28, 2019
@kiddinn kiddinn requested a review from berggren October 28, 2019 16:32
@kiddinn kiddinn self-assigned this Oct 28, 2019
@kiddinn kiddinn marked this pull request as ready for review October 28, 2019 16:32
@kiddinn kiddinn changed the title Added import stream object to the client API for more flexible data upload Added import stream object for more flexible data upload Oct 28, 2019
Copy link
Contributor

@berggren berggren left a comment

Choose a reason for hiding this comment

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

First round of comments.

string_items.append('{0:s} = {{0!s}}'.format(column))
format_message_string = ' '.join(string_items)

response = None
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename to streamer_response ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return 'No return value.'

return_lines = []
for timesketch_object in response.get('objects', []):
Copy link
Contributor

Choose a reason for hiding this comment

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

sketch_object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@@ -1368,6 +1369,50 @@ def post(self, sketch_id):
annotations, status_code=HTTP_STATUS_CODE_CREATED)


class AnalyzerPipelineResource(ResourceMixin, Resource):
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we want to extend this to also accept an analyzer name? So we can run a specific analyzer instead of all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is already supported in the AnalyzerRunResource

Decided to do this differently, removed this entire resource, merged it with the run resource, and made it so that we can run a single or multiple analyzers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also deleted the form so that we now just use request.json instead of the form

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, SG

timesketch/api/v1/resources.py Outdated Show resolved Hide resolved
# Create the search index in the Timesketch database
searchindex = SearchIndex.get_or_create(
# Check if search index already exists.
searchindex = SearchIndex.query.filter_by(
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, why not use get_or_create() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to create one here if it doesn't exist, only querying whether it exists or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

ack

timesketch/api/v1/routes.py Outdated Show resolved Hide resolved
@@ -0,0 +1,201 @@
# Create Timeline From Other Sources
Copy link
Contributor

Choose a reason for hiding this comment

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

Kudos for great documentation :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

;)

there are some TODOs there though

Copy link
Contributor Author

@kiddinn kiddinn left a comment

Choose a reason for hiding this comment

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

done with round

string_items.append('{0:s} = {{0!s}}'.format(column))
format_message_string = ' '.join(string_items)

response = None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return 'No return value.'

return_lines = []
for timesketch_object in response.get('objects', []):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@@ -0,0 +1,201 @@
# Create Timeline From Other Sources
Copy link
Contributor Author

Choose a reason for hiding this comment

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

;)

there are some TODOs there though

@@ -1368,6 +1369,50 @@ def post(self, sketch_id):
annotations, status_code=HTTP_STATUS_CODE_CREATED)


class AnalyzerPipelineResource(ResourceMixin, Resource):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is already supported in the AnalyzerRunResource

Decided to do this differently, removed this entire resource, merged it with the run resource, and made it so that we can run a single or multiple analyzers.

@@ -1368,6 +1369,50 @@ def post(self, sketch_id):
annotations, status_code=HTTP_STATUS_CODE_CREATED)


class AnalyzerPipelineResource(ResourceMixin, Resource):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also deleted the form so that we now just use request.json instead of the form

# Create the search index in the Timesketch database
searchindex = SearchIndex.get_or_create(
# Check if search index already exists.
searchindex = SearchIndex.query.filter_by(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to create one here if it doesn't exist, only querying whether it exists or not.

timesketch/api/v1/resources.py Outdated Show resolved Hide resolved
timesketch/api/v1/routes.py Outdated Show resolved Hide resolved
@kiddinn
Copy link
Contributor Author

kiddinn commented Oct 29, 2019

@berggren PTAL

@kiddinn kiddinn requested a review from berggren October 29, 2019 15:06
Copy link
Contributor

@berggren berggren left a comment

Choose a reason for hiding this comment

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

Just one small thing, otherwise LG

timesketch/api/v1/resources.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@kiddinn kiddinn left a comment

Choose a reason for hiding this comment

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

done

timesketch/api/v1/resources.py Outdated Show resolved Hide resolved
@kiddinn kiddinn requested a review from berggren October 29, 2019 15:24
Copy link
Contributor

@berggren berggren left a comment

Choose a reason for hiding this comment

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

LGTM

@kiddinn kiddinn merged commit b5fff65 into google:master Oct 29, 2019
@kiddinn kiddinn deleted the stream_upload branch October 29, 2019 15:35
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.

2 participants