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
49 changes: 49 additions & 0 deletions docs/openstatus-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,55 @@ The following flags are supported:
|-----------------------------|-----------------------------|:-------------:|:----------------------:|
| `--access-token="…"` (`-t`) | OpenStatus API Access Token | | `OPENSTATUS_API_TOKEN` |

### `notification` command (aliases: `n`)

Manage notifications.

Usage:

```bash
$ openstatus [GLOBAL FLAGS] notification [ARGUMENTS...]
```

### `notification list` subcommand

List all notifications.

> openstatus notification list
> openstatus notification list --limit 10

Usage:

```bash
$ openstatus [GLOBAL FLAGS] notification list [COMMAND FLAGS] [ARGUMENTS...]
```

The following flags are supported:

| Name | Description | Default value | Environment variables |
|-----------------------------|---------------------------------------------------|:-------------:|:----------------------:|
| `--access-token="…"` (`-t`) | OpenStatus API Access Token | | `OPENSTATUS_API_TOKEN` |
| `--limit="…"` | Maximum number of notifications to return (1-100) | `0` | *none* |

### `notification info` subcommand

Get notification details.

> openstatus notification info <NotificationID>
> openstatus notification info 12345

Usage:

```bash
$ openstatus [GLOBAL FLAGS] notification info [COMMAND FLAGS] [ARGUMENTS...]
```

The following flags are supported:

| Name | Description | Default value | Environment variables |
|-----------------------------|-----------------------------|:-------------:|:----------------------:|
| `--access-token="…"` (`-t`) | OpenStatus API Access Token | | `OPENSTATUS_API_TOKEN` |

### `run` command (aliases: `r`)

