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
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ OpenStatus CLI is a command line interface for OpenStatus.
## Installation

```bash
brew tap openstatusHQ/cli
brew install openstatus
brew install openstatusHQ/cli/openstatus --cask
```

#### Windows
```powershell
iwr instl.sh/openstatushq/cli/windows | iex
```

#### macOS
```bash
curl -sSL instl.sh/openstatushq/cli/macos | bash
```

#### Linux
```bash
curl -sSL instl.sh/openstatushq/cli/linux | bash
```

## Development

Expand Down
2 changes: 1 addition & 1 deletion cmd/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func main() {
app := cmd.NewApp()
md, err := docs.ToTabularMarkdown(app , "openstatus")
md, err := docs.ToTabularMarkdown(app, "openstatus")
if err != nil {
panic(err)
}
Expand Down
42 changes: 12 additions & 30 deletions docs/openstatus-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,41 @@ Usage:
$ openstatus [GLOBAL FLAGS] monitors [ARGUMENTS...]
```

### `monitors create` subcommand
### `monitors apply` subcommand

Create monitors (beta).
Create or update monitors.

> openstatus monitors create [options]
> openstatus monitors apply [options]

Create the monitors defined in the openstatus.yaml file.
Creates or updates monitors according to the OpenStatus configuration file.

Usage:

```bash
$ openstatus [GLOBAL FLAGS] monitors create [COMMAND FLAGS] [ARGUMENTS...]
$ openstatus [GLOBAL FLAGS] monitors apply [COMMAND FLAGS] [ARGUMENTS...]
```

The following flags are supported:

| Name | Description | Default value | Environment variables |
|-----------------------------|-------------------------------------------------------|:-----------------:|:----------------------:|
| `--config="…"` | The configuration file containing monitor information | `openstatus.yaml` | *none* |
| `--config="…"` (`-c`) | The configuration file containing monitor information | `openstatus.yaml` | *none* |
| `--access-token="…"` (`-t`) | OpenStatus API Access Token | | `OPENSTATUS_API_TOKEN` |
| `--auto-accept` (`-y`) | Automatically accept the prompt | `false` | *none* |

### `monitors delete` subcommand

Delete a monitor.
### `monitors import` subcommand

> openstatus monitors delete [MonitorID] [options]
Import all your monitors.

Usage:

```bash
$ openstatus [GLOBAL FLAGS] monitors delete [COMMAND FLAGS] [ARGUMENTS...]
```

The following flags are supported:

| Name | Description | Default value | Environment variables |
|-----------------------------|---------------------------------|:-------------:|:----------------------:|
| `--access-token="…"` (`-t`) | OpenStatus API Access Token | | `OPENSTATUS_API_TOKEN` |
| `--auto-accept` (`-y`) | Automatically accept the prompt | `false` | *none* |

### `monitors export` subcommand

Export all your monitors.

> openstatus monitor export [options]
> openstatus monitors import [options]

Export all your monitors to YAML.
Import all your monitors from your workspace to a YAML file; it will also create a lock file to manage your monitors with 'apply'.

Usage:

```bash
$ openstatus [GLOBAL FLAGS] monitors export [COMMAND FLAGS] [ARGUMENTS...]
$ openstatus [GLOBAL FLAGS] monitors import [COMMAND FLAGS] [ARGUMENTS...]
```

The following flags are supported:
Expand All @@ -88,7 +70,7 @@ The following flags are supported:

Get a monitor information.

> openstatus monitor info [MonitorID]
> openstatus monitors info [MonitorID]

Fetch the monitor information. The monitor information includes details such as name, description, endpoint, method, frequency, locations, active status, public status, timeout, degraded after, and body. The body is truncated to 40 characters.

Expand Down
72 changes: 14 additions & 58 deletions docs/openstatus.1
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ Usage:
.EX
$ openstatus [GLOBAL FLAGS] monitors [ARGUMENTS...]
.EE
.SS \f[CR]monitors create\f[R] subcommand
Create monitors (beta).
.SS \f[CR]monitors apply\f[R] subcommand
Create or update monitors.
.RS
.PP
openstatus monitors create [options]
openstatus monitors apply [options]
.RE
.PP
Create the monitors defined in the openstatus.yaml file.
Creates or updates monitors according to the OpenStatus configuration
file.
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] monitors create [COMMAND FLAGS] [ARGUMENTS...]
$ openstatus [GLOBAL FLAGS] monitors apply [COMMAND FLAGS] [ARGUMENTS...]
.EE
.PP
The following flags are supported:
Expand All @@ -55,7 +56,7 @@ Environment variables
T}
_
T{
\f[CR]\-\-config=\(dq\&...\(dq\f[R]
\f[CR]\-\-config=\(dq\&...\(dq\f[R] (\f[CR]\-c\f[R])
T}@T{
The configuration file containing monitor information
T}@T{
Expand All @@ -81,65 +82,20 @@ T}@T{
\f[I]none\f[R]
T}
.TE
.SS \f[CR]monitors delete\f[R] subcommand
Delete a monitor.
.RS
.PP
openstatus monitors delete [MonitorID] [options]
.RE
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] monitors delete [COMMAND FLAGS] [ARGUMENTS...]
.EE
.PP
The following flags are supported:
.PP
.TS
tab(@);
lw(20.1n) lw(22.9n) cw(10.4n) cw(16.6n).
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]\-\-auto\-accept\f[R] (\f[CR]\-y\f[R])
T}@T{
Automatically accept the prompt
T}@T{
\f[CR]false\f[R]
T}@T{
\f[I]none\f[R]
T}
.TE
.SS \f[CR]monitors export\f[R] subcommand
Export all your monitors.
.SS \f[CR]monitors import\f[R] subcommand
Import all your monitors.
.RS
.PP
openstatus monitor export [options]
openstatus monitors import [options]
.RE
.PP
Export all your monitors to YAML.
Import all your monitors from your workspace to a YAML file; it will
also create a lock file to manage your monitors with `apply'.
.PP
Usage:
.IP
.EX
$ openstatus [GLOBAL FLAGS] monitors export [COMMAND FLAGS] [ARGUMENTS...]
$ openstatus [GLOBAL FLAGS] monitors import [COMMAND FLAGS] [ARGUMENTS...]
.EE
.PP
The following flags are supported:
Expand Down Expand Up @@ -179,7 +135,7 @@ T}
Get a monitor information.
.RS
.PP
openstatus monitor info [MonitorID]
openstatus monitors info [MonitorID]
.RE
.PP
Fetch the monitor information.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/knadh/koanf/maps v0.1.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlnd
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo=
github.com/knadh/koanf/maps v0.1.2/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w=
Expand Down
52 changes: 52 additions & 0 deletions internal/config/lock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package config

import (
"errors"
"os"

"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/v2"
)

type Lock struct {
Monitor Monitor `yaml:"monitor"`
ID int `yaml:"id"`
}

type MonitorsLock map[string]Lock

func ReadLockFile(filename string) (MonitorsLock, error) {

var out MonitorsLock
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
return MonitorsLock{}, nil
}

file := file.Provider(filename)
var k = koanf.New(".")

err := k.Load(file, yaml.Parser())

if err != nil {
return nil, err
}
err = k.Unmarshal("", &out)
if err != nil {
return nil, err
}

for _, value := range out {
for _, assertion := range value.Monitor.Assertions {
if assertion.Kind == Header || assertion.Kind == TextBody {
assertion.Target = assertion.Target.(string)
}
if assertion.Kind == StatusCode {
assertion.Target = assertion.Target.(int)
}
}
}

return out, nil

}
Loading