Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ spec:
- approve: 1
deny: 1
annotations:
teleport.dev/schedules: ['teleport-access-request-notifications']
teleport.dev/notify-services: ['teleport-access-request-notifications']
```

The `teleport.dev/schedules` annotation specifies the schedule the alert will be be created for.
The `teleport.dev/notify-services` annotation specifies the schedules the alert will be be created for.

### Create a user who will request access

Expand Down Expand Up @@ -121,7 +121,7 @@ As the Teleport user `myuser`, create an Access Request for the `editor` role:

In Opsgenie, you will see a new alert containing information about the
Access Request in either the default schedule specified when enrolling the plugin,
or in the schedules specified by `teleport.dev/schedules` annotation in the requester's role.
or in the schedules specified by `teleport.dev/notify-services` annotation in the requester's role.

### Resolve the request

Expand Down
2 changes: 1 addition & 1 deletion integrations/access/accessrequest/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (a *App) getMessageRecipients(ctx context.Context, req types.AccessRequest)
recipientSet.Add(common.Recipient{})
return recipientSet.ToSlice()
case types.PluginTypeOpsgenie:
if recipients, ok := req.GetSystemAnnotations()[types.TeleportNamespace+types.ReqAnnotationSchedulesLabel]; ok {
if recipients, ok := req.GetSystemAnnotations()[types.TeleportNamespace+types.ReqAnnotationNotifyServicesLabel]; ok {
for _, recipient := range recipients {
rec, err := a.bot.FetchRecipient(ctx, recipient)
if err != nil {
Expand Down
13 changes: 9 additions & 4 deletions integrations/access/opsgenie/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ func (b Bot) SendReviewReminders(ctx context.Context, recipients []common.Recipi

// BroadcastAccessRequestMessage creates an alert for the provided recipients (schedules)
func (b *Bot) BroadcastAccessRequestMessage(ctx context.Context, recipients []common.Recipient, reqID string, reqData pd.AccessRequestData) (data accessrequest.SentMessages, err error) {
schedules := []string{}
rawRecipients := []string{}
for _, recipient := range recipients {
schedules = append(schedules, recipient.Name)
rawRecipients = append(rawRecipients, recipient.Name)
}
schedules := []string{}
if annSchedules, ok := reqData.SystemAnnotations[types.TeleportNamespace+types.ReqAnnotationSchedulesLabel]; ok {
schedules = annSchedules
}
if len(recipients) == 0 {
if len(schedules) == 0 {
schedules = append(schedules, b.client.DefaultSchedules...)
}
opsgenieReqData := RequestData{
Expand All @@ -79,7 +83,8 @@ func (b *Bot) BroadcastAccessRequestMessage(ctx context.Context, recipients []co
Reason: reqData.ResolutionReason,
},
SystemAnnotations: types.Labels{
types.TeleportNamespace + types.ReqAnnotationSchedulesLabel: schedules,
types.TeleportNamespace + types.ReqAnnotationSchedulesLabel: schedules,
types.TeleportNamespace + types.ReqAnnotationNotifyServicesLabel: rawRecipients,
},
}
opsgenieData, err := b.client.CreateAlert(ctx, reqID, opsgenieReqData)
Expand Down
2 changes: 1 addition & 1 deletion integrations/access/opsgenie/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (og Client) CreateAlert(ctx context.Context, reqID string, reqData RequestD

func (og Client) getResponders(reqData RequestData) []Responder {
schedules := og.DefaultSchedules
if reqSchedules, ok := reqData.SystemAnnotations[types.TeleportNamespace+types.ReqAnnotationSchedulesLabel]; ok {
if reqSchedules, ok := reqData.SystemAnnotations[types.TeleportNamespace+types.ReqAnnotationNotifyServicesLabel]; ok {
Comment thread
EdwardDowling marked this conversation as resolved.
schedules = reqSchedules
}
responders := make([]Responder, 0, len(schedules))
Expand Down
2 changes: 1 addition & 1 deletion integrations/access/opsgenie/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestCreateAlert(t *testing.T) {
Roles: []string{"role1", "role2"},
RequestReason: "someReason",
SystemAnnotations: types.Labels{
types.TeleportNamespace + types.ReqAnnotationSchedulesLabel: {"responder@teleport.com"},
types.TeleportNamespace + types.ReqAnnotationNotifyServicesLabel: {"responder@teleport.com"},
},
})
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions rfd/0109-opsgenie-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ spec:
request:
roles: [someOtherRole]
annotations:
opsgenie_notify_services: ["service1", "service2"] # These are the Opsgenie services alerts will be created under
opsgenie_oncall_schedules: ["service1", "service2"] # These are the Opsgenie schedules checked during auto approval
teleport.dev/notify-services: ["service1", "service2"] # These are the Opsgenie schedules alerts will be created under
teleport.dev/schedules: ["service1", "service2"] # These are the Opsgenie schedules checked during auto approval
```

## Implementation details
Expand Down