haproxy

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NetworkLbHaproxyCmd = &cobra.Command{
	Use:   "haproxy",
	Short: "HAProxy reports for network load balancer",
}
View Source
var NetworkLbHaproxyLiveCmd = &cobra.Command{
	Use:   "live",
	Short: "Get live HAProxy statistics for the network",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if err := cli.Preflight(true)(cmd, args); err != nil {
			return err
		}
		return cli.Validate(cmd,
			cli.Required("networkId"),
		)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		token := cli.TokenFromContext(cmd.Context())
		zoneId := cli.ZoneIDFromContext(cmd.Context())
		if err := cli.LoadFromCobraFlags(cmd, &lbHaproxyLiveOpts); err != nil {
			return err
		}
		httpClient := http.NewClient(token)
		resp, err := httpClient.GetHaproxyLive(zoneId, lbHaproxyLiveOpts.NetworkID)
		if err != nil {
			slog.Error("failed to get HAProxy live report", "error", err)
			return fmt.Errorf("error: %w", err)
		}
		fmt.Printf("Updated At: %d\n", resp.Data.UpdatedAt)
		if len(resp.Data.Rules) == 0 {
			fmt.Println("No HAProxy rules found.")
			return nil
		}
		fmt.Println("ID\tName\tAlgorithm\tPublicPort\tPrivatePort\tStatus")
		for _, rule := range resp.Data.Rules {
			fmt.Printf("%s\t%s\t%s\t%d\t%d\t%s\n", rule.ID, rule.Name, rule.Algorithm, rule.PublicPort, rule.PrivatePort, rule.Status)
		}
		return nil
	},
}
View Source
var NetworkLbHaproxyLogCmd = &cobra.Command{
	Use:   "log",
	Short: "Get HAProxy logs for the network",
	PreRunE: func(cmd *cobra.Command, args []string) error {
		if err := cli.Preflight(true)(cmd, args); err != nil {
			return err
		}
		return cli.Validate(cmd,
			cli.Required("networkId"),
		)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		token := cli.TokenFromContext(cmd.Context())
		zoneId := cli.ZoneIDFromContext(cmd.Context())
		if err := cli.LoadFromCobraFlags(cmd, &lbHaproxyLogOpts); err != nil {
			return err
		}
		httpClient := http.NewClient(token)
		resp, err := httpClient.GetHaproxyLog(zoneId, lbHaproxyLogOpts.NetworkID)
		if err != nil {
			slog.Error("failed to get HAProxy log report", "error", err)
			return fmt.Errorf("error: %w", err)
		}
		if len(resp.Data) == 0 {
			fmt.Println("No HAProxy logs found.")
			return nil
		}
		fmt.Println("HAProxy Logs:")
		for i, log := range resp.Data {
			fmt.Printf("%d: %v\n", i+1, log)
		}
		return nil
	},
}

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