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

New Parser for JSON data #1684

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

kbrajneesh
Copy link
Contributor

This parser can translate json key into harmonized key field and can create events from list of dict within key of JSON.

"json_data_format": true,
"json_data_key": "data.ipdata"

With above configuration, list of dict will be created from list present in json["data"]["ipdata"]. Each dict will then create atleast an event.
Copy link

Choose a reason for hiding this comment

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

What if the data is in json["data.ipdata"]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will still work. if we have both json["data"]["ipdata"] and json["data.ipdata"], the one which is later defined, will override the other and its value will be assigned in key "data.ipdata" of flattened json.

Copy link

Choose a reason for hiding this comment

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

If json_data_key can only be used in conjunction with json_data_format, why use two different parameters?

@ghost ghost self-requested a review December 14, 2020 17:23
Copy link

@ghost ghost 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 contribution! That's definitely a long-awaited parser :)

I only had a look at the added documentation so far.


**Configuration parameters**

* `"json_data_format"`: Boolean, if list of data is within key of json object, optional. Default: false.
Copy link

Choose a reason for hiding this comment

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

Please expand the explanation, examples are also helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

json_data_format will be True if there is a single json and list of data is inside any of its child nodes. For below json, we find data inside key 'data'
{ "complete": false, "count": 9632240, "data": [ { "ip": "179.124.36.196", "classification": "malicious", "first_seen": "2020-01-13", "last_seen": "2020-12-14", "tags": [ "SSH Scanner", "SSH Worm" ], "cve": [] }, { "ip": "189.86.227.150", "classification": "malicious", "first_seen": "2019-01-17", "last_seen": "2020-12-14", "tags": [ "Eternalblue", "SMB Scanner" ], "cve": [ "CVE-2017-0144" ] } ], "message": "ok" }

Copy link

Choose a reason for hiding this comment

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

Can you please add that example to the docs?

"json_data_key": "data.ipdata"

With above configuration, list of dict will be created from list present in json["data"]["ipdata"]. Each dict will then create atleast an event.
* `"splitlines"`: Boolean, spit multiline data into list, optional. Default: `"false"`. Either `"json_data_format"` or `"splitlines"` can be used.`
Copy link

Choose a reason for hiding this comment

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

Please expand the explanation, examples are also helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again in above json, if we have config json_data_key: data and json_data_format : True, it will create two event with list of data present in json["data"] with proper harmonized field as per given in translate_field parameter.

Copy link

Choose a reason for hiding this comment

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

Why are json_data_format and splitlines mutually exclusive?

Btw, I think there's no test that covers actual line splitting (the tests with splitlines=true only have one line)

@ghost
Copy link

ghost commented Dec 16, 2020

Hi, thanks a lot for your contribution! That looks like a very useful parser. Could you make your commit messages a bit more verbose? It would be great if the information you added in the pull request would be part of the commit message, i.e.

Add a new JSONCustom parser Bot

JSON Custom Parser allows can translate json key into harmonized key field 
and can create events from list of dict within key of JSON

and for the documentation commit (if you want to keep that separate - you could also simply squash to one commit!)

DOC: add documentation for the JSON Custom Parser

The JSON Custom Parser converts from a custom JSON-String into an Event.
This adds an explanation and examples to the Bot documentation.

Also there are a lot of unnecessary changes in the bots.rst file, it seems your editor somehow tries to change spaces in the whole file? See 35ff026 - it would be great if that could be fixed.

JSON Custom Parser allows can translate json key into harmonized key field
and can create events from list of dict within key of JSON
@kbrajneesh
Copy link
Contributor Author

Hi, all requested changes have been made in previous commit.

with open(os.path.join(os.path.dirname(__file__), 'multiple_msg.json'), 'rb') as fh:
RAW1 = base64.b64encode(fh.read()).decode()

MULTILINE_REPORT = {"feed.name": "RSTThreats Domain Feed",
Copy link

Choose a reason for hiding this comment

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

That bot is actually on the whishlist, so if you can contribute an entry to feeds.yaml that would be nice :)

@ghost ghost added feature request Indicates new feature requests component: bots needs: feedback labels Aug 16, 2021
@ghost ghost removed their request for review September 7, 2021 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant