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
2 changes: 2 additions & 0 deletions docs/stackit_argus_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ stackit argus instance [flags]
* [stackit argus](./stackit_argus.md) - Provides functionality for Argus
* [stackit argus instance create](./stackit_argus_instance_create.md) - Creates an Argus instance
* [stackit argus instance delete](./stackit_argus_instance_delete.md) - Deletes an Argus instance
* [stackit argus instance describe](./stackit_argus_instance_describe.md) - Shows details of an Argus instance
* [stackit argus instance list](./stackit_argus_instance_list.md) - Lists all Argus instances
* [stackit argus instance update](./stackit_argus_instance_update.md) - Updates an Argus instance

41 changes: 41 additions & 0 deletions docs/stackit_argus_instance_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## stackit argus instance describe

Shows details of an Argus instance

### Synopsis

Shows details of an Argus instance.

```
stackit argus instance describe INSTANCE_ID [flags]
```

### Examples

```
Get details of an Argus instance with ID "xxx"
$ stackit argus instance describe xxx

Get details of an Argus instance with ID "xxx" in a table format
$ stackit argus instance describe xxx --output-format pretty
```

### Options

```
-h, --help Help for "stackit argus instance describe"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit argus instance](./stackit_argus_instance.md) - Provides functionality for Argus instances

45 changes: 45 additions & 0 deletions docs/stackit_argus_instance_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## stackit argus instance list

Lists all Argus instances

### Synopsis

Lists all Argus instances.

```
stackit argus instance list [flags]
```

### Examples

```
List all Argus instances
$ stackit argus instance list

List all Argus instances in JSON format
$ stackit argus instance list --output-format json

List up to 10 Argus instances
$ stackit argus instance list --limit 10
```

### Options

```
-h, --help Help for "stackit argus instance list"
--limit int Maximum number of entries to list
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit argus instance](./stackit_argus_instance.md) - Provides functionality for Argus instances

127 changes: 127 additions & 0 deletions internal/cmd/argus/instance/describe/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package describe

import (
"context"
"encoding/json"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/argus"
)

const (
instanceIdArg = "INSTANCE_ID"
)

type inputModel struct {
*globalflags.GlobalFlagModel
InstanceId string
}

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", instanceIdArg),
Short: "Shows details of an Argus instance",
Long: "Shows details of an Argus instance.",
Args: args.SingleArg(instanceIdArg, utils.ValidateUUID),
Example: examples.Build(
examples.NewExample(
`Get details of an Argus instance with ID "xxx"`,
"$ stackit argus instance describe xxx"),
examples.NewExample(
`Get details of an Argus instance with ID "xxx" in a table format`,
"$ stackit argus instance describe xxx --output-format pretty"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
model, err := parseInput(cmd, args)
if err != nil {
return err
}
// Configure API client
apiClient, err := client.ConfigureClient(cmd)
if err != nil {
return err
}

// Call API
req := buildRequest(ctx, model, apiClient)
resp, err := req.Execute()
if err != nil {
return fmt.Errorf("read Argus instance: %w", err)
}

return outputResult(cmd, model.OutputFormat, resp)
},
}
return cmd
}

func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
instanceId := inputArgs[0]

globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, &errors.ProjectIdError{}
}

return &inputModel{
GlobalFlagModel: globalFlags,
InstanceId: instanceId,
}, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APIClient) argus.ApiGetInstanceRequest {
req := apiClient.GetInstance(ctx, model.InstanceId, model.ProjectId)
return req
}

func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetInstanceResponse) error {
switch outputFormat {
case globalflags.PrettyOutputFormat:

table := tables.NewTable()
table.AddRow("ID", *instance.Id)
table.AddSeparator()
table.AddRow("NAME", *instance.Name)
table.AddSeparator()
table.AddRow("STATUS", *instance.Status)
table.AddSeparator()
table.AddRow("PLAN NAME", *instance.PlanName)
table.AddSeparator()
table.AddRow("METRIC SAMPLES (PER MIN)", *instance.Instance.Plan.TotalMetricSamples)
table.AddSeparator()
table.AddRow("LOGS (GB)", *instance.Instance.Plan.LogsStorage)
table.AddSeparator()
table.AddRow("TRACES (GB)", *instance.Instance.Plan.TracesStorage)
table.AddSeparator()
table.AddRow("NOTIFICATION RULES", *instance.Instance.Plan.AlertRules)
table.AddSeparator()
table.AddRow("GRAFANA USERS", *instance.Instance.Plan.GrafanaGlobalUsers)
table.AddSeparator()
table.AddRow("GRAFANA URL", *instance.Instance.GrafanaUrl)
table.AddSeparator()
err := table.Display(cmd)
if err != nil {
return fmt.Errorf("render table: %w", err)
}

return nil
default:
details, err := json.MarshalIndent(instance, "", " ")
if err != nil {
return fmt.Errorf("marshal Argus instance: %w", err)
}
cmd.Println(string(details))

return nil
}
}
Loading