Skip to content

Commit

Permalink
[parser] switching to using a list for optional top level keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandeivert committed Jun 8, 2017
1 parent 06b470f commit 8f9b55b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions conf/logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@
"ingress.event.filemod"
]
},
"optional_top_level_keys": {
"filetype": "integer",
"filetype_name": "string"
}
"optional_top_level_keys": [
"filetype",
"filetype_name"
]
}
},
"carbonblack:binaryinfo.host.observed": {
Expand Down
8 changes: 5 additions & 3 deletions stream_alert/rule_processor/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,19 @@ def default_optional_values(key):
elif key == OrderedDict():
return dict()

for key_name, value_type in optional_keys.iteritems():
for key_name in optional_keys:
# Instead of doing a schema.update() here with a default value type,
# we should enforce having any optional keys declared within the schema
# and log an error if that is not the case
if key_name not in schema:
LOGGER.error('Optional key \'%s\' not found in schema', key_name)
LOGGER.error('Optional top level key \'%s\' '
'not found in declared log schema', key_name)
continue
# If the optional key isn't in our parsed json payload
for record in json_records:
if key_name not in record:
# Set default value
record[key_name] = default_optional_values(value_type)
record[key_name] = default_optional_values(schema[key_name])

return json_records

Expand Down

0 comments on commit 8f9b55b

Please sign in to comment.