github.com/vmware/govmomi@v0.43.0/govc/vcsa/log/forwarding.go (about) 1 /* 2 Copyright (c) 2020 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package logging 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 "io" 24 "text/tabwriter" 25 26 "github.com/vmware/govmomi/govc/cli" 27 "github.com/vmware/govmomi/govc/flags" 28 vlogging "github.com/vmware/govmomi/vapi/appliance/logging" 29 ) 30 31 type info struct { 32 *flags.ClientFlag 33 *flags.OutputFlag 34 } 35 36 func init() { 37 cli.Register("vcsa.log.forwarding.info", &info{}) 38 } 39 40 func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) { 41 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 42 cmd.ClientFlag.Register(ctx, f) 43 44 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 45 cmd.OutputFlag.Register(ctx, f) 46 } 47 48 func (cmd *info) Process(ctx context.Context) error { 49 if err := cmd.ClientFlag.Process(ctx); err != nil { 50 return err 51 } 52 if err := cmd.OutputFlag.Process(ctx); err != nil { 53 return err 54 } 55 return nil 56 } 57 58 func (cmd *info) Description() string { 59 return `Retrieve the VC Appliance log forwarding configuration 60 61 Examples: 62 govc vcsa.log.forwarding.info` 63 } 64 65 func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error { 66 c, err := cmd.RestClient() 67 if err != nil { 68 return err 69 } 70 71 fwd := vlogging.NewManager(c) 72 73 res, err := fwd.Forwarding(ctx) 74 if err != nil { 75 return nil 76 } 77 78 return cmd.WriteResult(forwardingConfigResult(res)) 79 } 80 81 type forwardingConfigResult []vlogging.Forwarding 82 83 func (res forwardingConfigResult) Write(w io.Writer) error { 84 tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0) 85 86 for _, c := range res { 87 fmt.Fprintf(tw, "Hostname:\t%s\n", c.Hostname) 88 fmt.Fprintf(tw, "Port:\t%d\n", c.Port) 89 fmt.Fprintf(tw, "Protocol:\t%s\n", c.Protocol) 90 } 91 92 return tw.Flush() 93 }