alerts

package
v1.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlertsCmd = &cobra.Command{
	Use:          "alerts",
	Aliases:      []string{"alert", "actionitems"},
	Short:        "Show dashboard alerts",
	SilenceUsage: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		c, err := cmdutil.ClientFromCommand(cmd)
		if err != nil {
			return err
		}

		path := types.Endpoints.DashboardActionItems(c.EnvID())
		if debugAllGood {
			parsed, err := url.Parse(path)
			if err != nil {
				return fmt.Errorf("failed to parse endpoint path: %w", err)
			}
			q := parsed.Query()
			q.Set("debugAllGood", "true")
			parsed.RawQuery = q.Encode()
			path = parsed.String()
		}

		resp, err := c.Get(cmd.Context(), path)
		if err != nil {
			return fmt.Errorf("failed to get dashboard alerts: %w", err)
		}
		defer func() { _ = resp.Body.Close() }()

		var result base.ApiResponse[dashboardtypes.ActionItems]
		if err := cmdutil.DecodeJSON(resp, &result); err != nil {
			return fmt.Errorf("failed to parse response: %w", err)
		}

		if cmdutil.JSONOutputEnabled(cmd) {
			return cmdutil.PrintJSON(result.Data)
		}

		items := result.Data.Items
		if len(items) == 0 {
			output.Success("No alerts. Environment is good.")
			return nil
		}

		output.Header("Dashboard Alerts")
		headers := []string{"KIND", "COUNT", "SEVERITY"}
		rows := make([][]string, 0, len(items))
		for _, item := range items {
			rows = append(rows, []string{
				formatActionItemKind(item.Kind),
				fmt.Sprintf("%d", item.Count),
				strings.ToUpper(string(item.Severity)),
			})
		}
		output.Table(headers, rows)
		output.Info("Total: %d alert(s)", len(items))
		return nil
	},
}

AlertsCmd shows dashboard alerts/action items.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL