forked from opensearch-project/security-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates bucket level monitors for rules containing aggregations (open…
…search-project#92) Signed-off-by: Stevan Buzejic <stevan.buzejic@htecgroup.com>
- Loading branch information
Showing
15 changed files
with
1,133 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/opensearch/securityanalytics/rules/backend/AggregationBuilders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.rules.backend; | ||
|
||
import java.util.Locale; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.opensearch.search.aggregations.AggregationBuilder; | ||
import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.AvgAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.MaxAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.MedianAbsoluteDeviationAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.MinAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.SumAggregationBuilder; | ||
import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder; | ||
|
||
public final class AggregationBuilders { | ||
|
||
/** | ||
* Finds the builder aggregation based on the forwarded function | ||
* | ||
* @param aggregationFunction Aggregation function | ||
* @param name Name of the aggregation | ||
* @return Aggregation builder | ||
*/ | ||
public static AggregationBuilder getAggregationBuilderByFunction(String aggregationFunction, String name) { | ||
AggregationBuilder aggregationBuilder; | ||
switch (aggregationFunction.toLowerCase(Locale.ROOT)) { | ||
case AvgAggregationBuilder.NAME: | ||
aggregationBuilder = new AvgAggregationBuilder(name).field(name); | ||
break; | ||
case MaxAggregationBuilder.NAME: | ||
aggregationBuilder = new MaxAggregationBuilder(name).field(name); | ||
break; | ||
case MedianAbsoluteDeviationAggregationBuilder.NAME: | ||
aggregationBuilder = new MedianAbsoluteDeviationAggregationBuilder(name).field(name); | ||
break; | ||
case MinAggregationBuilder.NAME: | ||
aggregationBuilder = new MinAggregationBuilder(name).field(name); | ||
break; | ||
case SumAggregationBuilder.NAME: | ||
aggregationBuilder = new SumAggregationBuilder(name).field(name); | ||
break; | ||
case TermsAggregationBuilder.NAME: | ||
aggregationBuilder = new TermsAggregationBuilder(name).field(name); | ||
break; | ||
case "count": | ||
aggregationBuilder = new ValueCountAggregationBuilder(name).field(name); | ||
break; | ||
default: | ||
throw new NotImplementedException(String.format(Locale.getDefault(), "Aggregation %s not supported by the backend", aggregationFunction)); | ||
} | ||
return aggregationBuilder; | ||
} | ||
} |
Oops, something went wrong.