Skip to content

Commit

Permalink
tctl alerts ls: encode empty array instead of null
Browse files Browse the repository at this point in the history
  • Loading branch information
zmb3 committed Jan 15, 2025
1 parent 35a0440 commit 66ff150
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions tool/tctl/common/alert_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package common

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

Expand All @@ -37,6 +37,7 @@ import (
"github.com/gravitational/teleport/lib/auth/authclient"
libclient "github.com/gravitational/teleport/lib/client"
"github.com/gravitational/teleport/lib/service/servicecfg"
"github.com/gravitational/teleport/lib/utils"
commonclient "github.com/gravitational/teleport/tool/tctl/common/client"
tctlcfg "github.com/gravitational/teleport/tool/tctl/common/config"
)
Expand Down Expand Up @@ -261,12 +262,7 @@ func calculateTTL(expiration *time.Time) time.Duration {
}

func displayAlertsJSON(alerts []types.ClusterAlert) error {
out, err := json.MarshalIndent(alerts, "", " ")
if err != nil {
return trace.Wrap(err, "failed to marshal alerts")
}
fmt.Println(string(out))
return nil
return utils.WriteJSONArray(os.Stdout, alerts)
}

func (c *AlertCommand) Create(ctx context.Context, client *authclient.Client) error {
Expand Down

0 comments on commit 66ff150

Please sign in to comment.