Skip to content
2 changes: 2 additions & 0 deletions docs/stackit_argus_scrape-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ stackit argus scrape-config [flags]
* [stackit argus](./stackit_argus.md) - Provides functionality for Argus
* [stackit argus scrape-config create](./stackit_argus_scrape-config_create.md) - Creates a scrape configuration for an Argus instance
* [stackit argus scrape-config delete](./stackit_argus_scrape-config_delete.md) - Deletes a scrape configuration from an Argus instance
* [stackit argus scrape-config describe](./stackit_argus_scrape-config_describe.md) - Shows details of a scrape configuration from an Argus instance
* [stackit argus scrape-config generate-payload](./stackit_argus_scrape-config_generate-payload.md) - Generates a payload to create/update scrape configurations for an Argus instance
* [stackit argus scrape-config list](./stackit_argus_scrape-config_list.md) - Lists all scrape configurations of an Argus instance
* [stackit argus scrape-config update](./stackit_argus_scrape-config_update.md) - Updates a scrape configuration of an Argus instance

43 changes: 43 additions & 0 deletions docs/stackit_argus_scrape-config_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## stackit argus scrape-config describe

Shows details of a scrape configuration from an Argus instance

### Synopsis

Shows details of a scrape configuration from an Argus instance.

```
stackit argus scrape-config describe JOB_NAME [flags]
```

### Examples

```
Get details of a scrape configuration with name "my-config" from Argus instance "xxx"
$ stackit argus scrape-config describe my-config --instance-id xxx

Get details of a scrape configuration with name "my-config" from Argus instance "xxx" in a table format
$ stackit argus scrape-config describe my-config --output-format pretty
```

### Options

```
-h, --help Help for "stackit argus scrape-config describe"
--instance-id string Instance ID
```

### 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
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit argus scrape-config](./stackit_argus_scrape-config.md) - Provides functionality for scrape configurations in Argus

47 changes: 47 additions & 0 deletions docs/stackit_argus_scrape-config_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## stackit argus scrape-config list

Lists all scrape configurations of an Argus instance

### Synopsis

Lists all scrape configurations of an Argus instance.

```
stackit argus scrape-config list [flags]
```

### Examples

```
List all scrape configurations of Argus instance "xxx"
$ stackit argus scrape-config list --instance-id xxx

List all scrape configurations of Argus instance "xxx" in JSON format
$ stackit argus scrape-config list --instance-id xxx --output-format json

List up to 10 scrape configurations of Argus instance "xxx"
$ stackit argus scrape-config list --instance-id xxx --limit 10
```

### Options

```
-h, --help Help for "stackit argus scrape-config list"
--instance-id string Instance ID
--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
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit argus scrape-config](./stackit_argus_scrape-config.md) - Provides functionality for scrape configurations in Argus

2 changes: 1 addition & 1 deletion internal/cmd/argus/scrape-config/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to create a scrape configuration on Argus instance %q?", instanceLabel)
prompt := fmt.Sprintf("Are you sure you want to create scrape configuration %q on Argus instance %q?", *model.Payload.JobName, instanceLabel)
err = p.PromptForConfirmation(prompt)
if err != nil {
return err
Expand Down
176 changes: 176 additions & 0 deletions internal/cmd/argus/scrape-config/describe/describe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package describe

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

"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/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"
"github.com/stackitcloud/stackit-sdk-go/services/argus"

"github.com/spf13/cobra"
)

const (
jobNameArg = "JOB_NAME"

instanceIdFlag = "instance-id"
)

type inputModel struct {
*globalflags.GlobalFlagModel
JobName string
InstanceId string
}

func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("describe %s", jobNameArg),
Short: "Shows details of a scrape configuration from an Argus instance",
Long: "Shows details of a scrape configuration from an Argus instance.",
Args: args.SingleArg(jobNameArg, nil),
Example: examples.Build(
examples.NewExample(
`Get details of a scrape configuration with name "my-config" from Argus instance "xxx"`,
"$ stackit argus scrape-config describe my-config --instance-id xxx"),
examples.NewExample(
`Get details of a scrape configuration with name "my-config" from Argus instance "xxx" in a table format`,
"$ stackit argus scrape-config describe my-config --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(p)
if err != nil {
return err
}

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

return outputResult(p, model.OutputFormat, resp.Data)
},
}
configureFlags(cmd)
return cmd
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID")

err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
cobra.CheckErr(err)
}

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

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

return &inputModel{
GlobalFlagModel: globalFlags,
JobName: jobName,
InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag),
}, nil
}

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

func outputResult(p *print.Printer, outputFormat string, config *argus.Job) error {
switch outputFormat {
case globalflags.PrettyOutputFormat:

saml2Enabled := "Enabled"
if config.Params != nil {
saml2 := (*config.Params)["saml2"]
if len(saml2) > 0 && saml2[0] == "disabled" {
saml2Enabled = "Disabled"
}
}

var targets []string
for _, target := range *config.StaticConfigs {
targetLabels := []string{}
targetLabelStr := "N/A"
if target.Labels != nil {
// make map prettier
for k, v := range *target.Labels {
targetLabels = append(targetLabels, fmt.Sprintf("%s:%s", k, v))
}
if targetLabels != nil {
targetLabelStr = strings.Join(targetLabels, ",")
}
}
targetUrlsStr := "N/A"
if target.Targets != nil {
targetUrlsStr = strings.Join(*target.Targets, ",")
}
targets = append(targets, fmt.Sprintf("labels: %s\nurls: %s", targetLabelStr, targetUrlsStr))
}

table := tables.NewTable()
table.AddRow("NAME", *config.JobName)
table.AddSeparator()
table.AddRow("METRICS PATH", *config.MetricsPath)
table.AddSeparator()
table.AddRow("SCHEME", *config.Scheme)
table.AddSeparator()
table.AddRow("SCRAPE INTERVAL", *config.ScrapeInterval)
table.AddSeparator()
table.AddRow("SCRAPE TIMEOUT", *config.ScrapeTimeout)
table.AddSeparator()
table.AddRow("SAML2", saml2Enabled)
table.AddSeparator()
if config.BasicAuth == nil {
table.AddRow("AUTHENTICATION", "None")
} else {
table.AddRow("AUTHENTICATION", "Basic Auth")
table.AddSeparator()
table.AddRow("USERNAME", *config.BasicAuth.Username)
table.AddSeparator()
table.AddRow("PASSWORD", *config.BasicAuth.Password)
}
table.AddSeparator()
for i, target := range targets {
table.AddRow(fmt.Sprintf("TARGET #%d", i+1), target)
table.AddSeparator()
}

err := table.Display(p)
if err != nil {
return fmt.Errorf("render table: %w", err)
}

return nil
default:
details, err := json.MarshalIndent(config, "", " ")
if err != nil {
return fmt.Errorf("marshal scrape configuration: %w", err)
}
p.Outputln(string(details))

return nil
}
}
Loading