Prime Detect OSS Parser
A DSL pipeline for parsing and transforming events using a flexible query-based syntax. It’s part of Prime Detect OSS by SOC Prime — check out the README for more details and setup instructions.
Overview
Prime Detect Parser provides a domain-specific language (DSL) for parsing and transforming event data. It supports query-based parsers and configured parsers.
Quick Start
from schema_parser.manager import ParserManager
manager = ParserManager()
# Parse an event using a query string
event = {"raw": '{"name": "John", "age": 30}'}
query = 'parse_json(field="raw", in_place=True)'
parser_config = manager.query_parser(query)
result = manager.configured_parser(event, parser_config)
print(result)
# Output: {'raw': {'name': 'John', 'age': 30}}
Usage
Query-Based Parsing
The most common way to use Schema Parser is through query strings:
from schema_parser.manager import ParserManager
manager = ParserManager()
event = {"raw": '{"name": "John", "age": 30}'}
query = """
parse_json(field="raw", in_place=True)
| rename(from="raw", to="user")
| set(field="event.type", value="user_data")
"""
parser_config = manager.query_parser(query)
result = manager.configured_parser(event, parser_config)
Configured Parser
You can also use a pre-configured parser dictionary. This is the same normalized
shape returned by manager.query_parser(...):
parser_config = {
"steps": [
{
"function_name": "parse_json",
"args": {"field": "raw", "in_place": True},
},
{
"function_name": "rename",
"args": {"from_field": "raw", "to_field": "data"},
},
]
}
result = manager.configured_parser(event, parser_config)
Available Functions
All functions support nested field paths using dot notation (e.g., "user.profile.name"). If a direct key exists with the same name as a nested path (e.g., {"a.b": "value"}), it will be replaced with the nested structure when using set or delete operations.
parse_json
Parses a JSON string from a field.
Parameters:
field (required): Name of the field containing the JSON string. Supports nested paths (e.g., "event.raw").
in_place (optional, default: False): If True, replaces the field value with parsed JSON. If False, returns only the parsed JSON value (must be a dict).
Examples:
# Parse JSON and return the parsed value
parse_json(field="raw")
# Parse JSON in place (replaces field with parsed value)
parse_json(field="raw", in_place=True)
# Parse nested field
parse_json(field="event.raw", in_place=True)
# Case-insensitive boolean values are supported
parse_json(field="raw", in_place=true)
Behavior:
- When
in_place=False: Returns only the parsed JSON (must be a dict)
- When
in_place=True: Modifies the input data dictionary and returns it
- Silently ignores if field is missing,
None, empty string "", empty array [], or empty dict {}
- Raises
ParseJsonFunctionError if JSON parsing fails or parsed value is not a dict when in_place=False
parse_kv
Parses delimiter-separated key=value pairs from a field. Tokens that are not valid KV pairs are skipped.
Parameters:
field (required): Name of the field containing the KV string. Supports nested paths (e.g., "event.original").
in_place (optional, default: False): If True, replaces the field value with the parsed dictionary. If False, returns only the parsed KV dictionary.
delimiter (optional, default: |): Separator between pairs. "\t", "\n", and "\r" are interpreted as tab/newline/carriage return.
value_delimiter (optional, default: =): Separator between key and value. "\t", "\n", and "\r" are interpreted as tab/newline/carriage return.
Examples:
# Parse pipe-separated KV and return the parsed dictionary
parse_kv(field="raw")
# Parse in place (replaces field with parsed dictionary)
parse_kv(field="raw", in_place=True)
# Custom field delimiter (tab-separated pairs)
parse_kv(field="raw", delimiter="\\t")
# Custom value delimiter (colon-separated key/value)
parse_kv(field="raw", value_delimiter=":")
Behavior:
- Splits on the field delimiter when it is followed by
key<value_delimiter>
- Uses the first value delimiter in each pair to separate key and value, so values may contain that character. Spaces around the value delimiter are allowed (
src = 1)
- Skips tokens that do not look like
key<value_delimiter>value
- Empty values such as
note= are kept as empty strings
- A trailing field delimiter after the last pair is dropped (
user=alice| → alice)
key<value_delimiter> inside a value (for example a= in a URL) is not treated as a new field
- Silently ignores if field is missing,
None, empty string "", empty array [], or empty dict {}
- Raises
ParseKvFunctionError if the field is not a string
Output Example:
# Input: {"raw": "header|1.0|src=192.0.2.10|user=alice"}
# Query: parse_kv(field="raw")
# Output: {"src": "192.0.2.10", "user": "alice"}
parse_leef
Parses a LEEF (Log Event Extended Format) event. The header is always |-separated. Extension key=value pairs are parsed the same way as parse_kv.
Parameters:
field (required): Name of the field containing the LEEF string. Supports nested paths (e.g., "event.original").
in_place (optional, default: False): If True, replaces the field value with the parsed dictionary. If False, returns only the parsed LEEF dictionary.
delimiter (optional, default: tab): Separator between extension pairs. If the event is LEEF 2.0 and the header declares a delimiter (^, x09, …), that value is used instead. Pipe-separated vendors (McAfee) must pass delimiter="|".
Examples:
# IBM-style events (tab-separated extensions)
parse_leef(field="raw")
# McAfee Web Gateway and similar (pipe-separated extensions)
parse_leef(field="raw", delimiter="|")
# Nested field, in place
parse_leef(field="event.original", delimiter="|", in_place=True)
Behavior:
- Finds
LEEF:, so a syslog prefix before the payload is ignored
- Header fields:
leef_version, vendor, product, product_version, event_id
- Extension delimiter: LEEF 2.0 header field, then
delimiter, then tab. It is not guessed from the payload
- Extension pairs follow
parse_kv (empty values kept, = inside values allowed)
- Silently ignores if field is missing,
None, empty string "", empty array [], or empty dict {}
- Raises
ParseLeefFunctionError if the field is not a string or is not a LEEF event
Output Example:
# Input: {"raw": "LEEF:1.0|McAfee|Web Gateway|12.2.23|0|src=10.1.25.86|usrName=USER1"}
# Query: parse_leef(field="raw", delimiter="|")
# Output: {
# "leef_version": "1.0",
# "vendor": "McAfee",
# "product": "Web Gateway",
# "product_version": "12.2.23",
# "event_id": "0",
# "src": "10.1.25.86",
# "usrName": "USER1",
# }
parse_xml
Parses an XML string into a nested dictionary.
Parameters:
field (required): Name of the field containing the XML string. Supports nested paths (e.g., "event.raw").
in_place (optional, default: False): If True, replaces the field value with the parsed dictionary. If False, returns only the parsed XML dictionary.
Examples:
parse_xml(field="raw")
parse_xml(field="raw", in_place=True)
parse_xml(field="event.raw", in_place=True)
# Windows Event XML: turn EventData fields into top-level keys
parse_xml(field="raw") | list_to_dict(field="Event.EventData.Data", key="@Name", value="#text") | extract(field="Event.EventData.Data")
Windows Event XML stores event fields as repeated <Data Name="..."> elements. parse_xml leaves them as a list of @Name / #text objects; list_to_dict converts that list to a flat map, and extract promotes those keys to the top level.
Behavior:
- Root element name is the top-level key
- Attributes become
@Name-style keys; element text is #text when the element also has attributes
- Repeated tags become lists
- Namespaces are stripped
- Missing or empty field is ignored
- Raises
ParseXmlFunctionError if the value is not a string, the XML is invalid, or it contains a DTD
Output Example:
# Input: {"raw": '<Event><EventData><Data Name="User">alice</Data><Data Name="LogonType">3</Data></EventData></Event>'}
# Query: parse_xml(field="raw")
# Output: {
# "Event": {
# "EventData": {
# "Data": [
# {"@Name": "User", "#text": "alice"},
# {"@Name": "LogonType", "#text": "3"},
# ]
# }
# }
# }
regex
Extracts data from a field using a regular expression pattern.
Parameters:
pattern (required): Regular expression pattern with named groups
field (required): Name of the field to apply the regex to. Supports nested paths (e.g., "event.log").
in_place (optional, default: False): If True, replaces the field value with the matched groupdict and returns the modified data dictionary. If False, returns only the matched groupdict.
Examples:
# Pattern first, field second
regex(pattern="^(?P<ip>\\S+) .*", field="log")
# Field first, pattern second (both orders supported)
regex(field="log", pattern="^(?P<ip>\\S+) .*")
# Apply regex to nested field
regex(field="event.log", pattern="^(?P<ip>\\S+) .*")
# Regex in place (replaces field with matched groups)
regex(field="log", pattern="^(?P<ip>\\S+) .*", in_place=True)
# Case-insensitive boolean values are supported
regex(field="log", pattern="^(?P<ip>\\S+) .*", in_place=true)
in_place examples:
Without in_place (default — returns only the matched groups):
# Input: {"log": "192.168.1.1 - GET /api"}
# Query: regex(field="log", pattern="^(?P<ip>\\S+) .*")
# Output: {"ip": "192.168.1.1"}
With in_place=True (replaces the field value with matched groups):
# Input: {"log": "192.168.1.1 - GET /api", "other": "value"}
# Query: regex(field="log", pattern="^(?P<ip>\\S+) .*", in_place=True)
# Output: {"log": {"ip": "192.168.1.1"}, "other": "value"}
With in_place=True on a nested field:
# Input: {"event": {"raw": "192.168.1.1 - GET /api"}, "type": "access"}
# Query: regex(field="event.raw", pattern="^(?P<ip>\\S+) .*", in_place=True)
# Output: {"event": {"raw": {"ip": "192.168.1.1"}}, "type": "access"}
Behavior:
- When
in_place=False: Returns only the matched groupdict
- When
in_place=True: Replaces the field value with the matched groupdict and returns the modified data dictionary
- Raises
RegexPatternMatchError if the field is missing or the pattern doesn't match
- Raises
RegexFieldTypeError if the field value is not a string
rename
Renames a field in the data dictionary.
Parameters:
from (required): Current field name. Supports nested paths (e.g., "user.profile.name").
to (required): New field name. Supports nested paths (e.g., "user.name"). Creates intermediate dictionaries if needed.
Examples:
# Simple rename
rename(from="old_field", to="new_field")
# Rename from nested path
rename(from="event.user", to="user.name")
# Rename from nested to nested
rename(from="user.profile.name", to="user.name")
extract
Extracts a nested dictionary from a field and merges it with the parent dictionary.
Parameters:
field (required): Name of the field containing the nested dictionary to extract. Supports nested paths (e.g., "winlog.event_data").
Examples:
# Extract a nested user object
extract(field="user")
# Example transformation:
# Input: {'user': {'user_name': 'test', 'user_id': '1'}, 'some_field': 'some_value'}
# Output: {'user_name': 'test', 'user_id': '1', 'some_field': 'some_value'}
# Extract from nested path
extract(field="winlog.event_data")
# Empty dict is also extracted (field is removed):
# Input: {'empty': {}, 'other': 'value'}
# Output: {'other': 'value'}
Behavior:
- Extracts the nested dictionary from the specified field (supports nested paths)
- Merges all fields from the nested dictionary into the parent
- Removes the original nested field
- Silently ignores if field is missing,
None, empty string "", or empty array []
- Empty dict
{} is valid and will be extracted (field removed, nothing merged)
- Raises an error only if field exists and is not a dictionary
list_to_dict
Turns a list of objects into a dictionary using two fields as key and value. Always returns the full event, with that field replaced.
# Before
{"Data": [{"@Name": "User", "#text": "alice"}, {"@Name": "LogonType", "#text": "3"}]}
# After list_to_dict(field="Data", key="@Name", value="#text")
{"Data": {"User": "alice", "LogonType": "3"}}
Parameters:
field (required): Path to the list (or a single object). Supports nested paths.