Skip to content

Commit a69f90c

Browse files
committed
feat(alerts): add notify_on_acknwoledge, deprecated opts at notification channel level
1 parent 9c6e110 commit a69f90c

File tree

35 files changed

+217
-180
lines changed

35 files changed

+217
-180
lines changed

sysdig/internal/client/v2/model.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ type NotificationChannelOptions struct {
138138
CustomData map[string]any `json:"customData,omitempty"` // Type: ibm function, Webhook
139139
TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` // Type: slack, ms teams
140140

141-
NotifyOnOk bool `json:"notifyOnOk"`
142-
NotifyOnResolve bool `json:"notifyOnResolve"`
143-
SendTestNotification bool `json:"sendTestNotification"`
141+
NotifyOnOk *bool `json:"notifyOnOk,omitempty"`
142+
NotifyOnResolve *bool `json:"notifyOnResolve,omitempty"`
143+
SendTestNotification bool `json:"sendTestNotification"`
144144
}
145145

146146
type NotificationChannel struct {
@@ -628,7 +628,7 @@ type NotificationChannelConfigV2 struct {
628628
}
629629

630630
type NotificationChannelOptionsV2 struct {
631-
NotifyOnAcknowledge bool `json:"notifyOnAcknowledge,omitempty"`
631+
NotifyOnAcknowledge *bool `json:"notifyOnAcknowledge,omitempty"`
632632
NotifyOnResolve bool `json:"notifyOnResolve"`
633633
ReNotifyEverySec *int `json:"reNotifyEverySec"`
634634
CustomNotificationTemplate *CustomNotificationTemplateV2 `json:"customNotificationTemplate,omitempty"`

sysdig/resource_sysdig_monitor_alert_v2_common.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func createAlertV2Schema(original map[string]*schema.Schema) map[string]*schema.
8383
Optional: true,
8484
Default: true,
8585
},
86+
"notify_on_acknowledge": {
87+
Type: schema.TypeString,
88+
Optional: true,
89+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
90+
},
8691
"main_threshold": {
8792
Type: schema.TypeBool,
8893
Optional: true,
@@ -262,6 +267,16 @@ func buildAlertV2CommonStruct(d *schema.ResourceData) *v2.AlertV2Common {
262267
}
263268

264269
newChannel.OverrideOptions.NotifyOnResolve = channelMap["notify_on_resolve"].(bool)
270+
if notifyOnAcknowledge, ok := channelMap["notify_on_acknowledge"]; ok && notifyOnAcknowledge.(string) != "" {
271+
if notifyOnAcknowledge.(string) == "true" {
272+
trueValue := true
273+
newChannel.OverrideOptions.NotifyOnAcknowledge = &trueValue
274+
} else {
275+
falseValue := false
276+
newChannel.OverrideOptions.NotifyOnAcknowledge = &falseValue
277+
}
278+
// else do not set any value for newChannel.OverrideOptions.NotifyOnAcknowledge
279+
}
265280

266281
newChannel.OverrideOptions.Thresholds = []string{}
267282
mainThreshold := channelMap["main_threshold"].(bool)
@@ -358,6 +373,14 @@ func updateAlertV2CommonState(d *schema.ResourceData, alert *v2.AlertV2Common) (
358373
"notify_on_resolve": ncc.OverrideOptions.NotifyOnResolve,
359374
}
360375

376+
if ncc.OverrideOptions.NotifyOnAcknowledge != nil {
377+
if *ncc.OverrideOptions.NotifyOnAcknowledge {
378+
config["notify_on_acknowledge"] = "true"
379+
} else {
380+
config["notify_on_acknowledge"] = "false"
381+
}
382+
}
383+
361384
if ncc.OverrideOptions.ReNotifyEverySec != nil {
362385
config["renotify_every_minutes"] = secondsToMinutes(*ncc.OverrideOptions.ReNotifyEverySec)
363386
} else {

sysdig/resource_sysdig_monitor_notification_channel_common.go

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sysdig
33
import (
44
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
67
)
78

89
func createMonitorNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
@@ -22,14 +23,16 @@ func createMonitorNotificationChannelSchema(original map[string]*schema.Schema)
2223
Default: false,
2324
},
2425
"notify_when_ok": {
25-
Type: schema.TypeBool,
26-
Optional: true,
27-
Default: false,
26+
Type: schema.TypeString,
27+
Optional: true,
28+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
29+
Deprecated: "The notify_when_ok field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_resolve` field inside `notification_channels` when defining an alert resource.",
2830
},
2931
"notify_when_resolved": {
30-
Type: schema.TypeBool,
31-
Optional: true,
32-
Default: false,
32+
Type: schema.TypeString,
33+
Optional: true,
34+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
35+
Deprecated: "The notify_when_resolved field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_acknowledge` field inside `notification_channels` when defining an alert resource.",
3336
},
3437
"version": {
3538
Type: schema.TypeInt,
@@ -56,13 +59,35 @@ func monitorNotificationChannelFromResourceData(d *schema.ResourceData, teamID i
5659
tID = &teamID
5760
}
5861

62+
var notifyOnOk *bool = nil
63+
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
64+
if onOk.(string) == "true" {
65+
trueValue := true
66+
notifyOnOk = &trueValue
67+
} else {
68+
falseValue := false
69+
notifyOnOk = &falseValue
70+
}
71+
}
72+
73+
var notifyOnResolve *bool = nil
74+
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
75+
if onResolve.(string) == "true" {
76+
trueValue := true
77+
notifyOnResolve = &trueValue
78+
} else {
79+
falseValue := false
80+
notifyOnResolve = &falseValue
81+
}
82+
}
83+
5984
nc = v2.NotificationChannel{
6085
Name: d.Get("name").(string),
6186
Enabled: d.Get("enabled").(bool),
6287
TeamID: tID,
6388
Options: v2.NotificationChannelOptions{
64-
NotifyOnOk: d.Get("notify_when_ok").(bool),
65-
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
89+
NotifyOnOk: notifyOnOk,
90+
NotifyOnResolve: notifyOnResolve,
6691
SendTestNotification: d.Get("send_test_notification").(bool),
6792
},
6893
}
@@ -82,8 +107,23 @@ func monitorNotificationChannelToResourceData(nc *v2.NotificationChannel, data *
82107
if err != nil {
83108
return err
84109
}
85-
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
86-
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
110+
111+
if nc.Options.NotifyOnOk != nil {
112+
if *nc.Options.NotifyOnOk {
113+
_ = data.Set("notify_when_ok", "true")
114+
} else {
115+
_ = data.Set("notify_when_ok", "false")
116+
}
117+
}
118+
119+
if nc.Options.NotifyOnResolve != nil {
120+
if *nc.Options.NotifyOnResolve {
121+
_ = data.Set("notify_when_resolved", "true")
122+
} else {
123+
_ = data.Set("notify_when_resolved", "false")
124+
}
125+
}
126+
87127
// do not update "send_test_notification" from the api response as it will always be "false" on subsequent reads because the fields is not persisted
88128

89129
return err

sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ func TestAccMonitorNotificationChannelCustomWebhook(t *testing.T) {
6969
ImportStateVerify: true,
7070
ImportStateVerifyIgnore: []string{"send_test_notification"},
7171
},
72+
{
73+
Config: monitorNotificationChannelCustomWebhookWithoutNotifyFields(rText()),
74+
},
75+
{
76+
ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook6",
77+
ImportState: true,
78+
ImportStateVerify: true,
79+
ImportStateVerifyIgnore: []string{"send_test_notification"},
80+
},
7281
},
7382
})
7483
}
@@ -150,3 +159,15 @@ func monitorNotificationChannelCustomWebhookSharedWithAdditionalHeaders(name str
150159
send_test_notification = false
151160
}`, name)
152161
}
162+
163+
func monitorNotificationChannelCustomWebhookWithoutNotifyFields(name string) string {
164+
return fmt.Sprintf(`
165+
resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook6" {
166+
name = "Example Channel %s - Custom Webhook"
167+
enabled = true
168+
url = "https://example.com/"
169+
http_method = "POST"
170+
template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}"
171+
send_test_notification = false
172+
}`, name)
173+
}

sysdig/resource_sysdig_secure_notification_channel_common.go

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sysdig
33
import (
44
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
67
)
78

89
func createSecureNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
@@ -22,14 +23,16 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m
2223
Default: false,
2324
},
2425
"notify_when_ok": {
25-
Type: schema.TypeBool,
26-
Optional: true,
27-
Default: false,
26+
Type: schema.TypeString,
27+
Optional: true,
28+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
29+
Deprecated: "The notify_when_ok field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_resolve` field inside `notification_channels` when defining an alert resource.",
2830
},
2931
"notify_when_resolved": {
30-
Type: schema.TypeBool,
31-
Optional: true,
32-
Default: false,
32+
Type: schema.TypeString,
33+
Optional: true,
34+
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
35+
Deprecated: "The notify_when_resolved field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_acknowledge` field inside `notification_channels` when defining an alert resource.",
3336
},
3437
"version": {
3538
Type: schema.TypeInt,
@@ -56,13 +59,35 @@ func secureNotificationChannelFromResourceData(d *schema.ResourceData, teamID in
5659
tID = &teamID
5760
}
5861

62+
var notifyOnOk *bool = nil
63+
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
64+
if onOk.(string) == "true" {
65+
trueValue := true
66+
notifyOnOk = &trueValue
67+
} else {
68+
falseValue := false
69+
notifyOnOk = &falseValue
70+
}
71+
}
72+
73+
var notifyOnResolve *bool = nil
74+
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
75+
if onResolve.(string) == "true" {
76+
trueValue := true
77+
notifyOnResolve = &trueValue
78+
} else {
79+
falseValue := false
80+
notifyOnResolve = &falseValue
81+
}
82+
}
83+
5984
nc = v2.NotificationChannel{
6085
Name: d.Get("name").(string),
6186
Enabled: d.Get("enabled").(bool),
6287
TeamID: tID,
6388
Options: v2.NotificationChannelOptions{
64-
NotifyOnOk: d.Get("notify_when_ok").(bool),
65-
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
89+
NotifyOnOk: notifyOnOk,
90+
NotifyOnResolve: notifyOnResolve,
6691
SendTestNotification: d.Get("send_test_notification").(bool),
6792
},
6893
}
@@ -82,8 +107,23 @@ func secureNotificationChannelToResourceData(nc *v2.NotificationChannel, data *s
82107
if err != nil {
83108
return err
84109
}
85-
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
86-
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
110+
111+
if nc.Options.NotifyOnOk != nil {
112+
if *nc.Options.NotifyOnOk {
113+
_ = data.Set("notify_when_ok", "true")
114+
} else {
115+
_ = data.Set("notify_when_ok", "false")
116+
}
117+
}
118+
119+
if nc.Options.NotifyOnResolve != nil {
120+
if *nc.Options.NotifyOnResolve {
121+
_ = data.Set("notify_when_resolved", "true")
122+
} else {
123+
_ = data.Set("notify_when_resolved", "false")
124+
}
125+
}
126+
87127
// do not update "send_test_notification" from the api response as it will always be "false" on subsequent reads because the fields is not persisted
88128

89129
return err

website/docs/r/monitor_alert_v2_change.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ By defining this field, the user can choose to which notification channels send
7575
It is a list of objects with the following fields:
7676
* `id` - (Required) The ID of the notification channel.
7777
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
78-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
78+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
79+
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
7980
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
8081
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
8182

website/docs/r/monitor_alert_v2_downtime.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ By defining this field, the user can choose to which notification channels send
6363
It is a list of objects with the following fields:
6464
* `id` - (Required) The ID of the notification channel.
6565
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
66-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
66+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
67+
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
6768

6869
### `custom_notification`
6970

@@ -94,7 +95,7 @@ Enables the creation of a capture file of the syscalls during the event.
9495
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
9596
* `storage` - (Optional) Custom bucket where to save the capture.
9697
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
97-
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
98+
* `enabled` - (Optional) Whether to enable captures. Default: `true`.
9899

99100
### Downtime alert arguments
100101

website/docs/r/monitor_alert_v2_event.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ By defining this field, the user can choose to which notification channels send
7373
It is a list of objects with the following fields:
7474
* `id` - (Required) The ID of the notification channel.
7575
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
76-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
76+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
77+
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
7778
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
7879
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
7980

@@ -106,7 +107,7 @@ Enables the creation of a capture file of the syscalls during the event.
106107
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
107108
* `storage` - (Optional) Custom bucket where to save the capture.
108109
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
109-
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
110+
* `enabled` - (Optional) Whether to enable captures. Default: `true`.
110111

111112
### Event alert arguments
112113

website/docs/r/monitor_alert_v2_form_based_prometheus.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ By defining this field, the user can choose to which notification channels send
5454
It is a list of objects with the following fields:
5555
* `id` - (Required) The ID of the notification channel.
5656
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled.
57-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
57+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
58+
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
5859
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
5960
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
6061

website/docs/r/monitor_alert_v2_group_outlier.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ By defining this field, the user can choose to which notification channels send
7575
It is a list of objects with the following fields:
7676
* `id` - (Required) The ID of the notification channel.
7777
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
78-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
78+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
79+
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
7980
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
8081
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
8182

@@ -108,7 +109,7 @@ Enables the creation of a capture file of the syscalls during the event.
108109
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
109110
* `storage` - (Optional) Custom bucket where to save the capture.
110111
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
111-
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
112+
* `enabled` - (Optional) Whether to enable captures. Default: `true`.
112113

113114
### Group Outlier alert arguments
114115

0 commit comments

Comments
 (0)