Skip to content

Commit 19dd5cd

Browse files
feat: Add alert group name (#190)
1 parent 577256c commit 19dd5cd

10 files changed

+66
-0
lines changed

sysdig/internal/client/monitor/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Alert struct {
4949
Name string `json:"name"`
5050
Description string `json:"description"`
5151
Enabled bool `json:"enabled"`
52+
GroupName string `json:"groupName,omitempty"`
5253
NotificationChannelIds []int `json:"notificationChannelIds"`
5354
Filter string `json:"filter"`
5455
Severity int `json:"severity"` // 6 == INFO, 4 == LOW, 2 == MEDIUM, 0 == HIGH // NOT USED

sysdig/resource_sysdig_monitor_alert_common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sysdig
33
import (
44
"errors"
55
"regexp"
6+
"strings"
67
"time"
78

89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -42,6 +43,14 @@ func createAlertSchema(original map[string]*schema.Schema) map[string]*schema.Sc
4243
Type: schema.TypeInt,
4344
Computed: true,
4445
},
46+
"group_name": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Default: "default",
50+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
51+
return strings.EqualFold(old, new)
52+
},
53+
},
4554
"team": {
4655
Type: schema.TypeInt,
4756
Computed: true,
@@ -148,6 +157,9 @@ func alertFromResourceData(d *schema.ResourceData) (alert *monitor.Alert, err er
148157
if description, ok := d.GetOk("description"); ok {
149158
alert.Description = description.(string)
150159
}
160+
if groupName, ok := d.GetOk("group_name"); ok {
161+
alert.GroupName = strings.ToLower(groupName.(string))
162+
}
151163
if version, ok := d.GetOk("version"); ok {
152164
alert.Version = version.(int)
153165
}
@@ -197,6 +209,7 @@ func alertToResourceData(alert *monitor.Alert, data *schema.ResourceData) (err e
197209
_ = data.Set("description", alert.Description)
198210
_ = data.Set("scope", alert.Filter)
199211
_ = data.Set("trigger_after_minutes", int(trigger_after_minutes.Minutes()))
212+
_ = data.Set("group_name", alert.GroupName)
200213
_ = data.Set("team", alert.TeamID)
201214
_ = data.Set("enabled", alert.Enabled)
202215
_ = data.Set("severity", alert.Severity)

sysdig/resource_sysdig_monitor_alert_metric_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func TestAccAlertMetric(t *testing.T) {
3030
{
3131
Config: alertMetricWithName(rText()),
3232
},
33+
{
34+
Config: alertMetricWithGroupName(rText()),
35+
},
3336
{
3437
Config: alertMetricWithoutScopeWithName(rText()),
3538
},
@@ -69,6 +72,30 @@ resource "sysdig_monitor_alert_metric" "sample" {
6972
`, name, name)
7073
}
7174

75+
func alertMetricWithGroupName(name string) string {
76+
return fmt.Sprintf(`
77+
resource "sysdig_monitor_alert_metric" "sample" {
78+
name = "TERRAFORM TEST - METRIC %s"
79+
description = "TERRAFORM TEST - METRIC %s"
80+
severity = 3
81+
82+
metric = "avg(avg(cpu.used.percent)) > 50"
83+
scope = "agent.id in (\"foo\")"
84+
85+
trigger_after_minutes = 10
86+
group_name = "sample_group_name"
87+
enabled = false
88+
89+
multiple_alerts_by = ["kubernetes.deployment.name"]
90+
91+
capture {
92+
filename = "TERRAFORM_TEST.scap"
93+
duration = 15
94+
}
95+
}
96+
`, name, name)
97+
}
98+
7299
func alertMetricWithoutScopeWithName(name string) string {
73100
return fmt.Sprintf(`
74101
resource "sysdig_monitor_alert_metric" "sample2" {

sysdig/resource_sysdig_monitor_alert_promql_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func TestAccAlertPromql(t *testing.T) {
3030
{
3131
Config: alertPromqlWithName(rText()),
3232
},
33+
{
34+
Config: alertPromqlWithGroupName(rText()),
35+
},
3336
{
3437
ResourceName: "sysdig_monitor_alert_promql.sample",
3538
ImportState: true,
@@ -54,3 +57,19 @@ resource "sysdig_monitor_alert_promql" "sample" {
5457
}
5558
`, name, name)
5659
}
60+
61+
func alertPromqlWithGroupName(name string) string {
62+
return fmt.Sprintf(`
63+
resource "sysdig_monitor_alert_promql" "sample" {
64+
name = "TERRAFORM TEST - PROMQL %s"
65+
description = "TERRAFORM TEST - PROMQL %s"
66+
severity = 3
67+
group_name = "sample_group_name"
68+
promql = "(elasticsearch_jvm_memory_used_bytes{area=\"heap\"} / elasticsearch_jvm_memory_max_bytes{area=\"heap\"}) * 100 > 80"
69+
70+
trigger_after_minutes = 10
71+
72+
enabled = false
73+
}
74+
`, name, name)
75+
}

website/docs/r/monitor_alert_anomaly.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ These arguments are common to all alerts in Sysdig Monitor.
4444
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
4545
* `scope` - (Optional) Part of the infrastructure where the alert is valid. Defaults to the entire infrastructure.
4646
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
47+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
4748
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
4849
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
4950
* `capture` - (Optional) Enables the creation of a capture file of the syscalls during the event.

website/docs/r/monitor_alert_downtime.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ These arguments are common to all alerts in Sysdig Monitor.
4040
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
4141
* `scope` - (Optional) Part of the infrastructure where the alert is valid. Defaults to the entire infrastructure.
4242
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
43+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
4344
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
4445
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
4546
* `capture` - (Optional) Enables the creation of a capture file of the syscalls during the event.

website/docs/r/monitor_alert_event.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ These arguments are common to all alerts in Sysdig Monitor.
4646
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
4747
* `scope` - (Optional) Part of the infrastructure where the alert is valid. Defaults to the entire infrastructure.
4848
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
49+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
4950
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
5051
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
5152
* `capture` - (Optional) Enables the creation of a capture file of the syscalls during the event.

website/docs/r/monitor_alert_group_outlier.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ These arguments are common to all alerts in Sysdig Monitor.
4444
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
4545
* `scope` - (Optional) Part of the infrastructure where the alert is valid. Defaults to the entire infrastructure.
4646
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
47+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
4748
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
4849
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
4950
* `capture` - (Optional) Enables the creation of a capture file of the syscalls during the event.

website/docs/r/monitor_alert_metric.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ These arguments are common to all alerts in Sysdig Monitor.
4848
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
4949
* `scope` - (Optional) Part of the infrastructure where the alert is valid. Defaults to the entire infrastructure.
5050
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
51+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
5152
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
5253
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
5354
* `capture` - (Optional) Enables the creation of a capture file of the syscalls during the event.

website/docs/r/monitor_alert_promql.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ These arguments are common to all alerts in Sysdig Monitor.
3737
with 0 being the most critical and 7 the less critical. Defaults to 4.
3838
* `trigger_after_minutes` - (Required) Threshold of time for the status to stabilize until the alert is fired.
3939
* `enabled` - (Optional) Boolean that defines if the alert is enabled or not. Defaults to true.
40+
* `group_name` - (Optional) Lowercase string to group alerts in the UI
4041
* `notification_channels` - (Optional) List of notification channel IDs where an alert must be sent to once fired.
4142
* `renotification_minutes` - (Optional) Number of minutes for the alert to re-notify until the status is solved.
4243
* `custom_notification` - (Optional) Allows to define a custom notification title, prepend and append text.

0 commit comments

Comments
 (0)