Skip to content

Commit

Permalink
Merge pull request #60 from netdata/fix/notification-rsc
Browse files Browse the repository at this point in the history
fix: rename attribute in the notification channels
  • Loading branch information
witalisoft authored Feb 7, 2025
2 parents f481ae4 + 557bf44 commit b77629c
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 72 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.4.0

BREAKING CHANGES:

- resource/netdata_notification_discord_channel: renamed attribute from `alarms` to `notifications` with new values
- resource/netdata_notification_pagerduty_channel: renamed attribute from `alarms` to `notifications` with new values
- resource/netdata_notification_slack_channel: renamed attribute from `alarms` to `notifications` with new values

## 0.3.0

FEATURES:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/node_room_member.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resource "netdata_node_room_member" "test" {

Required:

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

Optional:

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/notification_discord_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ resource "netdata_notification_discord_channel" "test" {

### Required

- `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`
- `channel_type` (String) Discord channel type. Valid values are: `text`, `forum`
- `enabled` (Boolean) The enabled status of the Discord notification
- `name` (String) The name of the Discord notification
- `notifications` (List of String) The notification options for the Discord. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
- `space_id` (String) The ID of the space for the Discord notification
- `webhook_url` (String, Sensitive) Discord webhook URL

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/notification_pagerduty_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ resource "netdata_notification_pagerduty_channel" "test" {

### Required

- `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`
- `alert_events_url` (String) URL for alert events
- `enabled` (Boolean) The enabled status of the Pagerduty notification
- `integration_key` (String, Sensitive) Integration key
- `name` (String) The name of the Pagerduty notification
- `notifications` (List of String) The notification options for the Pagerduty. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
- `space_id` (String) The ID of the space for the Pagerduty notification

### Optional
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/notification_slack_channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ resource "netdata_notification_slack_channel" "test" {

### Required

- `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`
- `enabled` (Boolean) The enabled status of the Slack notification
- `name` (String) The name of the Slack notification
- `notifications` (List of String) The notification options for the Slack. Valid values are: `CRITICAL`, `WARNING`, `CLEAR`, `REACHABLE`, `UNREACHABLE`
- `space_id` (String) The ID of the space for the Slack notification
- `webhook_url` (String, Sensitive) Slack webhook URL

Expand Down
4 changes: 2 additions & 2 deletions internal/client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type NotificationChannel struct {
Enabled bool `json:"enabled"`
Name string `json:"name"`
Integration NotificationIntegration `json:"integration"`
Alarms string `json:"alarms"`
NotificationOptions []string `json:"notification_options"`
Rooms []string `json:"rooms"`
Secrets json.RawMessage `json:"secrets"`
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`
Expand Down Expand Up @@ -68,7 +68,7 @@ type NotificationPagerdutyChannel struct {
type notificationRequestPayload struct {
Name string `json:"name"`
IntegrationID string `json:"integrationID"`
Alarms string `json:"alarms"`
NotificationOptions []string `json:"notification_options"`
Rooms []string `json:"rooms"`
Secrets json.RawMessage `json:"secrets"`
RepeatNotificationMinute int64 `json:"repeat_notification_min,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions internal/client/notification_discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Client) CreateDiscordChannel(spaceID string, commonParams NotificationC
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func (c *Client) UpdateDiscordChannelByID(spaceID string, commonParams Notificat
reqBody := notificationRequestPayload{
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}

Expand Down
4 changes: 2 additions & 2 deletions internal/client/notification_pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Client) CreatePagerdutyChannel(spaceID string, commonParams Notificatio
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}

Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *Client) UpdatePagerdutyChannelByID(spaceID string, commonParams Notific
reqBody := notificationRequestPayload{
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}

Expand Down
4 changes: 2 additions & 2 deletions internal/client/notification_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (c *Client) CreateSlackChannel(spaceID string, commonParams NotificationCha
Name: commonParams.Name,
IntegrationID: commonParams.Integration.ID,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *Client) UpdateSlackChannelByID(spaceID string, commonParams Notificatio
reqBody := notificationRequestPayload{
Name: commonParams.Name,
Rooms: commonParams.Rooms,
Alarms: commonParams.Alarms,
NotificationOptions: commonParams.NotificationOptions,
RepeatNotificationMinute: commonParams.RepeatNotificationMinute,
}
secretsJson, err := json.Marshal(slackParams)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/node_room_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ There are two options to add nodes to the room:
},
},
"action": schema.StringAttribute{
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.",
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.",
Required: true,
Validators: []validator.String{
stringvalidator.OneOf([]string{"INCLUDE", "EXCLUDE"}...),
Expand Down
18 changes: 12 additions & 6 deletions internal/provider/notification_discord_channel_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type discordChannelResourceModel struct {
Enabled types.Bool `tfsdk:"enabled"`
SpaceID types.String `tfsdk:"space_id"`
RoomsID types.List `tfsdk:"rooms_id"`
Alarms types.String `tfsdk:"alarms"`
NotificationOptions types.List `tfsdk:"notifications"`
RepeatNotificationMinute types.Int64 `tfsdk:"repeat_notification_min"`
WebhookURL types.String `tfsdk:"webhook_url"`
ChannelType types.String `tfsdk:"channel_type"`
Expand Down Expand Up @@ -118,11 +118,14 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
var roomsID []string
plan.RoomsID.ElementsAs(ctx, &roomsID, false)

var notificationOptions []string
plan.NotificationOptions.ElementsAs(ctx, &notificationOptions, false)

commonParams := client.NotificationChannel{
Name: plan.Name.ValueString(),
Integration: *notificationIntegration,
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
NotificationOptions: notificationOptions,
Enabled: plan.Enabled.ValueBool(),
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
}
Expand Down Expand Up @@ -152,7 +155,7 @@ func (s *discordChannelResource) Create(ctx context.Context, req resource.Create
plan.Name = types.StringValue(notificationChannel.Name)
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
plan.Alarms = types.StringValue(notificationChannel.Alarms)
plan.NotificationOptions, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.NotificationOptions)
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)

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

var notificationOptions []string
plan.NotificationOptions.ElementsAs(ctx, &notificationOptions, false)

commonParams := client.NotificationChannel{
ID: plan.ID.ValueString(),
Name: plan.Name.ValueString(),
Rooms: roomsID,
Alarms: plan.Alarms.ValueString(),
NotificationOptions: notificationOptions,
Enabled: plan.Enabled.ValueBool(),
RepeatNotificationMinute: plan.RepeatNotificationMinute.ValueInt64(),
}
Expand Down Expand Up @@ -265,7 +271,7 @@ func (s *discordChannelResource) Update(ctx context.Context, req resource.Update
plan.Name = types.StringValue(notificationChannel.Name)
plan.Enabled = types.BoolValue(notificationChannel.Enabled)
plan.RoomsID, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.Rooms)
plan.Alarms = types.StringValue(notificationChannel.Alarms)
plan.NotificationOptions, _ = types.ListValueFrom(ctx, types.StringType, notificationChannel.NotificationOptions)
plan.RepeatNotificationMinute = types.Int64Value(notificationChannel.RepeatNotificationMinute)

diags = resp.State.Set(ctx, plan)
Expand Down
17 changes: 11 additions & 6 deletions internal/provider/notification_discord_channel_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
space_id = "%s"
rooms_id = [netdata_room.test.id]
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
alarms = "ALARMS_SETTING_ALL"
notifications = ["CRITICAL","WARNING","CLEAR"]
channel_type = "text"
repeat_notification_min = 30
}
Expand All @@ -35,7 +35,9 @@ func TestAccDiscordNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CRITICAL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "WARNING"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.2", "CLEAR"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "30"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "text"),
Expand All @@ -53,7 +55,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
space_id = "%s"
rooms_id = [netdata_room.test.id]
webhook_url = "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
alarms = "ALARMS_SETTING_ALL"
notifications = ["CLEAR","CRITICAL"]
channel_type = "text"
repeat_notification_min = 60
}
Expand All @@ -64,7 +66,8 @@ func TestAccDiscordNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "true"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CLEAR"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "CRITICAL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "60"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/0000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "text"),
Expand All @@ -82,7 +85,7 @@ func TestAccDiscordNotificationResource(t *testing.T) {
space_id = "%s"
rooms_id = null
webhook_url = "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"
alarms = "ALARMS_SETTING_ALL"
notifications = ["CRITICAL","WARNING","CLEAR"]
channel_type = "forum"
channel_thread = "thread"
}
Expand All @@ -93,7 +96,9 @@ func TestAccDiscordNotificationResource(t *testing.T) {
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "enabled", "false"),
resource.TestCheckResourceAttrSet("netdata_notification_discord_channel.test", "space_id"),
resource.TestCheckNoResourceAttr("netdata_notification_discord_channel.test", "rooms_id.0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "alarms", "ALARMS_SETTING_ALL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.0", "CRITICAL"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.1", "WARNING"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "notifications.2", "CLEAR"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "repeat_notification_min", "0"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "webhook_url", "https://discord.com/api/webhooks/1000000000000/XXXXXXXXXXXXXXXXXXXXXXXX"),
resource.TestCheckResourceAttr("netdata_notification_discord_channel.test", "channel_type", "forum"),
Expand Down
Loading

0 comments on commit b77629c

Please sign in to comment.