Skip to content

Commit 12ece15

Browse files
author
Josh Williams
committed
Fixes
1 parent 8873ad2 commit 12ece15

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

sumologic/resource_sumologic_cse_match_rule.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,24 @@ func resourceSumologicCSEMatchRuleRead(d *schema.ResourceData, meta interface{})
6565

6666
CSEMatchRuleGet, err := c.GetCSEMatchRule(id)
6767
if err != nil {
68-
log.Printf("[WARN] CSE Insights Status not found when looking by id: %s, err: %v", id, err)
68+
log.Printf("[WARN] CSE Match Rule not found when looking by id: %s, err: %v", id, err)
6969

7070
}
7171

7272
if CSEMatchRuleGet == nil {
73-
log.Printf("[WARN] CSE Insights Status not found, removing from state: %v - %v", id, err)
73+
log.Printf("[WARN] CSE Match Rule not found, removing from state: %v - %v", id, err)
7474
d.SetId("")
7575
return nil
7676
}
7777

7878
d.Set("description_expression", CSEMatchRuleGet.DescriptionExpression)
7979
d.Set("enabled", CSEMatchRuleGet.Enabled)
80-
d.Set("entity_selectors", CSEMatchRuleGet.EntitySelectors)
80+
d.Set("entity_selectors", entitySelectorArrayToResource(CSEMatchRuleGet.EntitySelectors))
8181
d.Set("expression", CSEMatchRuleGet.Expression)
8282
d.Set("is_prototype", CSEMatchRuleGet.IsPrototype)
8383
d.Set("name", CSEMatchRuleGet.Name)
8484
d.Set("name_expression", CSEMatchRuleGet.NameExpression)
85-
d.Set("severity_mapping", CSEMatchRuleGet.SeverityMapping)
85+
d.Set("severity_mapping", severityMappingToResource(CSEMatchRuleGet.SeverityMapping))
8686
d.Set("summary_expression", CSEMatchRuleGet.SummaryExpression)
8787
d.Set("tags", CSEMatchRuleGet.Tags)
8888

@@ -117,7 +117,6 @@ func resourceSumologicCSEMatchRuleCreate(d *schema.ResourceData, meta interface{
117117
if err != nil {
118118
return err
119119
}
120-
log.Printf("[INFO] got id: %s", id)
121120
d.SetId(id)
122121
}
123122

sumologic/resource_sumologic_cse_threshold_rule.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func resourceSumologicCSEThresholdRuleRead(d *schema.ResourceData, meta interfac
8888

8989
CSEThresholdRuleGet, err := c.GetCSEThresholdRule(id)
9090
if err != nil {
91-
log.Printf("[WARN] CSE Insights Status not found when looking by id: %s, err: %v", id, err)
91+
log.Printf("[WARN] CSE Threshold Rule not found when looking by id: %s, err: %v", id, err)
9292
}
9393

9494
if CSEThresholdRuleGet == nil {
95-
log.Printf("[WARN] CSE Insights Status not found, removing from state: %v - %v", id, err)
95+
log.Printf("[WARN] CSE Threshold Rule not found, removing from state: %v - %v", id, err)
9696
d.SetId("")
9797
return nil
9898
}
@@ -101,7 +101,7 @@ func resourceSumologicCSEThresholdRuleRead(d *schema.ResourceData, meta interfac
101101
d.Set("count_field", CSEThresholdRuleGet.CountField)
102102
d.Set("description", CSEThresholdRuleGet.Description)
103103
d.Set("enabled", CSEThresholdRuleGet.Enabled)
104-
d.Set("entity_selectors", CSEThresholdRuleGet.EntitySelectors)
104+
d.Set("entity_selectors", entitySelectorArrayToResource(CSEThresholdRuleGet.EntitySelectors))
105105
d.Set("expression", CSEThresholdRuleGet.Expression)
106106
d.Set("group_by_fields", CSEThresholdRuleGet.GroupByFields)
107107
d.Set("is_prototype", CSEThresholdRuleGet.IsPrototype)
@@ -147,7 +147,6 @@ func resourceSumologicCSEThresholdRuleCreate(d *schema.ResourceData, meta interf
147147
if err != nil {
148148
return err
149149
}
150-
log.Printf("[INFO] got id: %s", id)
151150
d.SetId(id)
152151
}
153152

sumologic/sumologic_cse_rule_common.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ func resourceToEntitySelectorArray(resourceEntitySelectors []interface{}) []Enti
9090
return result
9191
}
9292

93+
func entitySelectorArrayToResource(entitySelectors []EntitySelector) []map[string]interface{} {
94+
result := make([]map[string]interface{}, len(entitySelectors))
95+
96+
for i, entitySelector := range entitySelectors {
97+
result[i] = map[string]interface{}{
98+
"entity_type": entitySelector.EntityType,
99+
"expression": entitySelector.Expression,
100+
}
101+
}
102+
103+
return result
104+
}
105+
93106
func resourceToSeverityMappingValueMappingArray(resourceSeverityMappingValueMappings []interface{}) []SeverityMappingValueMapping {
94107
result := make([]SeverityMappingValueMapping, len(resourceSeverityMappingValueMappings))
95108

@@ -115,6 +128,29 @@ func resourceToSeverityMapping(resourceSeverityMapping interface{}) SeverityMapp
115128
}
116129
}
117130

131+
func severityMappingValueMappingArrayToResource(severityMappingValueMappings []SeverityMappingValueMapping) []map[string]interface{} {
132+
result := make([]map[string]interface{}, len(severityMappingValueMappings))
133+
134+
for i, severityMappingValueMapping := range severityMappingValueMappings {
135+
result[i] = map[string]interface{}{
136+
"type": severityMappingValueMapping.Type,
137+
"from": severityMappingValueMapping.From,
138+
"to": severityMappingValueMapping.To,
139+
}
140+
}
141+
142+
return result
143+
}
144+
145+
func severityMappingToResource(severityMapping SeverityMapping) map[string]interface{} {
146+
return map[string]interface{}{
147+
"type": severityMapping.Type,
148+
"default": severityMapping.Default,
149+
"field": severityMapping.Field,
150+
"mapping": severityMappingValueMappingArrayToResource(severityMapping.Mapping),
151+
}
152+
}
153+
118154
type EntitySelector struct {
119155
Expression string `json:"expression"`
120156
EntityType string `json:"entityType"`

sumologic/sumologic_cse_threshold_rule.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ func (s *Client) UpdateCSEThresholdRule(CSEThresholdRule CSEThresholdRule) error
5555
url := fmt.Sprintf("sec/v1/rules/threshold/%s", CSEThresholdRule.ID)
5656

5757
CSEThresholdRule.ID = ""
58-
fmt.Printf("Window Size: %s\n", CSEThresholdRule.WindowSize)
59-
fmt.Printf("Window Size Name: %s\n", CSEThresholdRule.WindowSizeName)
6058
request := CSEThresholdRuleRequest{
6159
CSEThresholdRule: CSEThresholdRule,
6260
}

0 commit comments

Comments
 (0)