31
31
from contentctl .objects .notable_event import NotableEvent
32
32
33
33
34
+ # TODO (cmcginley): disable logging
34
35
# Suppress logging by default; enable for local testing
35
- ENABLE_LOGGING = False
36
+ ENABLE_LOGGING = True
36
37
LOG_LEVEL = logging .DEBUG
37
38
LOG_PATH = "correlation_search.log"
38
39
@@ -652,15 +653,8 @@ def validate_risk_events(self) -> None:
652
653
f"Unexpected error: Detection '{ self .detection .name } ' has no RBA objects associated"
653
654
" with it; cannot validate."
654
655
)
655
- risk_object_counts : dict [str , int ] = {str (x ): 0 for x in self .detection .rba .risk_objects }
656
656
657
- # NOTE: we intentionally want this to be an error state and not a failure state, as
658
- # ultimately this validation should be handled during the build process
659
- if len (self .detection .rba .risk_objects ) != len (risk_object_counts ):
660
- raise ClientError (
661
- f"At least two risk objects in '{ self .detection .name } ' have the same name; "
662
- "each risk object for a detection should be unique."
663
- )
657
+ risk_object_counts : dict [int , int ] = {id (x ): 0 for x in self .detection .rba .risk_objects }
664
658
665
659
# Get the risk events; note that we use the cached risk events, expecting they were
666
660
# saved by a prior call to risk_event_exists
@@ -681,20 +675,20 @@ def validate_risk_events(self) -> None:
681
675
self .logger .debug (
682
676
f"Matched risk event (object={ event .risk_object } , type={ event .risk_object_type } ) "
683
677
f"to detection's risk object (name={ matched_risk_object .field } , "
684
- f"type={ matched_risk_object .type .value } using the source field "
678
+ f"type={ matched_risk_object .type .value } ) using the source field "
685
679
f"'{ event .source_field_name } '"
686
680
)
687
- risk_object_counts [str (matched_risk_object )] += 1
681
+ risk_object_counts [id (matched_risk_object )] += 1
688
682
689
683
# Report any risk objects which did not have at least one match to a risk event
690
684
for risk_object in self .detection .rba .risk_objects :
691
685
self .logger .debug (
692
686
f"Matched risk object (name={ risk_object .field } , type={ risk_object .type .value } "
693
- f"to { risk_object_counts [str (risk_object )]} risk events."
687
+ f"to { risk_object_counts [id (risk_object )]} risk events."
694
688
)
695
- if risk_object_counts [str (risk_object )] == 0 :
689
+ if risk_object_counts [id (risk_object )] == 0 :
696
690
raise ValidationFailed (
697
- f"Risk object (name={ risk_object .field } , type={ risk_object .type .value } "
691
+ f"Risk object (name={ risk_object .field } , type={ risk_object .type .value } ) "
698
692
"was not matched to any risk events."
699
693
)
700
694
@@ -703,26 +697,26 @@ def validate_risk_events(self) -> None:
703
697
# relevant risk object, and the total count should match the total number of events
704
698
# individual_count: int | None = None
705
699
# total_count = 0
706
- # for risk_object_str in risk_object_counts:
700
+ # for risk_object_id in risk_object_counts:
707
701
# self.logger.debug(
708
- # f"Risk object <{risk_object_str }> match count: {risk_object_counts[risk_object_str ]}"
702
+ # f"Risk object <{risk_object_id }> match count: {risk_object_counts[risk_object_id ]}"
709
703
# )
710
704
711
705
# # Grab the first value encountered if not set yet
712
706
# if individual_count is None:
713
- # individual_count = risk_object_counts[risk_object_str ]
707
+ # individual_count = risk_object_counts[risk_object_id ]
714
708
# else:
715
709
# # Confirm that the count for the current risk object matches the count of the
716
710
# # others
717
- # if risk_object_counts[risk_object_str ] != individual_count:
711
+ # if risk_object_counts[risk_object_id ] != individual_count:
718
712
# raise ValidationFailed(
719
- # f"Count of risk events matching detection's risk object <\"{risk_object_str }\"> "
720
- # f"({risk_object_counts[risk_object_str ]}) does not match the count of those "
713
+ # f"Count of risk events matching detection's risk object <\"{risk_object_id }\"> "
714
+ # f"({risk_object_counts[risk_object_id ]}) does not match the count of those "
721
715
# f"matching other risk objects ({individual_count})."
722
716
# )
723
717
724
718
# # Aggregate total count of events matched to risk objects
725
- # total_count += risk_object_counts[risk_object_str ]
719
+ # total_count += risk_object_counts[risk_object_id ]
726
720
727
721
# # Raise if the the number of events doesn't match the number of those matched to risk
728
722
# # objects
0 commit comments