Skip to content

Commit

Permalink
fix(alerts): properly handle info severity (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbonf authored Jun 24, 2024
1 parent c448de9 commit 9ce2c75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
18 changes: 14 additions & 4 deletions sysdig/resource_sysdig_monitor_alert_v2_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func createAlertV2Schema(original map[string]*schema.Schema) map[string]*schema.
Optional: true,
Default: string(v2.AlertV2SeverityLow),
ValidateFunc: validation.StringInSlice(AlertV2SeverityValues(), true),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
},
"group": {
Type: schema.TypeString,
Expand Down Expand Up @@ -201,10 +204,14 @@ func AlertLinkV2TypeValues() []string {

func buildAlertV2CommonStruct(d *schema.ResourceData) *v2.AlertV2Common {
alert := &v2.AlertV2Common{
Name: d.Get("name").(string),
Type: "MANUAL",
Severity: d.Get("severity").(string),
Enabled: d.Get("enabled").(bool),
Name: d.Get("name").(string),
Type: "MANUAL",
Enabled: d.Get("enabled").(bool),
}

alert.Severity = strings.ToLower(d.Get("severity").(string))
if alert.Severity == "info" {
alert.Severity = "none"
}

if description, ok := d.GetOk("description"); ok {
Expand Down Expand Up @@ -307,6 +314,9 @@ func updateAlertV2CommonState(d *schema.ResourceData, alert *v2.AlertV2Common) (
_ = d.Set("name", alert.Name)
_ = d.Set("description", alert.Description)
_ = d.Set("severity", alert.Severity)
if alert.Severity == "none" {
_ = d.Set("severity", "info")
}

// optional with defaults
_ = d.Set("group", alert.Group)
Expand Down
20 changes: 20 additions & 0 deletions sysdig/resource_sysdig_monitor_alert_v2_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func TestAccAlertV2Metric(t *testing.T) {
{
Config: alertV2MetricWithSeverity(rText()),
},
{
Config: alertV2MetricWithSeverityInfo(rText()),
},
{
Config: alertV2MetricWithGroupBy(rText()),
},
Expand Down Expand Up @@ -202,6 +205,23 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
`, name)
}

func alertV2MetricWithSeverityInfo(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_alert_v2_metric" "sample" {
name = "TERRAFORM TEST - METRICV2 %s"
metric = "sysdig_container_cpu_used_percent"
group_aggregation = "avg"
time_aggregation = "avg"
operator = ">="
threshold = 50
trigger_after_minutes = 15
severity = "info"
}
`, name)
}

func alertV2MetricWithGroupBy(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_alert_v2_metric" "sample" {
Expand Down

0 comments on commit 9ce2c75

Please sign in to comment.