cmd

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: Apache-2.0 Imports: 104 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STDOUT outputType = 0 + iota
	MARKDOWN
	HTML
	JSONOUTPUT
	JSONPATH
)

outputTypes enum values

View Source
const (
	PolicyEnabled  = "Enabled"
	PolicyDisabled = "Disabled"
	PolicyAudit    = "Disabled (Audit)"
	UnknownState   = "Unknown"
)

PolicyEnabled and PolicyDisabled represent the endpoint policy status

Variables

View Source
var MetricsListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all metrics",
	Run: func(cmd *cobra.Command, args []string) {
		res, err := client.Metrics.GetMetrics(nil)
		if err != nil {
			Fatalf("Cannot get metrics list: %s", err)
		}

		re, err := regexp.Compile(matchPattern)
		if err != nil {
			Fatalf("Cannot compile regex: %s", err)
		}

		metrics := make([]*models.Metric, 0, len(res.Payload))
		for _, metric := range res.Payload {
			if re.MatchString(metric.Name) {
				metrics = append(metrics, metric)
			}
		}

		if command.OutputJSON() {
			if err := command.PrintOutput(metrics); err != nil {
				os.Exit(1)
			}
			return
		}

		w := tabwriter.NewWriter(os.Stdout, 5, 0, 3, ' ', 0)

		fmt.Fprintln(w, "Metric\tLabels\tValue")
		for _, metric := range metrics {
			label := ""
			if len(metric.Labels) > 0 {
				labelArray := []string{}
				for key, value := range metric.Labels {
					labelArray = append(labelArray, fmt.Sprintf(`%s="%s"`, key, value))
				}
				label = strings.Join(labelArray, " ")
			}
			fmt.Fprintf(w, "%s\t%s\t%f\n", metric.Name, label, metric.Value)
		}
		w.Flush()
	},
}

MetricsListCmd dumps all metrics into stdout

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func Fatalf

func Fatalf(msg string, args ...interface{})

Fatalf prints the Printf formatted message to stderr and exits the program Note: os.Exit(1) is not recoverable

func TablePrinter added in v0.15.7

func TablePrinter(firstTitle, secondTitle string, data map[string][]string)

TablePrinter prints the map[string][]string, which is an usual representation of dumped BPF map, using tabwriter.

func Usagef

func Usagef(cmd *cobra.Command, msg string, args ...interface{})

Usagef prints the Printf formatted message to stderr, prints usage help and exits the program Note: os.Exit(1) is not recoverable

Types

type PolicyUpdateArgs added in v0.15.7

type PolicyUpdateArgs struct {
	// contains filtered or unexported fields
}

PolicyUpdateArgs is the parsed representation of a bpf policy {add,delete} command.

Source Files

Jump to

Keyboard shortcuts

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