Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DET-422: Add support for CSE Rule custom window sizes. #623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.28.4 (Unreleased)

ENHANCEMENTS:
* Added support for custom window sizes for the CSE Rules (Aggregation, Chain, Threshold). (GH-623)

## 2.28.3 (March 5, 2024)

Expand Down
80 changes: 45 additions & 35 deletions sumologic/resource_sumologic_cse_aggregation_rule.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package sumologic

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"log"
)

func resourceSumologicCSEAggregationRule() *schema.Resource {
Expand Down Expand Up @@ -99,6 +101,10 @@ func resourceSumologicCSEAggregationRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"window_size_millis": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -136,7 +142,9 @@ func resourceSumologicCSEAggregationRuleRead(d *schema.ResourceData, meta interf
d.Set("tags", CSEAggregationRuleGet.Tags)
d.Set("trigger_expression", CSEAggregationRuleGet.TriggerExpression)
d.Set("window_size", CSEAggregationRuleGet.WindowSizeName)

if strings.EqualFold(CSEAggregationRuleGet.WindowSizeName, "CUSTOM") {
d.Set("window_size_millis", CSEAggregationRuleGet.WindowSize)
}
return nil
}

Expand All @@ -152,22 +160,23 @@ func resourceSumologicCSEAggregationRuleCreate(d *schema.ResourceData, meta inte

if d.Id() == "" {
id, err := c.CreateCSEAggregationRule(CSEAggregationRule{
AggregationFunctions: resourceToAggregationFunctionsArray(d.Get("aggregation_functions").([]interface{})),
DescriptionExpression: d.Get("description_expression").(string),
Enabled: d.Get("enabled").(bool),
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
GroupByEntity: d.Get("group_by_entity").(bool),
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
IsPrototype: d.Get("is_prototype").(bool),
MatchExpression: d.Get("match_expression").(string),
Name: d.Get("name").(string),
NameExpression: d.Get("name_expression").(string),
SeverityMapping: resourceToSeverityMapping(d.Get("severity_mapping").([]interface{})[0]),
Stream: "record",
SummaryExpression: d.Get("summary_expression").(string),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
TriggerExpression: d.Get("trigger_expression").(string),
WindowSize: windowSizeField(d.Get("window_size").(string)),
AggregationFunctions: resourceToAggregationFunctionsArray(d.Get("aggregation_functions").([]interface{})),
DescriptionExpression: d.Get("description_expression").(string),
Enabled: d.Get("enabled").(bool),
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
GroupByEntity: d.Get("group_by_entity").(bool),
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
IsPrototype: d.Get("is_prototype").(bool),
MatchExpression: d.Get("match_expression").(string),
Name: d.Get("name").(string),
NameExpression: d.Get("name_expression").(string),
SeverityMapping: resourceToSeverityMapping(d.Get("severity_mapping").([]interface{})[0]),
Stream: "record",
SummaryExpression: d.Get("summary_expression").(string),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
TriggerExpression: d.Get("trigger_expression").(string),
WindowSize: windowSizeField(d.Get("window_size").(string)),
WindowSizeMilliseconds: d.Get("window_size_millis").(string),
})

if err != nil {
Expand Down Expand Up @@ -229,22 +238,23 @@ func resourceToCSEAggregationRule(d *schema.ResourceData) (CSEAggregationRule, e
}

return CSEAggregationRule{
ID: id,
AggregationFunctions: resourceToAggregationFunctionsArray(d.Get("aggregation_functions").([]interface{})),
DescriptionExpression: d.Get("description_expression").(string),
Enabled: d.Get("enabled").(bool),
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
GroupByEntity: d.Get("group_by_entity").(bool),
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
IsPrototype: d.Get("is_prototype").(bool),
MatchExpression: d.Get("match_expression").(string),
Name: d.Get("name").(string),
NameExpression: d.Get("name_expression").(string),
SeverityMapping: resourceToSeverityMapping(d.Get("severity_mapping").([]interface{})[0]),
Stream: "record",
SummaryExpression: d.Get("summary_expression").(string),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
TriggerExpression: d.Get("trigger_expression").(string),
WindowSize: windowSizeField(d.Get("window_size").(string)),
ID: id,
AggregationFunctions: resourceToAggregationFunctionsArray(d.Get("aggregation_functions").([]interface{})),
DescriptionExpression: d.Get("description_expression").(string),
Enabled: d.Get("enabled").(bool),
EntitySelectors: resourceToEntitySelectorArray(d.Get("entity_selectors").([]interface{})),
GroupByEntity: d.Get("group_by_entity").(bool),
GroupByFields: resourceToStringArray(d.Get("group_by_fields").([]interface{})),
IsPrototype: d.Get("is_prototype").(bool),
MatchExpression: d.Get("match_expression").(string),
Name: d.Get("name").(string),
NameExpression: d.Get("name_expression").(string),
SeverityMapping: resourceToSeverityMapping(d.Get("severity_mapping").([]interface{})[0]),
Stream: "record",
SummaryExpression: d.Get("summary_expression").(string),
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
TriggerExpression: d.Get("trigger_expression").(string),
WindowSize: windowSizeField(d.Get("window_size").(string)),
WindowSizeMilliseconds: d.Get("window_size_millis").(string),
}, nil
}
Loading
Loading