4
4
if TYPE_CHECKING :
5
5
from contentctl .objects .detection import Detection
6
6
from contentctl .objects .enums import AnalyticsType
7
- SEARCH_PLACEHOLDER = "%original_detection_search%"
7
+ DRILLDOWN_SEARCH_PLACEHOLDER = "%original_detection_search%"
8
8
EARLIEST_OFFSET = "$info_min_time$"
9
9
LATEST_OFFSET = "$info_max_time$"
10
10
RISK_SEARCH = "index = risk starthoursago = 168 endhoursago = 0 | stats count values(search_name) values(risk_message) values(analyticstories) values(annotations._all) values(annotations.mitre_attack.mitre_tactic) "
@@ -29,7 +29,7 @@ def constructDrilldownsFromDetection(cls, detection: Detection) -> list[Drilldow
29
29
if len (victim_observables ) == 0 or detection .type == AnalyticsType .Hunting :
30
30
# No victims, so no drilldowns
31
31
return []
32
- print ("Adding default drilldowns. REMOVE THIS BEFORE MERGING " )
32
+ print (f "Adding default drilldowns for [ { detection . name } ] " )
33
33
variableNamesString = ' and ' .join ([f"${ o .name } $" for o in victim_observables ])
34
34
nameField = f"View the detection results for { variableNamesString } "
35
35
appendedSearch = " | search " + ' ' .join ([f"{ o .name } = ${ o .name } $" for o in victim_observables ])
@@ -40,18 +40,20 @@ def constructDrilldownsFromDetection(cls, detection: Detection) -> list[Drilldow
40
40
nameField = f"View risk events for the last 7 days for { variableNamesString } "
41
41
fieldNamesListString = ', ' .join ([o .name for o in victim_observables ])
42
42
search_field = f"{ RISK_SEARCH } by { fieldNamesListString } { appendedSearch } "
43
- #risk_events_last_7_days = cls(name=nameField, earliest_offset=EARLIEST_OFFSET, latest_offset=LATEST_OFFSET, search=search_field)
44
43
risk_events_last_7_days = cls (name = nameField , earliest_offset = None , latest_offset = None , search = search_field )
45
44
46
45
return [detection_results ,risk_events_last_7_days ]
47
46
48
47
49
48
def perform_search_substitutions (self , detection :Detection )-> None :
50
- if (self .search .count ("%" ) % 2 ) or (self .search .count ("$" ) % 2 ):
51
- print ("\n \n Warning - a non-even number of '%' or '$' characters were found in the\n "
52
- f"drilldown search '{ self .search } ' for Detection { detection .file_path } .\n "
53
- "If this was intentional, then please ignore this warning.\n " )
54
- self .search = self .search .replace (SEARCH_PLACEHOLDER , detection .search )
49
+ """Replaces the field DRILLDOWN_SEARCH_PLACEHOLDER (%original_detection_search%)
50
+ with the search contained in the detection. We do this so that the YML does not
51
+ need the search copy/pasted from the search field into the drilldown object.
52
+
53
+ Args:
54
+ detection (Detection): Detection to be used to update the search field of the drilldown
55
+ """
56
+ self .search = self .search .replace (DRILLDOWN_SEARCH_PLACEHOLDER , detection .search )
55
57
56
58
57
59
@model_serializer
0 commit comments