mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat: add tool to send a test notification (#16611)
Relates to https://github.com/coder/coder/issues/16463 Adds a CLI command, and API endpoint, to trigger a test notification for administrators of a deployment.
This commit is contained in:
@ -23,6 +23,10 @@ func (r *RootCmd) notifications() *serpent.Command {
|
||||
Description: "Resume Coder notifications",
|
||||
Command: "coder notifications resume",
|
||||
},
|
||||
Example{
|
||||
Description: "Send a test notification. Administrators can use this to verify the notification target settings.",
|
||||
Command: "coder notifications test",
|
||||
},
|
||||
),
|
||||
Aliases: []string{"notification"},
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
@ -31,6 +35,7 @@ func (r *RootCmd) notifications() *serpent.Command {
|
||||
Children: []*serpent.Command{
|
||||
r.pauseNotifications(),
|
||||
r.resumeNotifications(),
|
||||
r.testNotifications(),
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
@ -83,3 +88,24 @@ func (r *RootCmd) resumeNotifications() *serpent.Command {
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (r *RootCmd) testNotifications() *serpent.Command {
|
||||
client := new(codersdk.Client)
|
||||
cmd := &serpent.Command{
|
||||
Use: "test",
|
||||
Short: "Send a test notification",
|
||||
Middleware: serpent.Chain(
|
||||
serpent.RequireNArgs(0),
|
||||
r.InitClient(client),
|
||||
),
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
if err := client.PostTestNotification(inv.Context()); err != nil {
|
||||
return xerrors.Errorf("unable to post test notification: %w", err)
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintln(inv.Stderr, "A test notification has been sent. If you don't receive the notification, check Coder's logs for any errors.")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
Reference in New Issue
Block a user