From b5d10d535e38f7ff3043c06befed8fe6b6fb8230 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 23 May 2023 12:22:20 +1000 Subject: [PATCH] check vcenter url for /sdk --- main.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e65dc99..95bf957 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "fmt" "net/url" "os" + "strings" "time" "github.com/vmware/govmomi" @@ -17,10 +18,12 @@ import ( ) var ( - c *govmomi.Client - ctx context.Context - cancel context.CancelFunc - location *time.Location + c *govmomi.Client + ctx context.Context + cancel context.CancelFunc + location *time.Location + sha1ver string // sha1 revision used to build the program + buildTime string // when the executable was built ) func getEvents(eventTypes []string, entities []types.ManagedObjectReference, begin time.Duration, end time.Duration) []types.Event { @@ -102,13 +105,20 @@ func main() { // So we can convert vCenter UTC to our local timezone location, _ = time.LoadLocation(*vTZ) + fmt.Printf("Starting execution. Built on %s from sha1 %s\n", buildTime, sha1ver) + u, err := url.Parse(*vURL) if err != nil { fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err) os.Exit(1) + } else { + if !strings.HasSuffix(u.Path, "/sdk") { + u.Path, _ = url.JoinPath(u.Path, "/sdk") + fmt.Printf("Updated vCenter URL to '%v'\n", u) + } } - //fmt.Printf("Connecting to vCenter %s\n", u) + fmt.Printf("Connecting to vCenter %s\n", u) u.User = url.UserPassword(*vUser, *vPass) ctx, cancel = context.WithCancel(context.Background())