Skip to content

Commit e6c1a37

Browse files
authored
feat(monitor): support notify_on_resolve option in alerts (#260)
* feat(monitor): support notify_on_resolve option in alerts * fix(monitor): avoid drift on apply after update
1 parent 37a8e9b commit e6c1a37

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

sysdig/internal/client/monitor/models_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type NotificationChannelConfigV2 struct {
227227
type NotificationChannelOptionsV2 struct {
228228
// commons
229229
NotifyOnAcknowledge bool `json:"notifyOnAcknowledge,omitempty"`
230-
NotifyOnResolve bool `json:"notifyOnResolve,omitempty"`
230+
NotifyOnResolve bool `json:"notifyOnResolve"`
231231
ReNotifyEverySec *int `json:"reNotifyEverySec"` // must send null to remove this opt
232232
CustomNotificationTemplate *CustomNotificationTemplateV2 `json:"customNotificationTemplate,omitempty"`
233233
Thresholds []string `json:"thresholds"` //Set of thresholds the notification channel will be used for. Possible values [MAIN, WARNING]

sysdig/resource_sysdig_monitor_alert_v2_common.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,19 @@ func createAlertV2Schema(original map[string]*schema.Schema) map[string]*schema.
7373
"type": {
7474
Type: schema.TypeString,
7575
Optional: true, //for retro compatibility, content will be discarded, remove this is the next major release
76+
Default: "",
7677
Deprecated: "no need to define \"type\" attribute anymore, please remove it",
7778
},
7879
"renotify_every_minutes": {
7980
Type: schema.TypeInt,
8081
Optional: true,
8182
Default: 0,
8283
},
84+
"notify_on_resolve": {
85+
Type: schema.TypeBool,
86+
Optional: true,
87+
Default: true,
88+
},
8389
"main_threshold": {
8490
Type: schema.TypeBool,
8591
Optional: true,
@@ -222,6 +228,8 @@ func buildAlertV2CommonStruct(d *schema.ResourceData) *monitor.AlertV2Common {
222228
}
223229
}
224230

231+
newChannel.OverrideOptions.NotifyOnResolve = channelMap["notify_on_resolve"].(bool)
232+
225233
newChannel.OverrideOptions.Thresholds = []string{}
226234
main_threshold := channelMap["main_threshold"].(bool)
227235
if main_threshold {
@@ -299,7 +307,8 @@ func updateAlertV2CommonState(d *schema.ResourceData, alert *monitor.AlertV2Comm
299307
var notificationChannels []interface{}
300308
for _, ncc := range alert.NotificationChannelConfigList {
301309
config := map[string]interface{}{
302-
"id": ncc.ChannelID,
310+
"id": ncc.ChannelID,
311+
"notify_on_resolve": ncc.OverrideOptions.NotifyOnResolve,
303312
}
304313

305314
if ncc.OverrideOptions.ReNotifyEverySec != nil {

sysdig/resource_sysdig_monitor_alert_v2_metric_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func alertV2MetricWithNotificationChannels(name string) string {
139139
resource "sysdig_monitor_alert_v2_metric" "sample" {
140140
141141
name = "TERRAFORM TEST - METRICV2 %s"
142-
metric = "sysdig_container_cpu_used_percent"
142+
metric = "sysdig_container_cpu_used_percent"
143143
group_aggregation = "avg"
144144
time_aggregation = "avg"
145145
operator = ">="
@@ -148,6 +148,7 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
148148
enabled = false
149149
notification_channels {
150150
id = 47160
151+
notify_on_resolve = false
151152
}
152153
notification_channels {
153154
id = 47163
@@ -203,8 +204,8 @@ func alertV2MetricWithGroupBy(name string) string {
203204
threshold = 50
204205
trigger_after_minutes = 15
205206
group_by = ["kube_cluster_name", "kube_pod_name", "cloud_provider_tag_Owner",]
206-
207-
}
207+
208+
}
208209
`, name)
209210
}
210211

@@ -292,7 +293,7 @@ func alertV2MetricWithEnabled(name string) string {
292293
resource "sysdig_monitor_alert_v2_metric" "sample" {
293294
294295
name = "TERRAFORM TEST - METRICV2 %s"
295-
metric = "sysdig_container_cpu_used_percent"
296+
metric = "sysdig_container_cpu_used_percent"
296297
group_aggregation = "avg"
297298
time_aggregation = "avg"
298299
operator = ">="
@@ -309,7 +310,7 @@ func alertV2MetricWithWarningThreshold(name string) string {
309310
resource "sysdig_monitor_alert_v2_metric" "sample" {
310311
311312
name = "TERRAFORM TEST - METRICV2 %s"
312-
metric = "sysdig_container_cpu_used_percent"
313+
metric = "sysdig_container_cpu_used_percent"
313314
group_aggregation = "avg"
314315
time_aggregation = "avg"
315316
operator = ">="

website/docs/r/monitor_alert_v2_downtime.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ These arguments are common to all alerts in Sysdig Monitor.
5757

5858
### `notification_channels`
5959

60-
By defining this field, the user can choose to which notification channels send the events when the alert fires.
60+
By defining this field, the user can choose to which notification channels send the events when the alert fires.
6161

6262
It is a list of objects with the following fields:
6363
* `id` - (Required) The ID of the notification channel.
64-
* `renotify_every_minutes`: (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
64+
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
65+
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
6566

6667
### `custom_notification`
6768

website/docs/r/monitor_alert_v2_event.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ description: |-
88

99
# Resource: sysdig_monitor_alert_v2_event
1010

11-
Creates a Sysdig Monitor Event Alert. Monitor occurrences of specific events, and alert if the total
12-
number of occurrences violates a threshold. Useful for alerting on container, orchestration, and
11+
Creates a Sysdig Monitor Event Alert. Monitor occurrences of specific events, and alert if the total
12+
number of occurrences violates a threshold. Useful for alerting on container, orchestration, and
1313
service events like restarts and deployments.
1414

1515
-> **Note:** Sysdig Terraform Provider is under rapid development at this point. If you experience any issue or discrepancy while using it, please make sure you have the latest version. If the issue persists, or you have a Feature Request to support an additional set of resources, please open a [new issue](https://github.com/sysdiglabs/terraform-provider-sysdig/issues/new) in the GitHub repository.
@@ -69,13 +69,14 @@ These arguments are common to all alerts in Sysdig Monitor.
6969

7070
### `notification_channels`
7171

72-
By defining this field, the user can choose to which notification channels send the events when the alert fires.
72+
By defining this field, the user can choose to which notification channels send the events when the alert fires.
7373

7474
It is a list of objects with the following fields:
7575
* `id` - (Required) The ID of the notification channel.
76-
* `renotify_every_minutes`: (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
77-
* `main_threshold`: (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
78-
* `warning_threshold`: (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
76+
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
77+
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
78+
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
79+
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
7980

8081
### `custom_notification`
8182

website/docs/r/monitor_alert_v2_metric.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ These arguments are common to all alerts in Sysdig Monitor.
6767

6868
### `notification_channels`
6969

70-
By defining this field, the user can choose to which notification channels send the events when the alert fires.
70+
By defining this field, the user can choose to which notification channels send the events when the alert fires.
7171

7272
It is a list of objects with the following fields:
7373
* `id` - (Required) The ID of the notification channel.
74-
* `renotify_every_minutes`: (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
75-
* `main_threshold`: (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
76-
* `warning_threshold`: (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
74+
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled. Default: `0`.
75+
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
76+
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
77+
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
7778

7879
### `custom_notification`
7980

website/docs/r/monitor_alert_v2_prometheus.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ These arguments are common to all alerts in Sysdig Monitor.
4444
* `custom_notification` - (Optional) Allows to define a custom notification title, prepend and append text.
4545
* `link` - (Optional) List of links to add to notifications.
4646

47-
### `notification_channels` -
47+
### `notification_channels` -
4848

49-
By defining this field, the user can choose to which notification channels send the events when the alert fires.
49+
By defining this field, the user can choose to which notification channels send the events when the alert fires.
5050

5151
It is a list of objects with the following fields:
5252
* `id` - (Required) The ID of the notification channel.
53-
* `renotify_every_minutes`: (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled.
53+
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotifiacation enabled.
54+
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
5455

5556
### `custom_notification`
5657

0 commit comments

Comments
 (0)