Skip to content

Commit da3d48c

Browse files
authored
feat(alerts): add notify_on_acknwoledge, deprecated opts at notification channel level (#679)
* add new attribute `notify_on_acknwoledge` on all alert resources, it should be used if one want to send a notification for an alert that has been manually acknowledged by a user; * deprecate `notify_when_ok` and `notify_when_resolved` on notification channel resources: users should define these behaviors at alert level now.
1 parent ad781b4 commit da3d48c

34 files changed

+109
-169
lines changed

sysdig/internal/client/v2/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ func createMonitorNotificationChannelSchema(original map[string]*schema.Schema)
2222
Default: false,
2323
},
2424
"notify_when_ok": {
25-
Type: schema.TypeBool,
26-
Optional: true,
27-
Default: false,
25+
Type: schema.TypeBool,
26+
Optional: true,
27+
Default: false,
28+
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.",
2829
},
2930
"notify_when_resolved": {
30-
Type: schema.TypeBool,
31-
Optional: true,
32-
Default: false,
31+
Type: schema.TypeBool,
32+
Optional: true,
33+
Default: false,
34+
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.",
3335
},
3436
"version": {
3537
Type: schema.TypeInt,

sysdig/resource_sysdig_secure_notification_channel_common.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m
2222
Default: false,
2323
},
2424
"notify_when_ok": {
25-
Type: schema.TypeBool,
26-
Optional: true,
27-
Default: false,
25+
Type: schema.TypeBool,
26+
Optional: true,
27+
Default: false,
28+
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.",
2829
},
2930
"notify_when_resolved": {
30-
Type: schema.TypeBool,
31-
Optional: true,
32-
Default: false,
31+
Type: schema.TypeBool,
32+
Optional: true,
33+
Default: false,
34+
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.",
3335
},
3436
"version": {
3537
Type: schema.TypeInt,

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.
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.
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.
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.
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.
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

website/docs/r/monitor_alert_v2_metric.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ By defining this field, the user can choose to which notification channels send
9090
It is a list of objects with the following fields:
9191
* `id` - (Required) The ID of the notification channel.
9292
* `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`.
93-
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
93+
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
94+
* `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.
9495
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
9596
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
9697

@@ -123,7 +124,7 @@ Enables the creation of a capture file of the syscalls during the event.
123124
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
124125
* `storage` - (Optional) Custom bucket where to save the capture.
125126
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
126-
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
127+
* `enabled` - (Optional) Whether to enable captures. Default: `true`.
127128

128129
### Metric Threshold alert arguments
129130

0 commit comments

Comments
 (0)