Skip to content

Commit e5e9294

Browse files
authored
Merge pull request #57 from netdata/feat/add-notification-repeat
feat: add notification repeat option
2 parents 1987cd7 + 7f7c219 commit e5e9294

19 files changed

+314
-164
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.2.2
2+
3+
FEATURES:
4+
5+
- option to specify notification repeat interval `repeat_notification_min` for the paid notification channels
6+
17
## 0.2.1
28

39
BUGFIXES:

docs/resources/notification_discord_channel.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ Resource for managing centralized notifications for Discord. Available only in p
1616
resource "netdata_notification_discord_channel" "test" {
1717
name = "discord notifications"
1818
19-
enabled = true
20-
space_id = "<space_id>"
21-
rooms_id = ["<room_id>"]
22-
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
23-
alarms = "ALARMS_SETTING_ALL"
24-
channel_type = "text"
19+
enabled = true
20+
space_id = "<space_id>"
21+
rooms_id = ["<room_id>"]
22+
repeat_notification_min = 30
23+
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
24+
alarms = "ALARMS_SETTING_ALL"
25+
channel_type = "text"
2526
}
2627
```
2728

@@ -40,6 +41,7 @@ resource "netdata_notification_discord_channel" "test" {
4041
### Optional
4142

4243
- `channel_thread` (String) Discord channel thread name required if channel type is `forum`
44+
- `repeat_notification_min` (Number) The time interval for the Discord notification to be repeated. The interval is presented in minutes and should be between 30 and 1440, or 0 to avoid repetition, which is the default.
4345
- `rooms_id` (List of String) The list of room IDs to set the Discord notification. If the rooms list is null, the Discord notification will be applied to `All rooms`
4446

4547
### Read-Only

docs/resources/notification_pagerduty_channel.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ Resource for managing centralized notifications for Pagerduty. Available only in
1616
resource "netdata_notification_pagerduty_channel" "test" {
1717
name = "pagerduty notifications"
1818
19-
enabled = true
20-
space_id = netdata_space.test.id
21-
rooms_id = ["<room_id>"]
22-
alarms = "ALARMS_SETTING_ALL"
23-
alert_events_url = "https://events.pagerduty.com/v2/enqueue"
24-
integration_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
19+
enabled = true
20+
space_id = netdata_space.test.id
21+
rooms_id = ["<room_id>"]
22+
alarms = "ALARMS_SETTING_ALL"
23+
repeat_notification_min = 30
24+
alert_events_url = "https://events.pagerduty.com/v2/enqueue"
25+
integration_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
2526
}
2627
```
2728

