Skip to content

Commit b77629c

Browse files
authored
Merge pull request #60 from netdata/fix/notification-rsc
fix: rename attribute in the notification channels
2 parents f481ae4 + 557bf44 commit b77629c

17 files changed

+112
-72
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.4.0
2+
3+
BREAKING CHANGES:
4+
5+
- resource/netdata_notification_discord_channel: renamed attribute from `alarms` to `notifications` with new values
6+
- resource/netdata_notification_pagerduty_channel: renamed attribute from `alarms` to `notifications` with new values
7+
- resource/netdata_notification_slack_channel: renamed attribute from `alarms` to `notifications` with new values
8+
19
## 0.3.0
210

311
FEATURES:

docs/resources/node_room_member.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ resource "netdata_node_room_member" "test" {
6262

6363
Required:
6464

65-
- `action` (String) Determines whether matching nodes will be included or excluded from the room. EXCLUDE action always takes precedence against INCLUDE. Valid values: INCLUDE or EXCLUDE.
65+
- `action` (String) Determines whether matching nodes will be included or excluded from the room. Valid values: INCLUDE or EXCLUDE. EXCLUDE action always takes precedence against INCLUDE.
6666

6767
Optional:
6868

docs/resources/notification_discord_channel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ resource "netdata_notification_discord_channel" "test" {
3131

3232
### Required
3333

34-
- `alarms` (String) The alarms setting to set the Discord notification. Valid values are: `ALARMS_SETTING_ALL`, `ALARMS_SETTING_CRITICAL`, `ALARMS_SETTING_ALL_BUT_UNREACHABLE`, `ALARMS_SETTING_UNREACHABLE`
3534
- `channel_type` (String) Discord channel type. Valid values are: `text`, `forum`
3635
- `enabled` (Boolean) The enabled status of the Discord notification
3736
- `name` (String) The name of the Discord notification
37+
- `notifications` (List of String) The notification options for the Discord. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
3838
- `space_id` (String) The ID of the space for the Discord notification
3939
- `webhook_url` (String, Sensitive) Discord webhook URL
4040

docs/resources/notification_pagerduty_channel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ resource "netdata_notification_pagerduty_channel" "test" {
3131

3232
### Required
3333

34-
- `alarms` (String) The alarms setting to set the Pagerduty notification. Valid values are: `ALARMS_SETTING_ALL`, `ALARMS_SETTING_CRITICAL`, `ALARMS_SETTING_ALL_BUT_UNREACHABLE`, `ALARMS_SETTING_UNREACHABLE`
3534
- `alert_events_url` (String) URL for alert events
3635
- `enabled` (Boolean) The enabled status of the Pagerduty notification
3736
- `integration_key` (String, Sensitive) Integration key
3837
- `name` (String) The name of the Pagerduty notification
38+
- `notifications` (List of String) The notification options for the Pagerduty. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
3939
- `space_id` (String) The ID of the space for the Pagerduty notification
4040

4141
### Optional

docs/resources/notification_slack_channel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ resource "netdata_notification_slack_channel" "test" {
3030

3131
### Required
3232

33-
- `alarms` (String) The alarms setting to set the Slack notification. Valid values are: `ALARMS_SETTING_ALL`, `ALARMS_SETTING_CRITICAL`, `ALARMS_SETTING_ALL_BUT_UNREACHABLE`, `ALARMS_SETTING_UNREACHABLE`
3433
- `enabled` (Boolean) The enabled status of the Slack notification
3534
- `name` (String) The name of the Slack notification
35+
- `notifications` (List of String) The notification options for the Slack. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
3636
- `space_id` (String) The ID of the space for the Slack notification
3737
- `webhook_url` (String, Sensitive) Slack webhook URL
3838

internal/client/models.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type NotificationChannel struct {
3737
Enabled bool `json:"enabled"`
3838
Name string `json:"name"`
3939
Integration NotificationIntegration `json:"integration"`
40-
Alarms string `json:"alarms"`
40+
NotificationOptions []string `json:"notification_options"`
4141
Rooms []string `json:"rooms"`
4242
Secrets json.RawMessage `json:"secrets"`
4343
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`
@@ -68,7 +68,7 @@ type NotificationPagerdutyChannel struct {
6868
type notificationRequestPayload struct {
6969
Name string `json:"name"`
7070
IntegrationID string `json:"integrationID"`
71-
Alarms string `json:"alarms"`
71+
NotificationOptions []string `json:"notification_options"`
7272
Rooms []string `json:"rooms"`
7373
Secrets json.RawMessage `json:"secrets"`
7474
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`

internal/client/notification_discord.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (c *Client) CreateDiscordChannel(spaceID string, commonParams NotificationC
1717
Name: commonParams.Name,
1818
IntegrationID: commonParams.Integration.ID,
1919
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
20+
NotificationOptions: commonParams.NotificationOptions,
2121
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2222
}
2323

@@ -73,7 +73,7 @@ func (c *Client) UpdateDiscordChannelByID(spaceID string, commonParams Notificat
7373
reqBody := notificationRequestPayload{
7474
Name: commonParams.Name,
7575
Rooms: commonParams.Rooms,
76-
Alarms: commonParams.Alarms,
76+
NotificationOptions: commonParams.NotificationOptions,
7777
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7878
}
7979

internal/client/notification_pagerduty.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (c *Client) CreatePagerdutyChannel(spaceID string, commonParams Notificatio
1717
Name: commonParams.Name,
1818
IntegrationID: commonParams.Integration.ID,
1919
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
20+
NotificationOptions: commonParams.NotificationOptions,
2121
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2222
}
2323

@@ -72,7 +72,7 @@ func (c *Client) UpdatePagerdutyChannelByID(spaceID string, commonParams Notific
7272
reqBody := notificationRequestPayload{
7373
Name: commonParams.Name,
7474
Rooms: commonParams.Rooms,
75-
Alarms: commonParams.Alarms,
75+
NotificationOptions: commonParams.NotificationOptions,
7676
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7777
}
7878

internal/client/notification_slack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (c *Client) CreateSlackChannel(spaceID string, commonParams NotificationCha
1717
Name: commonParams.Name,
1818
IntegrationID: commonParams.Integration.ID,
1919
Rooms: commonParams.Rooms,
20-
Alarms: commonParams.Alarms,
20+
NotificationOptions: commonParams.NotificationOptions,
2121
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
2222
}
2323

@@ -71,7 +71,7 @@ func (c *Client) UpdateSlackChannelByID(spaceID string, commonParams Notificatio
7171
reqBody := notificationRequestPayload{
7272
Name: commonParams.Name,
7373
Rooms: commonParams.Rooms,
74-
Alarms: commonParams.Alarms,
74+
NotificationOptions: commonParams.NotificationOptions,
7575
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
7676
}
7777
secretsJson, err := json.Marshal(slackParams)

internal/provider/node_room_member.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ There are two options to add nodes to the room:
103103
},
104104
},
105105
"action": schema.StringAttribute{
106-
Description: "Determines whether matching nodes will be included or excluded from the room. EXCLUDE action always takes precedence against INCLUDE. Valid values: INCLUDE or EXCLUDE.",
106+
Description: "Determines whether matching nodes will be included or excluded from the room. Valid values: INCLUDE or EXCLUDE. EXCLUDE action always takes precedence against INCLUDE.",
107107
Required: true,
108108
Validators: []validator.String{
109109
stringvalidator.OneOf([]string{"INCLUDE", "EXCLUDE"}...),

internal/provider/notification_discord_channel_resource.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type discordChannelResourceModel struct {
3636
Enabled types.Bool `tfsdk:"enabled"`
3737
SpaceID types.String `tfsdk:"space_id"`
3838
RoomsID types.List `tfsdk:"rooms_id"`
39-
Alarms types.String `tfsdk:"alarms"`
39+
NotificationOptions types.List `tfsdk:"notifications"`
4040
RepeatNotificationMinute types.Int64 `tfsdk:"repeat_notification_min"`
4141
WebhookURL types.String `tfsdk:"webhook_url"`
4242
ChannelType types.String `tfsdk:"channel_type"`
@@ -118,11 +118,14 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
118118
var roomsID []string
119119
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
120120

121+
var notificationOptions []string
122+
plan.NotificationOptions.ElementsAs(ctx, &notificationOptions, false)
123+
121124
commonParams := client.NotificationChannel{
122125
Name: plan.Name.ValueString(),
123126
Integration: *notificationIntegration,
124127
Rooms: roomsID,
125-
Alarms: plan.Alarms.ValueString(),
128+
NotificationOptions: notificationOptions,
126129
Enabled: plan.Enabled.ValueBool(),
127130
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
128131
}
@@ -152,7 +155,7 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
152155
plan.Name = types.StringValue(notificationChannel.Name)
153156
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
154157
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
155-
plan.Alarms = types.StringValue(notificationChannel.Alarms)
158+
plan.NotificationOptions, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.NotificationOptions)
156159
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
157160

158161
diags = resp.State.Set(ctx, plan)
@@ -196,7 +199,7 @@ func (s *discordChannelResource) Read(ctx context.Context, req resource.ReadRequ
196199
state.Name = types.StringValue(notificationChannel.Name)
197200
state.Enabled = types.BoolValue(notificationChannel.Enabled)
198201
state.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
199-
state.Alarms = types.StringValue(notificationChannel.Alarms)
202+
state.NotificationOptions, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.NotificationOptions)
200203
state.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
201204
state.WebhookURL = types.StringValue(notificationSecrets.URL)
202205
state.ChannelType = types.StringValue(notificationSecrets.ChannelParams.Selection)
@@ -231,11 +234,14 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
231234
var roomsID []string
232235
plan.RoomsID.ElementsAs(ctx, &roomsID, false)
233236

237+
var notificationOptions []string
238+
plan.NotificationOptions.ElementsAs(ctx, &notificationOptions, false)
239+
234240
commonParams := client.NotificationChannel{
235241
ID: plan.ID.ValueString(),
236242
Name: plan.Name.ValueString(),
237243
Rooms: roomsID,
238-
Alarms: plan.Alarms.ValueString(),
244+
NotificationOptions: notificationOptions,
239245
Enabled: plan.Enabled.ValueBool(),
240246
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
241247
}
@@ -265,7 +271,7 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
265271
plan.Name = types.StringValue(notificationChannel.Name)
266272
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
267273
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
268-
plan.Alarms = types.StringValue(notificationChannel.Alarms)
274+
plan.NotificationOptions, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.NotificationOptions)
269275
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)
270276

271277
diags = resp.State.Set(ctx, plan)

internal/provider/notification_discord_channel_resource_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
2424
space_id = "%s"
2525
rooms_id = [netdata_room.test.id]
2626
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
27-
alarms = "ALARMS_SETTING_ALL"
27+
notifications = ["CRITICAL","WARNING","CLEAR"]
2828
channel_type = "text"
2929
repeat_notification_min = 30
3030
}
@@ -35,7 +35,9 @@ func TestAccDiscordNotificationResource(t *testing.T) {
3535
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
3636
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
3737
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
38-
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
38+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CRITICAL"),
39+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "WARNING"),
40+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.2", "CLEAR"),
3941
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "30"),
4042
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
4143
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "text"),
@@ -53,7 +55,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
5355
space_id = "%s"
5456
rooms_id = [netdata_room.test.id]
5557
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
56-
alarms = "ALARMS_SETTING_ALL"
58+
notifications = ["CLEAR","CRITICAL"]
5759
channel_type = "text"
5860
repeat_notification_min = 60
5961
}
@@ -64,7 +66,8 @@ func TestAccDiscordNotificationResource(t *testing.T) {
6466
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
6567
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
6668
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
67-
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
69+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CLEAR"),
70+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "CRITICAL"),
6871
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "60"),
6972
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
7073
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "text"),
@@ -82,7 +85,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
8285
space_id = "%s"
8386
rooms_id = null
8487
webhook_url = "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
85-
alarms = "ALARMS_SETTING_ALL"
88+
notifications = ["CRITICAL","WARNING","CLEAR"]
8689
channel_type = "forum"
8790
channel_thread = "thread"
8891
}
@@ -93,7 +96,9 @@ func TestAccDiscordNotificationResource(t *testing.T) {
9396
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "false"),
9497
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
9598
resource.TestCheckNoResourceAttr("netdata_notification_discord_channel.test", "rooms_id.0"),
96-
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
99+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CRITICAL"),
100+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "WARNING"),
101+
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.2", "CLEAR"),
97102
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "0"),
98103
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
99104
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "forum"),

0 commit comments

Comments
 (0)