Skip to content

Commit

Permalink
feat: Add support of custom headers for Webhook notifications (#124)
Browse files Browse the repository at this point in the history
* Added support of custom headers for Webhook notifications
* Added description of the argument into docs
* Added test for notification channel webhook with additional headers
* Updated testacc for TestAccMonitorNotificationChannelWebhook

Co-authored-by: Denys Chekirda <[email protected]>
  • Loading branch information
DenysChekirda and Denys Chekirda authored Oct 5, 2021
1 parent 31a53bb commit ae298a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
19 changes: 10 additions & 9 deletions sysdig/internal/client/monitor/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ type usersListWrapper struct {
// -------- Notification Channels --------

type NotificationChannelOptions struct {
EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack
Channel string `json:"channel,omitempty"` // Type: Slack
Account string `json:"account,omitempty"` // Type: PagerDuty
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack
Channel string `json:"channel,omitempty"` // Type: Slack
Account string `json:"account,omitempty"` // Type: PagerDuty
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook

NotifyOnOk bool `json:"notifyOnOk"`
NotifyOnResolve bool `json:"notifyOnResolve"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"additional_headers": {
Type: schema.TypeMap,
Optional: true,
},
}),
}
}
Expand Down Expand Up @@ -131,6 +135,7 @@ func monitorNotificationChannelWebhookFromResourceData(d *schema.ResourceData) (

nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK
nc.Options.Url = d.Get("url").(string)
nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{})
return
}

Expand All @@ -141,5 +146,6 @@ func monitorNotificationChannelWebhookToResourceData(nc *monitor.NotificationCha
}

d.Set("url", nc.Options.Url)
d.Set("additional_headers", nc.Options.AdditionalHeaders)
return
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorNotificationChannelWebhookWithNameWithAdditionalheaders(rText()),
},
},
})
}
Expand All @@ -44,9 +47,24 @@ func monitorNotificationChannelWebhookWithName(name string) string {
resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" {
name = "Example Channel %s - Webhook"
enabled = true
url = "http://1.1.1.1:8080"
url = "https://example.com/"
notify_when_ok = false
notify_when_resolved = false
send_test_notification = false
}`, name)
}

func monitorNotificationChannelWebhookWithNameWithAdditionalheaders(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_notification_channel_webhook" "sample-webhook2" {
name = "Example Channel %s - Webhook With Additional Headers"
enabled = true
url = "https://example.com/"
notify_when_ok = false
notify_when_resolved = false
send_test_notification = false
additional_headers = {
"Webhook-Header": "TestHeader"
}
}`, name)
}
2 changes: 2 additions & 0 deletions website/docs/r/sysdig_monitor_notification_channel_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" {
* `send_test_notification` - (Optional) Send an initial test notification to check
if the notification channel is working. Default is false.

* `additional_headers` - (Optional) Key value list of custom headers.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down

0 comments on commit ae298a8

Please sign in to comment.