Skip to content

Commit a5af0cc

Browse files
committed
SUMO-196857: adding alert grouping support for monitors
1 parent 863c7ff commit a5af0cc

File tree

5 files changed

+81
-51
lines changed

5 files changed

+81
-51
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
FEATURES:
33
* **New Resource:** sumologic_cse_entity_entity_group_configuration (GH-376)
44
* **New Resource:** sumologic_cse_inventory_entity_group_configuration (GH-376)
5+
* Add new optional `notification_group_fields` field to resource/sumologic_monitor (GH-390)
56

67
## 2.16.2 (June 12, 2022)
78

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
353353
Optional: true,
354354
ValidateFunc: validation.StringLenBetween(1, 512),
355355
},
356+
"notification_group_fields": {
357+
Type: schema.TypeList,
358+
Optional: true,
359+
Elem: &schema.Schema{
360+
Type: schema.TypeString,
361+
},
362+
},
356363
},
357364
}
358365
}
@@ -608,6 +615,7 @@ func resourceSumologicMonitorsLibraryMonitorRead(d *schema.ResourceData, meta in
608615
d.Set("playbook", monitor.Playbook)
609616
d.Set("alert_name", monitor.AlertName)
610617
d.Set("slo_id", monitor.SloID)
618+
d.Set("notification_group_fields", monitor.NotificationGroupFields)
611619
// set notifications
612620
notifications := make([]interface{}, len(monitor.Notifications))
613621
for i, n := range monitor.Notifications {
@@ -1271,33 +1279,39 @@ func resourceToMonitorsLibraryMonitor(d *schema.ResourceData) MonitorsLibraryMon
12711279
for i := range rawStatus {
12721280
status[i] = rawStatus[i].(string)
12731281
}
1282+
rawGroupFields := d.Get("notification_group_fields").([]interface{})
1283+
notificationGroupFields := make([]string, len(rawGroupFields))
1284+
for i := range rawGroupFields {
1285+
notificationGroupFields[i] = rawGroupFields[i].(string)
1286+
}
12741287

12751288
return MonitorsLibraryMonitor{
1276-
CreatedBy: d.Get("created_by").(string),
1277-
Name: d.Get("name").(string),
1278-
ID: d.Id(),
1279-
CreatedAt: d.Get("created_at").(string),
1280-
MonitorType: d.Get("monitor_type").(string),
1281-
Description: d.Get("description").(string),
1282-
EvaluationDelay: d.Get("evaluation_delay").(string),
1283-
Queries: queries,
1284-
ModifiedBy: d.Get("modified_by").(string),
1285-
IsMutable: d.Get("is_mutable").(bool),
1286-
Version: d.Get("version").(int),
1287-
Notifications: notifications,
1288-
Type: d.Get("type").(string),
1289-
ParentID: d.Get("parent_id").(string),
1290-
ModifiedAt: d.Get("modified_at").(string),
1291-
Triggers: triggers,
1292-
ContentType: d.Get("content_type").(string),
1293-
IsLocked: d.Get("is_locked").(bool),
1294-
IsSystem: d.Get("is_system").(bool),
1295-
IsDisabled: d.Get("is_disabled").(bool),
1296-
Status: status,
1297-
GroupNotifications: d.Get("group_notifications").(bool),
1298-
Playbook: d.Get("playbook").(string),
1299-
AlertName: d.Get("alert_name").(string),
1300-
SloID: d.Get("slo_id").(string),
1289+
CreatedBy: d.Get("created_by").(string),
1290+
Name: d.Get("name").(string),
1291+
ID: d.Id(),
1292+
CreatedAt: d.Get("created_at").(string),
1293+
MonitorType: d.Get("monitor_type").(string),
1294+
Description: d.Get("description").(string),
1295+
EvaluationDelay: d.Get("evaluation_delay").(string),
1296+
Queries: queries,
1297+
ModifiedBy: d.Get("modified_by").(string),
1298+
IsMutable: d.Get("is_mutable").(bool),
1299+
Version: d.Get("version").(int),
1300+
Notifications: notifications,
1301+
Type: d.Get("type").(string),
1302+
ParentID: d.Get("parent_id").(string),
1303+
ModifiedAt: d.Get("modified_at").(string),
1304+
Triggers: triggers,
1305+
ContentType: d.Get("content_type").(string),
1306+
IsLocked: d.Get("is_locked").(bool),
1307+
IsSystem: d.Get("is_system").(bool),
1308+
IsDisabled: d.Get("is_disabled").(bool),
1309+
Status: status,
1310+
GroupNotifications: d.Get("group_notifications").(bool),
1311+
Playbook: d.Get("playbook").(string),
1312+
AlertName: d.Get("alert_name").(string),
1313+
SloID: d.Get("slo_id").(string),
1314+
NotificationGroupFields: notificationGroupFields,
13011315
}
13021316
}
13031317

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
189189
},
190190
}
191191
testAlertName := "Alert from {{Name}}"
192+
testGroupFields := [2]string{"groupingField1", "groupingField2"}
192193

