Skip to content

Commit

Permalink
feat: add aws event bridge notification type (#455)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine Toulme <atoulme@splunk.com>
  • Loading branch information
jphilaine and atoulme authored May 31, 2024
1 parent 36d0174 commit cea297f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
37 changes: 23 additions & 14 deletions signalfx/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ import (
)

const (
BigPandaNotificationType string = "BigPanda"
EmailNotificationType string = "Email"
JiraNotificationType string = "Jira"
Office365NotificationType string = "Office365"
OpsgenieNotificationType string = "Opsgenie"
PagerDutyNotificationType string = "PagerDuty"
ServiceNowNotificationType string = "ServiceNow"
SlackNotificationType string = "Slack"
TeamNotificationType string = "Team"
TeamEmailNotificationType string = "TeamEmail"
VictorOpsNotificationType string = "VictorOps"
WebhookNotificationType string = "Webhook"
XMattersNotificationType string = "XMatters"
AmazonEventBrigeNotificationType string = "AmazonEventBridge"
BigPandaNotificationType string = "BigPanda"
EmailNotificationType string = "Email"
JiraNotificationType string = "Jira"
Office365NotificationType string = "Office365"
OpsgenieNotificationType string = "Opsgenie"
PagerDutyNotificationType string = "PagerDuty"
ServiceNowNotificationType string = "ServiceNow"
SlackNotificationType string = "Slack"
TeamNotificationType string = "Team"
TeamEmailNotificationType string = "TeamEmail"
VictorOpsNotificationType string = "VictorOps"
WebhookNotificationType string = "Webhook"
XMattersNotificationType string = "XMatters"
)

func getNotifyStringFromAPI(not *notification.Notification) (string, error) {
nt := not.Type
switch nt {
case AmazonEventBrigeNotificationType:
aeb := not.Value.(*notification.AmazonEventBrigeNotification)
return fmt.Sprintf("%s,%s", nt, aeb.CredentialId), nil
case BigPandaNotificationType:
bp := not.Value.(*notification.BigPandaNotification)
return fmt.Sprintf("%s,%s", nt, bp.CredentialId), nil
Expand Down Expand Up @@ -79,6 +83,11 @@ func getNotifications(tfNotifications []interface{}) ([]*notification.Notificati
var n interface{}

switch vars[0] {
case AmazonEventBrigeNotificationType:
n = &notification.AmazonEventBrigeNotification{
Type: vars[0],
CredentialId: vars[1],
}
case BigPandaNotificationType:
n = &notification.BigPandaNotification{
Type: vars[0],
Expand Down Expand Up @@ -175,7 +184,7 @@ func validateNotification(val interface{}, key string) (warns []string, errs []e
}

switch parts[0] {
case BigPandaNotificationType, JiraNotificationType, Office365NotificationType, ServiceNowNotificationType, PagerDutyNotificationType, TeamNotificationType, TeamEmailNotificationType, XMattersNotificationType:
case AmazonEventBrigeNotificationType, BigPandaNotificationType, JiraNotificationType, Office365NotificationType, ServiceNowNotificationType, PagerDutyNotificationType, TeamNotificationType, TeamEmailNotificationType, XMattersNotificationType:
// These are ok, but have no further validation
case EmailNotificationType:
if !strings.Contains(parts[1], "@") {
Expand Down
17 changes: 17 additions & 0 deletions signalfx/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ func TestNotifyStringFromAPI(t *testing.T) {
CredentialId: "XXX",
},
},
&notification.Notification{
Type: AmazonEventBrigeNotificationType,
Value: &notification.AmazonEventBrigeNotification{
Type: AmazonEventBrigeNotificationType,
CredentialId: "XXX",
},
},
}

expected := []string{
Expand All @@ -130,6 +137,7 @@ func TestNotifyStringFromAPI(t *testing.T) {
"ServiceNow,XXX",
"VictorOps,XXX,YYY",
"XMatters,XXX",
"AmazonEventBridge,XXX",
}

for i, v := range values {
Expand Down Expand Up @@ -163,6 +171,7 @@ func TestNotifyValidationBad(t *testing.T) {
"ServiceNow",
"VictorOps,XXX",
"XMatters",
"AmazonEventBridge",
}

for _, v := range busted {
Expand All @@ -186,6 +195,7 @@ func TestGetNotifications(t *testing.T) {
"ServiceNow,credId",
"VictorOps,credId,routingKey",
"XMatters,credId",
"AmazonEventBridge,credId",
}

expected := []*notification.Notification{
Expand Down Expand Up @@ -287,6 +297,13 @@ func TestGetNotifications(t *testing.T) {
CredentialId: "credId",
},
},
&notification.Notification{
Type: AmazonEventBrigeNotificationType,
Value: &notification.AmazonEventBrigeNotification{
Type: AmazonEventBrigeNotificationType,
CredentialId: "credId",
},
},
}
nots, err := getNotifications(values)
assert.NoError(t, err, "No error expected on notification conversion")
Expand Down

0 comments on commit cea297f

Please sign in to comment.