Run your uptime tests.
Expand Down
91 changes: 91 additions & 0 deletions docs/openstatus.1
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,97 @@ T}@T{
\f[CR]OPENSTATUS_API_TOKEN\f[R]
T}
.TE
.SS \f[CR]notification\f[R] command (aliases: \f[CR]n\f[R])
Manage notifications.
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] notification [ARGUMENTS...]
.EE
.SS \f[CR]notification list\f[R] subcommand
List all notifications.
.RS
.PP
openstatus notification list openstatus notification list \(enlimit 10
.RE
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] notification list [COMMAND FLAGS] [ARGUMENTS...]
.EE
.PP
The following flags are supported:
.PP
.TS
tab(@);
lw(17.1n) lw(30.0n) cw(8.8n) cw(14.1n).
T{
Name
T}@T{
Description
T}@T{
Default value
T}@T{
Environment variables
T}
_
T{
\f[CR]\-\-access\-token=\(dq\&...\(dq\f[R] (\f[CR]\-t\f[R])
T}@T{
OpenStatus API Access Token
T}@T{
T}@T{
\f[CR]OPENSTATUS_API_TOKEN\f[R]
T}
T{
\f[CR]\-\-limit=\(dq\&...\(dq\f[R]
T}@T{
Maximum number of notifications to return (1\-100)
T}@T{
\f[CR]0\f[R]
T}@T{
\f[I]none\f[R]
T}
.TE
.SS \f[CR]notification info\f[R] subcommand
Get notification details.
.RS
.PP
openstatus notification info openstatus notification info 12345
.RE
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] notification info [COMMAND FLAGS] [ARGUMENTS...]
.EE
.PP
The following flags are supported:
.PP
.TS
tab(@);
lw(20.9n) lw(20.9n) cw(10.8n) cw(17.3n).
T{
Name
T}@T{
Description
T}@T{
Default value
T}@T{
Environment variables
T}
_
T{
\f[CR]\-\-access\-token=\(dq\&...\(dq\f[R] (\f[CR]\-t\f[R])
T}@T{
OpenStatus API Access Token
T}@T{
T}@T{
\f[CR]OPENSTATUS_API_TOKEN\f[R]
T}
.TE
.SS \f[CR]run\f[R] command (aliases: \f[CR]r\f[R])
Run your uptime tests.
.RS
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/openstatusHQ/cli/internal/login"
"github.com/openstatusHQ/cli/internal/maintenance"
"github.com/openstatusHQ/cli/internal/monitors"
"github.com/openstatusHQ/cli/internal/notification"
"github.com/openstatusHQ/cli/internal/run"
"github.com/openstatusHQ/cli/internal/statuspage"
"github.com/openstatusHQ/cli/internal/statusreport"
Expand Down Expand Up @@ -71,6 +72,7 @@ https://docs.openstatus.dev | https://github.com/openstatusHQ/cli/issues/new`,
statusreport.StatusReportCmd(),
maintenance.MaintenanceCmd(),
statuspage.StatusPageCmd(),
notification.NotificationCmd(),
run.RunCmd(),
whoami.WhoamiCmd(),
login.LoginCmd(),
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ func Test_NewApp(t *testing.T) {
t.Run("Has expected commands", func(t *testing.T) {
app := cmd.NewApp()

if len(app.Commands) != 9 {
t.Errorf("Expected 9 commands, got %d", len(app.Commands))
if len(app.Commands) != 10 {
t.Errorf("Expected 10 commands, got %d", len(app.Commands))
}

expectedCommands := map[string]bool{
"monitors": false,
"status-report": false,
"maintenance": false,
"status-page": false,
"notification": false,
"run": false,
"whoami": false,
"login": false,
Expand Down
83 changes: 83 additions & 0 deletions internal/notification/notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package notification

import (
"net/http"

"buf.build/gen/go/openstatus/api/connectrpc/gosimple/openstatus/notification/v1/notificationv1connect"
notificationv1 "buf.build/gen/go/openstatus/api/protocolbuffers/go/openstatus/notification/v1"
"connectrpc.com/connect"
"github.com/openstatusHQ/cli/internal/api"
"github.com/urfave/cli/v3"
)

func NewNotificationClient(apiKey string) notificationv1connect.NotificationServiceClient {
return notificationv1connect.NewNotificationServiceClient(
api.DefaultHTTPClient,
api.ConnectBaseURL,
connect.WithInterceptors(api.NewAuthInterceptor(apiKey)),
connect.WithProtoJSON(),
)
}

func NewNotificationClientWithHTTPClient(httpClient *http.Client, apiKey string) notificationv1connect.NotificationServiceClient {
return notificationv1connect.NewNotificationServiceClient(
httpClient,
api.ConnectBaseURL,
connect.WithInterceptors(api.NewAuthInterceptor(apiKey)),
connect.WithProtoJSON(),
)
}

func providerToString(p notificationv1.NotificationProvider) string {
switch p {
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_DISCORD:
return "discord"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_EMAIL:
return "email"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_GOOGLE_CHAT:
return "google_chat"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_GRAFANA_ONCALL:
return "grafana_oncall"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_NTFY:
return "ntfy"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_PAGERDUTY:
return "pagerduty"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_OPSGENIE:
return "opsgenie"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_SLACK:
return "slack"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_SMS:
return "sms"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_TELEGRAM:
return "telegram"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_WEBHOOK:
return "webhook"
case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_WHATSAPP:
return "whatsapp"
default:
return "unknown"
}
}

func opsgenieRegionToString(r notificationv1.OpsgenieRegion) string {
switch r {
case notificationv1.OpsgenieRegion_OPSGENIE_REGION_US:
return "us"
case notificationv1.OpsgenieRegion_OPSGENIE_REGION_EU:
return "eu"
default:
return "unknown"
}
}

func NotificationCmd() *cli.Command {
return &cli.Command{
Name: "notification",
Aliases: []string{"n"},
Usage: "Manage notifications",
Commands: []*cli.Command{
GetNotificationListCmd(),
GetNotificationInfoCmd(),
},
}
}
Loading
Loading