193194
resource.Test(t, resource.TestCase{
194195
PreCheck: func() { testAccPreCheck(t) },
@@ -212,6 +213,8 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
212213
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.time_range", testTriggers[0].TimeRange),
213214
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType),
214215
resource.TestCheckResourceAttr("sumologic_monitor.test", "alert_name", testAlertName),
216+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testGroupFields[0]),
217+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testGroupFields[1]),
215218
),
216219
},
217220
},
@@ -306,6 +309,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
306309
},
307310
}
308311
testAlertName := "Alert from {{Name}}"
312+
testGroupFields := [2]string{"groupingField1", "groupingField2"}
309313

310314
// updated fields
311315
testUpdatedName := "terraform_test_monitor_" + testNameSuffix
@@ -366,6 +370,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
366370
},
367371
}
368372
testUpdatedAlertName := "Updated Alert from {{Name}}"
373+
testUpdatedGroupFields := [2]string{"groupingField3", "groupingField4"}
369374

370375
resource.Test(t, resource.TestCase{
371376
PreCheck: func() { testAccPreCheck(t) },
@@ -390,6 +395,8 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
390395
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testNotifications[0].Notification.(EmailNotification).ConnectionType),
391396
resource.TestCheckResourceAttr("sumologic_monitor.test", "playbook", testPlaybook),
392397
resource.TestCheckResourceAttr("sumologic_monitor.test", "alert_name", testAlertName),
398+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testGroupFields[0]),
399+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testGroupFields[1]),
393400
),
394401
},
395402
{
@@ -408,6 +415,8 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
408415
resource.TestCheckResourceAttr("sumologic_monitor.test", "notifications.0.notification.0.connection_type", testUpdatedNotifications[0].Notification.(EmailNotification).ConnectionType),
409416
resource.TestCheckResourceAttr("sumologic_monitor.test", "playbook", testUpdatedPlaybook),
410417
resource.TestCheckResourceAttr("sumologic_monitor.test", "alert_name", testUpdatedAlertName),
418+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.0", testUpdatedGroupFields[0]),
419+
resource.TestCheckResourceAttr("sumologic_monitor.test", "notification_group_fields.1", testUpdatedGroupFields[1]),
411420
),
412421
},
413422
},
@@ -523,6 +532,7 @@ resource "sumologic_monitor" "test" {
523532
}
524533
playbook = "This is a test playbook"
525534
alert_name = "Alert from {{Name}}"
535+
notification_group_fields = ["groupingField1", "groupingField2"]
526536
}`, testName)
527537
}
528538

@@ -570,6 +580,7 @@ resource "sumologic_monitor" "test" {
570580
}
571581
playbook = "This is an updated test playbook"
572582
alert_name = "Updated Alert from {{Name}}"
583+
notification_group_fields = ["groupingField3", "groupingField4"]
573584
}`, testName)
574585
}
575586