@@ -39,6 +40,7 @@ resource "netdata_notification_pagerduty_channel" "test" {
3940

4041
### Optional
4142

43+
- `repeat_notification_min` (Number) The time interval for the Pagerduty notification to be repeated. The interval is presented in minutes and should be between 30 and 1440, or 0 to avoid repetition, which is the default.
4244
- `rooms_id` (List of String) The list of room IDs to set the Pagerduty notification. If the rooms list is null, the Pagerduty notification will be applied to `All rooms`
4345

4446
### Read-Only

docs/resources/notification_slack_channel.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Resource for managing centralized notifications for Slack. Available only in pai
1616
resource "netdata_notification_slack_channel" "test" {
1717
name = "slack notifications"
1818
19-
enabled = true
20-
space_id = "<space_id>"
21-
rooms_id = ["<room_id>"]
22-
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
23-
alarms = "ALARMS_SETTING_ALL"
19+
enabled = true
20+
space_id = "<space_id>"
21+
rooms_id = ["<room_id>"]
22+
repeat_notification_min = 30
23+
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
24+
alarms = "ALARMS_SETTING_ALL"
2425
}
2526
```
2627

@@ -37,6 +38,7 @@ resource "netdata_notification_slack_channel" "test" {
3738

3839
### Optional
3940

41+
- `repeat_notification_min` (Number) The time interval for the Slack notification to be repeated. The interval is presented in minutes and should be between 30 and 1440, or 0 to avoid repetition, which is the default.
4042
- `rooms_id` (List of String) The list of room IDs to set the Slack notification. If the rooms list is null, the Slack notification will be applied to `All rooms`
4143

4244
### Read-Only

examples/complete/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ resource "netdata_node_room_member" "test" {
4444
resource "netdata_notification_slack_channel" "test" {
4545
name = "slack"
4646

47-
enabled = true
48-
space_id = netdata_space.test.id
49-
rooms_id = [netdata_room.test.id]
50-
alarms = "ALARMS_SETTING_ALL"
51-
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
47+
enabled = true
48+
space_id = netdata_space.test.id
49+
rooms_id = [netdata_room.test.id]
50+
alarms = "ALARMS_SETTING_ALL"
51+
repeat_notification_min = 60
52+
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
5253
}
5354

5455
resource "netdata_notification_discord_channel" "test" {
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
resource "netdata_notification_discord_channel" "test" {
22
name = "discord notifications"
33

4-
enabled = true
5-
space_id = "<space_id>"
6-
rooms_id = ["<room_id>"]
7-
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
8-
alarms = "ALARMS_SETTING_ALL"
9-
channel_type = "text"
4+
enabled = true
5+
space_id = "<space_id>"
6+
rooms_id = ["<room_id>"]
7+
repeat_notification_min = 30
8+
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
9+
alarms = "ALARMS_SETTING_ALL"
10+
channel_type = "text"
1011
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
resource "netdata_notification_pagerduty_channel" "test" {
22
name = "pagerduty notifications"
33

4-
enabled = true
5-
space_id = netdata_space.test.id
6-
rooms_id = ["<room_id>"]
7-
alarms = "ALARMS_SETTING_ALL"
8-
alert_events_url = "https://events.pagerduty.com/v2/enqueue"
9-
integration_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
4+
enabled = true
5+
space_id = netdata_space.test.id
6+
rooms_id = ["<room_id>"]
7+
alarms = "ALARMS_SETTING_ALL"
8+
repeat_notification_min = 30
9+
alert_events_url = "https://events.pagerduty.com/v2/enqueue"
10+
integration_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
1011
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
resource "netdata_notification_slack_channel" "test" {
22
name = "slack notifications"
33

4-
enabled = true
5-
space_id = "<space_id>"
6-
rooms_id = ["<room_id>"]
7-
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
8-
alarms = "ALARMS_SETTING_ALL"
4+
enabled = true
5+
space_id = "<space_id>"
6+
rooms_id = ["<room_id>"]
7+
repeat_notification_min = 30
8+
webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
9+
alarms = "ALARMS_SETTING_ALL"
910
}

internal/client/models.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ type NotificationIntegrations struct {
2929
}
3030

3131
type NotificationChannel struct {
32-
ID string `json:"id"`
33-
Enabled bool `json:"enabled"`
34-
Name string `json:"name"`
35-
Integration NotificationIntegration `json:"integration"`
36-
Alarms string `json:"alarms"`
37-
Rooms []string `json:"rooms"`
38-
Secrets json.RawMessage `json:"secrets"`
32+
ID string `json:"id"`
33+
Enabled bool `json:"enabled"`
34+
Name string `json:"name"`
35+
Integration NotificationIntegration `json:"integration"`
36+
Alarms string `json:"alarms"`
37+
Rooms []string `json:"rooms"`
38+
Secrets json.RawMessage `json:"secrets"`
39+
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`
3940
}
4041

