Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notification channel): add new arguments to monitor slack notification channels #395

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sysdig/internal/client/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type NotificationChannelOptions struct {
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps, ibm event function
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook, Slack, google chat, prometheus alert manager, custom webhook
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook, Slack, google chat, prometheus alert manager, custom webhook, ms teams
Channel string `json:"channel,omitempty"` // Type: Slack
Account string `json:"account,omitempty"` // Type: PagerDuty
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
Expand All @@ -123,7 +123,7 @@ type NotificationChannelOptions struct {
InstanceId string `json:"instanceId,omitempty"` // Type: ibm event notification
IbmFunctionType string `json:"ibmFunctionType,omitempty"` // Type: ibm event function
CustomData map[string]interface{} `json:"customData,omitempty"` // Type: ibm function, Webhook
TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"`
TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` // Type: slack, ms teams

NotifyOnOk bool `json:"notifyOnOk"`
NotifyOnResolve bool `json:"notifyOnResolve"`
Expand Down
112 changes: 112 additions & 0 deletions sysdig/resource_sysdig_monitor_notification_channel_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,41 @@ func resourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"show_section_runbook_links": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_event_details": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_user_defined_content": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_notification_chart": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_dashboard_links": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_alert_details": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"show_section_capturing_information": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
}),
}
}
Expand Down Expand Up @@ -157,6 +192,46 @@ func monitorNotificationChannelSlackFromResourceData(d *schema.ResourceData, tea
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
nc.Options.Url = d.Get("url").(string)
nc.Options.Channel = d.Get("channel").(string)
nc.Options.TemplateConfiguration = []v2.NotificationChannelTemplateConfiguration{
{
TemplateKey: "SLACK_MONITOR_ALERT_NOTIFICATION_TEMPLATE_METADATA_v1",
TemplateConfigurationSections: []v2.NotificationChannelTemplateConfigurationSection{
{
SectionName: "MONITOR_ALERT_NOTIFICATION_HEADER",
ShouldShow: true,
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_RUNBOOK_LINKS",
ShouldShow: d.Get("show_section_runbook_links").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_EVENT_DETAILS",
ShouldShow: d.Get("show_section_event_details").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_USER_DEFINED_CONTENT",
ShouldShow: d.Get("show_section_user_defined_content").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_CHART",
ShouldShow: d.Get("show_section_notification_chart").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_DASHBOARD_LINKS",
ShouldShow: d.Get("show_section_dashboard_links").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_ALERT_DETAILS",
ShouldShow: d.Get("show_section_alert_details").(bool),
},
{
SectionName: "MONITOR_ALERT_NOTIFICATION_CAPTURING_INFORMATION",
ShouldShow: d.Get("show_section_capturing_information").(bool),
},
},
},
}

return
}

Expand All @@ -169,5 +244,42 @@ func monitorNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d
_ = d.Set("url", nc.Options.Url)
_ = d.Set("channel", nc.Options.Channel)

runbookLinks := true
eventDetails := true
userDefinedContent := true
notificationChart := true
dashboardLinks := true
alertDetails := true
capturingInformation := true

if len(nc.Options.TemplateConfiguration) == 1 {
for _, c := range nc.Options.TemplateConfiguration[0].TemplateConfigurationSections {
switch c.SectionName {
case "MONITOR_ALERT_NOTIFICATION_RUNBOOK_LINKS":
runbookLinks = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_EVENT_DETAILS":
eventDetails = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_USER_DEFINED_CONTENT":
userDefinedContent = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_CHART":
notificationChart = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_DASHBOARD_LINKS":
dashboardLinks = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_ALERT_DETAILS":
alertDetails = c.ShouldShow
case "MONITOR_ALERT_NOTIFICATION_CAPTURING_INFORMATION":
capturingInformation = c.ShouldShow
}
}
}

_ = d.Set("show_section_runbook_links", runbookLinks)
_ = d.Set("show_section_event_details", eventDetails)
_ = d.Set("show_section_user_defined_content", userDefinedContent)
_ = d.Set("show_section_notification_chart", notificationChart)
_ = d.Set("show_section_dashboard_links", dashboardLinks)
_ = d.Set("show_section_alert_details", alertDetails)
_ = d.Set("show_section_capturing_information", capturingInformation)

return
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func TestAccMonitorNotificationChannelSlack(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorNotificationChannelSlackSharedWithShowSection(rText()),
},
{
ResourceName: "sysdig_monitor_notification_channel_slack.sample-slack",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -63,3 +71,22 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
notify_when_resolved = true
}`, name)
}

func monitorNotificationChannelSlackSharedWithShowSection(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
name = "Example Channel %s - Slack"
enabled = true
url = "https://hooks.slack.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
channel = "#sysdig"
notify_when_ok = true
notify_when_resolved = true
show_section_runbook_links = false
show_section_event_details = false
show_section_user_defined_content = false
show_section_notification_chart = false
show_section_dashboard_links = false
show_section_alert_details = false
show_section_capturing_information = false
}`, name)
}
18 changes: 16 additions & 2 deletions website/docs/r/monitor_notification_channel_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {

* `url` - (Required) URL of the Slack.

* `show_section_runbook_links` - (Optional) Whether to include the runbook links section in the Slack messages. Default: true.

* `show_section_event_details` - (Optional) Whether to include the event details section in the Slack messages. Default: true.

* `show_section_user_defined_content` - (Optional) Whether to include the user defined section in the Slack messages. Default: true.

* `show_section_notification_chart` - (Optional) Whether to include the notification chart section in the Slack messages. Default: true.

* `show_section_dashboard_links` - (Optional) Whether to include the dashboard links section in the Slack messages. Default: true.

* `show_section_alert_details` - (Optional) Whether to include the alert details section in the Slack messages. Default: true.

* `show_section_capturing_information` - (Optional) Whether to include the capturing information section in the Slack messages. Default: true.

* `channel` - (Required) Channel name from this Slack.

* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true.

* `notify_when_ok` - (Optional) Send a new notification when the alert condition is
* `notify_when_ok` - (Optional) Send a new notification when the alert condition is
no longer triggered. Default is false.

* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually
* `notify_when_resolved` - (Optional) Send a new notification when the alert is manually
acknowledged by a user. Default is false.

* `send_test_notification` - (Optional) Send an initial test notification to check
Expand Down
Loading