sumologic/sumologic_monitors_library_monitor.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,32 @@ func (s *Client) MoveMonitorsLibraryMonitor(monitorsLibraryMonitor MonitorsLibra
115115

116116
// ---------- TYPES ----------
117117
type MonitorsLibraryMonitor struct {
118-
ID string `json:"id,omitempty"`
119-
IsSystem bool `json:"isSystem"`
120-
Type string `json:"type"`
121-
Queries []MonitorQuery `json:"queries,omitempty"`
122-
ParentID string `json:"parentId"`
123-
Name string `json:"name"`
124-
IsMutable bool `json:"isMutable"`
125-
Version int `json:"version"`
126-
Notifications []MonitorNotification `json:"notifications,omitempty"`
127-
CreatedBy string `json:"createdBy"`
128-
MonitorType string `json:"monitorType"`
129-
EvaluationDelay string `json:"evaluationDelay,omitempty"`
130-
IsLocked bool `json:"isLocked"`
131-
Description string `json:"description"`
132-
CreatedAt string `json:"createdAt"`
133-
Triggers []TriggerCondition `json:"triggers,omitempty"`
134-
ModifiedAt string `json:"modifiedAt"`
135-
ContentType string `json:"contentType"`
136-
ModifiedBy string `json:"modifiedBy"`
137-
IsDisabled bool `json:"isDisabled"`
138-
Status []string `json:"status"`
139-
GroupNotifications bool `json:"groupNotifications"`
140-
Playbook string `json:"playbook,omitempty"`
141-
AlertName string `json:"alertName,omitempty"`
142-
SloID string `json:"sloId,omitempty"`
118+
ID string `json:"id,omitempty"`
119+
IsSystem bool `json:"isSystem"`
120+
Type string `json:"type"`
121+
Queries []MonitorQuery `json:"queries,omitempty"`
122+
ParentID string `json:"parentId"`
123+
Name string `json:"name"`
124+
IsMutable bool `json:"isMutable"`
125+
Version int `json:"version"`
126+
Notifications []MonitorNotification `json:"notifications,omitempty"`
127+
CreatedBy string `json:"createdBy"`
128+
MonitorType string `json:"monitorType"`
129+
EvaluationDelay string `json:"evaluationDelay,omitempty"`
130+
IsLocked bool `json:"isLocked"`
131+
Description string `json:"description"`
132+
CreatedAt string `json:"createdAt"`
133+
Triggers []TriggerCondition `json:"triggers,omitempty"`
134+
ModifiedAt string `json:"modifiedAt"`
135+
ContentType string `json:"contentType"`
136+
ModifiedBy string `json:"modifiedBy"`
137+
IsDisabled bool `json:"isDisabled"`
138+
Status []string `json:"status"`
139+
GroupNotifications bool `json:"groupNotifications"`
140+
Playbook string `json:"playbook,omitempty"`
141+
AlertName string `json:"alertName,omitempty"`
142+
SloID string `json:"sloId,omitempty"`
143+
NotificationGroupFields []string `json:"notificationGroupFields,omitempty"`
143144
}
144145

145146
type MonitorQuery struct {

website/docs/r/monitor.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ resource "sumologic_monitor" "tf_logs_monitor_1" {
6363
}
6464
playbook = "{{Name}} should be fixed in 24 hours when {{TriggerType}} is triggered."
6565
alert_name = "Alert {{ResultJson.my_field}} from {{Name}}"
66+
notification_group_fields = ["_sourceHost"]
6667
}
6768
```
6869

@@ -80,7 +81,7 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" {
8081
8182
queries {
8283
row_id = "A"
83-
query = "metric=CPU_Idle _sourceCategory=event-action"
84+
query = "metric=CPU* _sourceCategory=event-action"
8485
}
8586
8687
trigger_conditions {
@@ -110,6 +111,7 @@ resource "sumologic_monitor" "tf_metrics_monitor_1" {
110111
run_for_trigger_types = ["Critical", "ResolvedCritical"]
111112
}
112113
playbook = "test playbook"
114+
notification_group_fields = ["metric"]
113115
}
114116
```
115117

@@ -288,6 +290,7 @@ The following arguments are supported:
288290
- `group_notifications` - (Optional) Whether or not to group notifications for individual items that meet the trigger condition. Defaults to true.
289291
- `playbook` - (Optional - Beta) Notes such as links and instruction to help you resolve alerts triggered by this monitor. {{Markdown}} supported. It will be enabled only if available for your organization. Please contact your Sumo Logic account team to learn more.
290292
- `alert_name` - (Optional) The display name when creating alerts. Monitor name will be used if `alert_name` is not provided. All template variables can be used in `alert_name` except `{{AlertName}}` and `{{ResultsJson}}`.
293+
- `notification_group_fields` - (Optional - Beta) Set of fields used to group data to create independent notifications and alerts.
291294

292295
Additional data provided in state:
293296

0 commit comments

Comments
 (0)