Skip to content

Commit 0cc5443

Browse files
Add initial non ecs support
1 parent 5a2e81c commit 0cc5443

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

detection_rules/rule_validators.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,22 @@ def validate_integration(
642642
pass
643643

644644

645+
def convert_to_nested_schema(flat_schemas: dict[str, str]) -> dict[str, Any]:
646+
"""Convert a flat schema to a nested schema with 'properties' for each sub-key."""
647+
nested_schema = {}
648+
649+
for key, value in flat_schemas.items():
650+
parts = key.split(".")
651+
current_level = nested_schema
652+
653+
for part in parts[:-1]:
654+
current_level = current_level.setdefault(part, {}).setdefault("properties", {})
655+
656+
current_level[parts[-1]] = {"type": value}
657+
658+
return nested_schema
659+
660+
645661
def extract_error_field(source: str, exc: eql.EqlParseError | kql.KqlParseError) -> str | None:
646662
"""Extract the field name from an EQL or KQL parse error."""
647663
lines = source.splitlines()
@@ -761,7 +777,16 @@ def log(val: str) -> None:
761777
combine_dicts(combined_mappings, existing_mappings)
762778
combine_dicts(combined_mappings, integration_mappings)
763779
# NOTE non-ecs schema needs to have formatting updates prior to merge
764-
# combine_dicts(combined_mappings, ecs.get_non_ecs_schema())
780+
# NOTE non-ecs schema uses Kibana reserved word "properties" as a field name
781+
# e.g. "azure.auditlogs.properties.target_resources.0.display_name": "keyword",
782+
non_ecs_mapping = {}
783+
non_ecs = ecs.get_non_ecs_schema()
784+
for index in indices:
785+
non_ecs_mapping.update(non_ecs.get(index, {}))
786+
non_ecs_mapping = ecs.flatten(non_ecs_mapping)
787+
non_ecs_mapping = convert_to_nested_schema(non_ecs_mapping)
788+
if non_ecs_mapping:
789+
combine_dicts(combined_mappings, non_ecs_mapping)
765790

766791
if not combined_mappings:
767792
log("ERROR: no mappings found for the rule")

0 commit comments

Comments
 (0)