github.com/vmware/govmomi@v0.51.0/cli/vcsa/log/forwarding.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package logging 6 7 import ( 8 "context" 9 "flag" 10 "fmt" 11 "io" 12 "text/tabwriter" 13 14 "github.com/vmware/govmomi/cli" 15 "github.com/vmware/govmomi/cli/flags" 16 vlogging "github.com/vmware/govmomi/vapi/appliance/logging" 17 ) 18 19 type info struct { 20 *flags.ClientFlag 21 *flags.OutputFlag 22 } 23 24 func init() { 25 cli.Register("vcsa.log.forwarding.info", &info{}) 26 } 27 28 func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) { 29 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 30 cmd.ClientFlag.Register(ctx, f) 31 32 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 33 cmd.OutputFlag.Register(ctx, f) 34 } 35 36 func (cmd *info) Process(ctx context.Context) error { 37 if err := cmd.ClientFlag.Process(ctx); err != nil { 38 return err 39 } 40 if err := cmd.OutputFlag.Process(ctx); err != nil { 41 return err 42 } 43 return nil 44 } 45 46 func (cmd *info) Description() string { 47 return `Retrieve the VC Appliance log forwarding configuration 48 49 Examples: 50 govc vcsa.log.forwarding.info` 51 } 52 53 func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error { 54 c, err := cmd.RestClient() 55 if err != nil { 56 return err 57 } 58 59 fwd := vlogging.NewManager(c) 60 61 res, err := fwd.Forwarding(ctx) 62 if err != nil { 63 return nil 64 } 65 66 return cmd.WriteResult(forwardingConfigResult(res)) 67 } 68 69 type forwardingConfigResult []vlogging.Forwarding 70 71 func (res forwardingConfigResult) Write(w io.Writer) error { 72 tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0) 73 74 for _, c := range res { 75 fmt.Fprintf(tw, "Hostname:\t%s\n", c.Hostname) 76 fmt.Fprintf(tw, "Port:\t%d\n", c.Port) 77 fmt.Fprintf(tw, "Protocol:\t%s\n", c.Protocol) 78 } 79 80 return tw.Flush() 81 }