Skip to content

Commit 88d58ed

Browse files
committed
DET-841: add support for strict custom insights
1 parent f060c64 commit 88d58ed

File tree

5 files changed

+106
-29
lines changed

5 files changed

+106
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## X.Y.Z (Unreleased)
22
* Add new change notes here
33

4+
FEATURES:
5+
* Add support for CSE strict custom insights
6+
47
## 3.0.5 (March 3, 2025)
58

69
ENHANCEMENTS:

sumologic/resource_sumologic_cse_custom_insight.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func resourceSumologicCSECustomInsight() *schema.Resource {
4545
Required: true,
4646
ValidateFunc: validation.StringInSlice([]string{"HIGH", "MEDIUM", "LOW", "CRITICAL"}, false),
4747
},
48+
"signal_match_strategy": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Default: "ENTITY",
52+
ValidateFunc: validation.StringInSlice([]string{"ENTITY", "STRICT"}, false),
53+
},
4854
"dynamic_severity": {
4955
Type: schema.TypeList,
5056
Optional: true,
@@ -103,6 +109,7 @@ func resourceSumologicCSECustomInsightRead(d *schema.ResourceData, meta interfac
103109
d.Set("ordered", CSECustomInsightGet.Ordered)
104110
d.Set("rule_ids", CSECustomInsightGet.RuleIds)
105111
d.Set("severity", CSECustomInsightGet.Severity)
112+
d.Set("signal_match_strategy", CSECustomInsightGet.SignalMatchStrategy)
106113
d.Set("dynamic_severity", dynamicSeverityArrayToResource(CSECustomInsightGet.DynamicSeverity))
107114
d.Set("signal_names", CSECustomInsightGet.SignalNames)
108115
d.Set("tags", CSECustomInsightGet.Tags)
@@ -121,15 +128,16 @@ func resourceSumologicCSECustomInsightCreate(d *schema.ResourceData, meta interf
121128

122129
if d.Id() == "" {
123130
id, err := c.CreateCSECustomInsight(CSECustomInsight{
124-
Description: d.Get("description").(string),
125-
Enabled: d.Get("enabled").(bool),
126-
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
127-
Name: d.Get("name").(string),
128-
Ordered: d.Get("ordered").(bool),
129-
Severity: d.Get("severity").(string),
130-
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
131-
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
132-
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
131+
Description: d.Get("description").(string),
132+
Enabled: d.Get("enabled").(bool),
133+
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
134+
Name: d.Get("name").(string),
135+
Ordered: d.Get("ordered").(bool),
136+
Severity: d.Get("severity").(string),
137+
SignalMatchStrategy: resourceToSignalMatchStrategy(d.Get("signal_match_strategy")),
138+
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
139+
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
140+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
133141
})
134142

135143
if err != nil {
@@ -162,16 +170,17 @@ func resourceToCSECustomInsight(d *schema.ResourceData) (CSECustomInsight, error
162170
}
163171

164172
return CSECustomInsight{
165-
ID: id,
166-
Description: d.Get("description").(string),
167-
Enabled: d.Get("enabled").(bool),
168-
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
169-
Name: d.Get("name").(string),
170-
Ordered: d.Get("ordered").(bool),
171-
Severity: d.Get("severity").(string),
172-
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
173-
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
174-
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
173+
ID: id,
174+
Description: d.Get("description").(string),
175+
Enabled: d.Get("enabled").(bool),
176+
RuleIds: resourceToStringArray(d.Get("rule_ids").([]interface{})),
177+
Name: d.Get("name").(string),
178+
Ordered: d.Get("ordered").(bool),
179+
Severity: d.Get("severity").(string),
180+
SignalMatchStrategy: resourceToSignalMatchStrategy(d.Get("signal_match_strategy")),
181+
DynamicSeverity: resourceToDynamicSeverityArray(d.Get("dynamic_severity").([]interface{})),
182+
SignalNames: resourceToStringArray(d.Get("signal_names").([]interface{})),
183+
Tags: resourceToStringArray(d.Get("tags").([]interface{})),
175184
}, nil
176185
}
177186

@@ -200,3 +209,10 @@ func dynamicSeverityArrayToResource(dynamicSeverities []DynamicSeverity) []map[s
200209

201210
return result
202211
}
212+
213+
func resourceToSignalMatchStrategy(value any) string {
214+
if v, ok := value.(string); ok {
215+
return v
216+
}
217+
return ""
218+
}

sumologic/resource_sumologic_cse_custom_insight_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ func TestAccSumologicCSECustomInsight_createAndUpdateWithDynamicSeverity(t *test
107107
})
108108
}
109109

110+
func TestAccSumologicCSECustomInsight_createAndUpdateWithSignalMatchStrategy(t *testing.T) {
111+
SkipCseTest(t)
112+
113+
var CustomInsight CSECustomInsight
114+
resourceName := "sumologic_cse_custom_insight.custom_insight_signal_match_strategy"
115+
resource.Test(t, resource.TestCase{
116+
PreCheck: func() { testAccPreCheck(t) },
117+
Providers: testAccProviders,
118+
CheckDestroy: testAccCSECustomInsightDestroy,
119+
Steps: []resource.TestStep{
120+
{
121+
Config: testCreateCSECustomInsightConfigWithSignalMatchStrategy("STRICT"),
122+
Check: resource.ComposeTestCheckFunc(
123+
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
124+
testCheckCustomInsightSignalMatchStrategy(t, &CustomInsight, "STRICT"),
125+
),
126+
},
127+
{
128+
Config: testCreateCSECustomInsightConfigWithSignalMatchStrategy("ENTITY"),
129+
Check: resource.ComposeTestCheckFunc(
130+
testCheckCSECustomInsightExists(resourceName, &CustomInsight),
131+
testCheckCustomInsightSignalMatchStrategy(t, &CustomInsight, "ENTITY"),
132+
),
133+
},
134+
{
135+
ResourceName: resourceName,
136+
ImportState: true,
137+
ImportStateVerify: true,
138+
},
139+
},
140+
})
141+
}
142+
110143
func testAccCSECustomInsightDestroy(s *terraform.State) error {
111144
client := testAccProvider.Meta().(*Client)
112145

@@ -219,3 +252,25 @@ func testCheckCustomInsightDynamicSeverity(t *testing.T, CustomInsight *CSECusto
219252
return nil
220253
}
221254
}
255+
256+
func testCreateCSECustomInsightConfigWithSignalMatchStrategy(signalMatchStrategy string) string {
257+
const config = `
258+
resource "sumologic_cse_custom_insight" "custom_insight_signal_match_strategy" {
259+
description = "Signal match strategy insight"
260+
enabled = true
261+
ordered = true
262+
name = "Signal match strategy insight"
263+
severity = "LOW"
264+
signal_match_strategy = "%s"
265+
tags = ["test tag"]
266+
}
267+
`
268+
return fmt.Sprintf(config, signalMatchStrategy)
269+
}
270+
271+
func testCheckCustomInsightSignalMatchStrategy(t *testing.T, customInsight *CSECustomInsight, expectedSignalMatchStrategy string) resource.TestCheckFunc {
272+
return func(s *terraform.State) error {
273+
assert.Equal(t, expectedSignalMatchStrategy, customInsight.SignalMatchStrategy)
274+
return nil
275+
}
276+
}

sumologic/sumologic_cse_custom_insight.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ type DynamicSeverity struct {
7878
}
7979

8080
type CSECustomInsight struct {
81-
ID string `json:"id,omitempty"`
82-
Description string `json:"description"`
83-
Enabled bool `json:"enabled"`
84-
Name string `json:"name"`
85-
Ordered bool `json:"ordered"`
86-
RuleIds []string `json:"ruleIds"`
87-
Severity string `json:"severity"`
88-
DynamicSeverity []DynamicSeverity `json:"dynamicSeverity"`
89-
SignalNames []string `json:"signalNames"`
90-
Tags []string `json:"tags"`
81+
ID string `json:"id,omitempty"`
82+
Description string `json:"description"`
83+
Enabled bool `json:"enabled"`
84+
Name string `json:"name"`
85+
Ordered bool `json:"ordered"`
86+
RuleIds []string `json:"ruleIds"`
87+
Severity string `json:"severity"`
88+
DynamicSeverity []DynamicSeverity `json:"dynamicSeverity"`
89+
SignalNames []string `json:"signalNames"`
90+
Tags []string `json:"tags"`
91+
SignalMatchStrategy string `json:"signalMatchStrategy,omitempty"`
9192
}

website/docs/r/cse_custom_insight.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ resource "sumologic_cse_custom_insight" "custom_insight" {
1717
name = "Custom Insight Example"
1818
rule_ids = ["MATCH-S00001", "THRESHOLD-U00005"]
1919
severity = "HIGH"
20+
signal_match_strategy = "ENTITY"
2021
dynamic_severity {
2122
minimum_signal_severity = 8
2223
insight_severity = "CRITICAL"
@@ -36,6 +37,7 @@ The following arguments are supported:
3637
- `name` - (Required) The name of the Custom Insight and the generated Insights
3738
- `rule_ids` - (Optional) The Rule IDs to match to generate an Insight (exactly one of rule_ids or signal_names must be specified)
3839
- `severity` - (Required) The severity of the generated Insights (CRITICAL, HIGH, MEDIUM, or LOW)
40+
- `signal_match_strategy` - (Optional) The signal match strategy to use when generating insights (ENTITY, STRICT)
3941
- `dynamic_severity` - (Optional) The severity of the generated Insight that is based on the severity of the Signals that trigger the Insight.
4042
+ `minimum_signal_severity` - (Required) minimum Signal severity as the threshold for an Insight severity level
4143
+ `insight_severity` - (Required) The severity of the generated Insight (CRITICAL, HIGH, MEDIUM, or LOW)

0 commit comments

Comments
 (0)