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

Enable redline CSV support in upload #642

Closed
wants to merge 1 commit into from

Conversation

berggren
Copy link
Contributor

Refactor the CSV importer to support Redline CSV as well.

@berggren berggren self-assigned this Jun 24, 2018
@berggren berggren requested review from tomchop and removed request for adamjnichols August 14, 2018 08:45
redline_intersection = set(
redline_fields).intersection(set(csv_header))
if len(redline_fields) == len(redline_intersection):
return u'redline'
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand what you're trying to achieve, I think set(redline_fields).issubset(set(csv_header)) has the same effect and is more readable.

timesketch_intersection = timesketch_fields.intersection(
set(csv_header))
if len(timesketch_fields) == len(timesketch_intersection):
return u'timesketch'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above

# check if it is the right redline format
mandatory_fields = [u'Alert', u'Tag', u'Timestamp', u'Field', u'Summary']
Returns:
Generator of event rows
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would also be useful to know what type event rows are.

yield row_to_yield
csv_dialect = get_csv_dialect(csv_header)

if u'redline' in csv_dialect:
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems that get_csv_dialect returns a string, not an array of strings. I think you want to use csv_dialect == 'redline'. Also, this will fail if csv_dialect is None.

continue
yield row
else:
raise RuntimeError(u'Unknown CSV format')
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can turn this into a guard statement before the other checks

if csv_dialect is None:
    raise RuntimeError()

if csv_dialect == 'timesketch':
    ...

if csv_dialect == 'redline':
    ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the proposal

@jaegeral
Copy link
Collaborator

@berggren any chance to review the changes from @tomchop

@berggren
Copy link
Contributor Author

This PR got lost in some other updates. This PR is partly obsolete and the validation of CSVs are being reworked. I'm dropping this one as thing are changing soon. Will enable redline uploads soon.

@berggren berggren closed this Dec 26, 2018
@berggren berggren deleted the upload-redline-support branch January 22, 2019 15:53
@jaegeral jaegeral mentioned this pull request Aug 22, 2019
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.

3 participants