44 */
55package org .opensearch .securityanalytics .config .monitors ;
66
7+ import java .util .ArrayList ;
8+ import java .util .List ;
79import org .opensearch .securityanalytics .model .Detector ;
810
911import java .util .Arrays ;
1315
1416
1517public class DetectorMonitorConfig {
18+
1619 public static final String OPENSEARCH_DEFAULT_RULE_INDEX = ".opensearch-sap-detectors-queries-default" ;
1720 public static final String OPENSEARCH_DEFAULT_ALERT_INDEX = ".opensearch-sap-alerts-default" ;
1821 public static final String OPENSEARCH_DEFAULT_ALERT_HISTORY_INDEX = ".opensearch-sap-alerts-history-default" ;
1922 public static final String OPENSEARCH_DEFAULT_ALERT_HISTORY_INDEX_PATTERN = "<.opensearch-sap-alerts-history-default-{now/d}-1>" ;
2023 public static final String OPENSEARCH_DEFAULT_FINDINGS_INDEX = ".opensearch-sap-findings-default" ;
2124 public static final String OPENSEARCH_DEFAULT_FINDINGS_INDEX_PATTERN = "<.opensearch-sap-findings-default-{now/d}-1>" ;
2225
23- private static Map <String , MonitorConfig > ruleIndexByDetectorTypeMap ;
26+ private static Map <String , MonitorConfig > detectorTypeToIndicesMapping ;
2427
2528 static {
26- ruleIndexByDetectorTypeMap = new HashMap <>();
29+ detectorTypeToIndicesMapping = new HashMap <>();
2730 Arrays .stream (Detector .DetectorType .values ()).forEach (
2831 detectorType -> {
2932 String ruleIndex = String .format (
30- Locale .getDefault (), ".opensearch-sap-detectors-queries-%s " , detectorType .getDetectorType ());
33+ Locale .getDefault (), ".opensearch-sap-%s- detectors-queries" , detectorType .getDetectorType ());
3134 String alertsIndex = String .format (
32- Locale .getDefault (), ".opensearch-sap-alerts-%s " , detectorType .getDetectorType ());
35+ Locale .getDefault (), ".opensearch-sap-%s-alerts " , detectorType .getDetectorType ());
3336 String alertsHistoryIndex = String .format (
34- Locale .getDefault (), ".opensearch-sap-alerts-history-%s " , detectorType .getDetectorType ());
37+ Locale .getDefault (), ".opensearch-sap-%s- alerts-history" , detectorType .getDetectorType ());
3538 String alertsHistoryIndexPattern = String .format (
36- Locale .getDefault (), "<.opensearch-sap-alerts-history-%s-{now/d}-1>" , detectorType .getDetectorType ());
39+ Locale .getDefault (), "<.opensearch-sap-%s-alerts-history-{now/d}-1>" , detectorType .getDetectorType ());
40+ String allAlertsIndicesPattern = String .format (
41+ Locale .getDefault (), ".opensearch-sap-%s-alerts*" , detectorType .getDetectorType ());
3742 String findingsIndex = String .format (
38- Locale .getDefault (), ".opensearch-sap-findings-%s " , detectorType .getDetectorType ());
43+ Locale .getDefault (), ".opensearch-sap-%s-findings " , detectorType .getDetectorType ());
3944 String findingsIndexPattern = String .format (
40- Locale .getDefault (), "<.opensearch-sap-findings-%s -{now/d}-1>" , detectorType .getDetectorType ());
45+ Locale .getDefault (), "<.opensearch-sap-%s-findings -{now/d}-1>" , detectorType .getDetectorType ());
4146
42- MonitorConfig monitor = new MonitorConfig (alertsIndex , alertsHistoryIndex , alertsHistoryIndexPattern , findingsIndex , findingsIndexPattern , ruleIndex );
43- ruleIndexByDetectorTypeMap .put (detectorType .getDetectorType (), monitor );
47+ MonitorConfig monitor = new MonitorConfig (alertsIndex , alertsHistoryIndex , alertsHistoryIndexPattern , allAlertsIndicesPattern , findingsIndex , findingsIndexPattern , ruleIndex );
48+ detectorTypeToIndicesMapping .put (detectorType .getDetectorType (), monitor );
4449 });
4550 }
4651
4752 public static String getRuleIndex (String detectorType ) {
48- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
49- ruleIndexByDetectorTypeMap .get (detectorType ).getRuleIndex () :
53+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
54+ detectorTypeToIndicesMapping .get (detectorType ).getRuleIndex () :
5055 OPENSEARCH_DEFAULT_RULE_INDEX ;
5156 }
5257
5358 public static String getAlertsIndex (String detectorType ) {
54- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
55- ruleIndexByDetectorTypeMap .get (detectorType ).getAlertsIndex () :
59+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
60+ detectorTypeToIndicesMapping .get (detectorType ).getAlertsIndex () :
5661 OPENSEARCH_DEFAULT_ALERT_INDEX ;
5762 }
5863
5964 public static String getAlertsHistoryIndex (String detectorType ) {
60- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
61- ruleIndexByDetectorTypeMap .get (detectorType ).getAlertsHistoryIndex () :
65+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
66+ detectorTypeToIndicesMapping .get (detectorType ).getAlertsHistoryIndex () :
6267 OPENSEARCH_DEFAULT_ALERT_HISTORY_INDEX ;
6368 }
6469
6570 public static String getAlertsHistoryIndexPattern (String detectorType ) {
66- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
67- ruleIndexByDetectorTypeMap .get (detectorType ).getAlertsHistoryIndexPattern () :
71+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
72+ detectorTypeToIndicesMapping .get (detectorType ).getAlertsHistoryIndexPattern () :
6873 OPENSEARCH_DEFAULT_ALERT_HISTORY_INDEX_PATTERN ;
6974 }
7075
76+ public static String getAllAlertsIndicesPattern (String detectorType ) {
77+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
78+ detectorTypeToIndicesMapping .get (detectorType ).getAllAlertsIndicesPattern () :
79+ "*" ;
80+ }
81+
7182 public static String getFindingsIndex (String detectorType ) {
72- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
73- ruleIndexByDetectorTypeMap .get (detectorType ).getFindingsIndex () :
83+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
84+ detectorTypeToIndicesMapping .get (detectorType ).getFindingsIndex () :
7485 OPENSEARCH_DEFAULT_FINDINGS_INDEX ;
7586 }
7687
7788 public static String getFindingsIndexPattern (String detectorType ) {
78- return ruleIndexByDetectorTypeMap .containsKey (detectorType ) ?
79- ruleIndexByDetectorTypeMap .get (detectorType ).getFindingsIndexPattern () :
80- OPENSEARCH_DEFAULT_FINDINGS_INDEX ;
89+ return detectorTypeToIndicesMapping .containsKey (detectorType ) ?
90+ detectorTypeToIndicesMapping .get (detectorType ).getFindingsIndexPattern () :
91+ OPENSEARCH_DEFAULT_FINDINGS_INDEX_PATTERN ;
8192 }
8293
8394 public static Map <String , Map <String , String >> getRuleIndexMappingsByType (String detectorType ) {
@@ -88,10 +99,11 @@ public static Map<String, Map<String, String>> getRuleIndexMappingsByType(String
8899 return fieldMappingProperties ;
89100 }
90101
91- private static class MonitorConfig {
102+ public static class MonitorConfig {
92103 private final String alertsIndex ;
93104 private final String alertsHistoryIndex ;
94105 private final String alertsHistoryIndexPattern ;
106+ private final String allAlertsIndicesPattern ;
95107 private final String findingIndex ;
96108 private final String findingsIndexPattern ;
97109 private final String ruleIndex ;
@@ -100,13 +112,15 @@ private MonitorConfig(
100112 String alertsIndex ,
101113 String alertsHistoryIndex ,
102114 String alertsHistoryIndexPattern ,
115+ String allAlertsIndicesPattern ,
103116 String findingsIndex ,
104117 String findingsIndexPattern ,
105118 String ruleIndex
106119 ) {
107120 this .alertsIndex = alertsIndex ;
108121 this .alertsHistoryIndex = alertsHistoryIndex ;
109122 this .alertsHistoryIndexPattern = alertsHistoryIndexPattern ;
123+ this .allAlertsIndicesPattern = allAlertsIndicesPattern ;
110124 this .findingIndex = findingsIndex ;
111125 this .findingsIndexPattern = findingsIndexPattern ;
112126 this .ruleIndex = ruleIndex ;
@@ -124,6 +138,10 @@ public String getAlertsHistoryIndexPattern() {
124138 return alertsHistoryIndexPattern ;
125139 }
126140
141+ public String getAllAlertsIndicesPattern () {
142+ return allAlertsIndicesPattern ;
143+ }
144+
127145 public String getFindingsIndex () {
128146 return findingIndex ;
129147 }
0 commit comments