Skip to content

Commit

Permalink
Merge pull request #570 from opencybersecurityalliance/k2-kestrel-too…
Browse files Browse the repository at this point in the history
…l-suffix-fix

fix kestrel-tool suffix field handling
  • Loading branch information
subbyte authored Jul 30, 2024
2 parents a740171 + 546dd73 commit 7f3dded
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ http_request:

# https://schema.ocsf.io/1.1.0/objects/query_info
query_info:
uid: ReportId_long
attr_list: AdditionalFields_string.AttributeList
search_filter: AdditionalFields_string.SearchFilter
uid: ReportId
attr_list: AdditionalFields.AttributeList
search_filter: AdditionalFields.SearchFilter


# https://schema.ocsf.io/1.1.0/objects/managed_entity
entity:
uid: ReportId_long
uid: ReportId
data: ActivityObjects


Expand Down
4 changes: 4 additions & 0 deletions packages/kestrel_core/src/kestrel/mapping/fields/ecs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# "*" is for entity/event projection mapping besides a single field
# if the submap is referred, there will be multiple reversed mappings, the first will be used


time: "@timestamp"


# endpoint: see https://schema.ocsf.io/1.1.0/objects/endpoint
device: &endpoint
"*": host.*
Expand Down
4 changes: 4 additions & 0 deletions packages/kestrel_core/src/kestrel/mapping/fields/stix.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# "*" is for entity/event projection mapping besides a single field


time: timestamp


# https://schema.ocsf.io/1.1.0/objects/file
file:
"*": file.*
Expand Down
12 changes: 12 additions & 0 deletions packages/kestrel_tool/src/kestrel_tool/mkdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def _normalize_event(event: dict) -> dict:
except json.JSONDecodeError:
pass # maybe it's NOT JSON

for k in list(event):
if k.endswith("_string"):
base_key = k[:-7]
if base_key not in event or not event[base_key]:
event[base_key] = event[k]
del event[k]
if k.endswith("_long"):
base_key = k[:-5]
if base_key not in event or not event[base_key]:
event[base_key] = int(event[k])
del event[k]

return event


Expand Down

0 comments on commit 7f3dded

Please sign in to comment.