4142
type NotificationIntegration struct {
@@ -61,11 +62,12 @@ type NotificationPagerdutyChannel struct {
6162
}
6263

6364
type notificationRequestPayload struct {
64-
Name string `json:"name"`
65-
IntegrationID string `json:"integrationID"`
66-
Alarms string `json:"alarms"`
67-
Rooms []string `json:"rooms"`
68-
Secrets json.RawMessage `json:"secrets"`
65+
Name string `json:"name"`
66+
IntegrationID string `json:"integrationID"`
67+
Alarms string `json:"alarms"`
68+
Rooms []string `json:"rooms"`
69+
Secrets json.RawMessage `json:"secrets"`
70+
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`
6971
}
7072

7173
type Invitation struct {

internal/client/notification_discord.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ func (c *Client) CreateDiscordChannel(spaceID string, commonParams NotificationC
1414
}
1515

1616
reqBody := notificationRequestPayload{
17-
Name: commonParams.Name,
18-
IntegrationID: commonParams.Integration.ID,
19-
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
17+
Name: commonParams.Name,
18+
IntegrationID: commonParams.Integration.ID,
19+
Rooms: commonParams.Rooms,
20+
Alarms: commonParams.Alarms,
21+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2122
}
2223

2324
secretsJson, err := json.Marshal(discordParams)
@@ -70,9 +71,10 @@ func (c *Client) UpdateDiscordChannelByID(spaceID string, commonParams Notificat
7071
}
7172

7273
reqBody := notificationRequestPayload{
73-
Name: commonParams.Name,
74-
Rooms: commonParams.Rooms,
75-
Alarms: commonParams.Alarms,
74+
Name: commonParams.Name,
75+
Rooms: commonParams.Rooms,
76+
Alarms: commonParams.Alarms,
77+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7678
}
7779

7880
secretsJson, err := json.Marshal(discordParams)

internal/client/notification_pagerduty.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ func (c *Client) CreatePagerdutyChannel(spaceID string, commonParams Notificatio
1414
}
1515

1616
reqBody := notificationRequestPayload{
17-
Name: commonParams.Name,
18-
IntegrationID: commonParams.Integration.ID,
19-
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
17+
Name: commonParams.Name,
18+
IntegrationID: commonParams.Integration.ID,
19+
Rooms: commonParams.Rooms,
20+
Alarms: commonParams.Alarms,
21+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2122
}
2223

2324
secretsJson, err := json.Marshal(pagerdutyParams)
@@ -69,9 +70,10 @@ func (c *Client) UpdatePagerdutyChannelByID(spaceID string, commonParams Notific
6970
}
7071

7172
reqBody := notificationRequestPayload{
72-
Name: commonParams.Name,
73-
Rooms: commonParams.Rooms,
74-
Alarms: commonParams.Alarms,
73+
Name: commonParams.Name,
74+
Rooms: commonParams.Rooms,
75+
Alarms: commonParams.Alarms,
76+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7577
}
7678

7779
secretsJson, err := json.Marshal(pagerdutyParams)

internal/client/notification_slack.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ func (c *Client) CreateSlackChannel(spaceID string, commonParams NotificationCha
1414
}
1515

1616
reqBody := notificationRequestPayload{
17-
Name: commonParams.Name,
18-
IntegrationID: commonParams.Integration.ID,
19-
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
17+
Name: commonParams.Name,
18+
IntegrationID: commonParams.Integration.ID,
19+
Rooms: commonParams.Rooms,
20+
Alarms: commonParams.Alarms,
21+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2122
}
2223

2324
secretsJson, err := json.Marshal(slackParams)
@@ -68,9 +69,10 @@ func (c *Client) UpdateSlackChannelByID(spaceID string, commonParams Notificatio
6869
}
6970

7071
reqBody := notificationRequestPayload{
71-
Name: commonParams.Name,
72-
Rooms: commonParams.Rooms,
73-
Alarms: commonParams.Alarms,
72+
Name: commonParams.Name,
73+
Rooms: commonParams.Rooms,
74+
Alarms: commonParams.Alarms,
75+
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7476
}
7577
secretsJson, err := json.Marshal(slackParams)
7678
if err != nil {

internal/provider/notification_discord_channel_resource.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ type discordChannelResource struct {
3131
}
3232

3333
type discordChannelResourceModel struct {
34-
ID types.String `tfsdk:"id"`
35-
Name types.String `tfsdk:"name"`
36-
Enabled types.Bool `tfsdk:"enabled"`
37-
SpaceID types.String `tfsdk:"space_id"`
38-
RoomsID types.List `tfsdk:"rooms_id"`
39-
Alarms types.String `tfsdk:"alarms"`
40-
WebhookURL types.String `tfsdk:"webhook_url"`
41-
ChannelType types.String `tfsdk:"channel_type"`
42-
ChannelThread types.String `tfsdk:"channel_thread"`
34+
ID types.String `tfsdk:"id"`
35+
Name types.String `tfsdk:"name"`
36+
Enabled types.Bool `tfsdk:"enabled"`
37+
SpaceID types.String `tfsdk:"space_id"`
38+
RoomsID types.List `tfsdk:"rooms_id"`
39+
Alarms types.String `tfsdk:"alarms"`
40+
RepeatNotificationMinute types.Int64 `tfsdk:"repeat_notification_min"`
41+
WebhookURL types.String `tfsdk:"webhook_url"`
42+
ChannelType types.String `tfsdk:"channel_type"`
43+
ChannelThread types.String `tfsdk:"channel_thread"`
4344
}
4445

4546
func (s *discordChannelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -118,11 +119,12 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
118119
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
119120

120121
commonParams := client.NotificationChannel{
121-
Name: plan.Name.ValueString(),
122-
Integration: *notificationIntegration,
123-
Rooms: roomsID,
124-
Alarms: plan.Alarms.ValueString(),
125-
Enabled: plan.Enabled.ValueBool(),
122+
Name: plan.Name.ValueString(),
123+
Integration: *notificationIntegration,
124+
Rooms: roomsID,
125+
Alarms: plan.Alarms.ValueString(),
126+
Enabled: plan.Enabled.ValueBool(),
127+
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
126128
}
127129

128130
discordParams := client.NotificationDiscordChannel{
@@ -151,6 +153,7 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
151153
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
152154
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
153155
plan.Alarms = types.StringValue(notificationChannel.Alarms)
156+
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
154157

155158
diags = resp.State.Set(ctx, plan)
156159
resp.Diagnostics.Append(diags...)
@@ -194,6 +197,7 @@ func (s *discordChannelResource) Read(ctx context.Context, req resource.ReadRequ
194197
state.Enabled = types.BoolValue(notificationChannel.Enabled)
195198
state.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
196199
state.Alarms = types.StringValue(notificationChannel.Alarms)
200+
state.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
197201
state.WebhookURL = types.StringValue(notificationSecrets.URL)
198202
state.ChannelType = types.StringValue(notificationSecrets.ChannelParams.Selection)
199203
if notificationSecrets.ChannelParams.Selection == "forum" {
@@ -228,11 +232,12 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
228232
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
229233

230234
commonParams := client.NotificationChannel{
231-
ID: plan.ID.ValueString(),
232-
Name: plan.Name.ValueString(),
233-
Rooms: roomsID,
234-
Alarms: plan.Alarms.ValueString(),
235-
Enabled: plan.Enabled.ValueBool(),
235+
ID: plan.ID.ValueString(),
236+
Name: plan.Name.ValueString(),
237+
Rooms: roomsID,
238+
Alarms: plan.Alarms.ValueString(),
239+
Enabled: plan.Enabled.ValueBool(),
240+
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
236241
}
237242

238243
discordParams := client.NotificationDiscordChannel{
@@ -261,6 +266,7 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
261266
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
262267
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
263268
plan.Alarms = types.StringValue(notificationChannel.Alarms)
269+
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
264270

265271
diags = resp.State.Set(ctx, plan)
266272
resp.Diagnostics.Append(diags...)

0 commit comments

Comments
 (0)