convert to sydney TZ
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-23 10:57:40 +10:00
parent dedb3ad7d5
commit 128275be7b

15
main.go
View File

@@ -15,9 +15,12 @@ import (
"github.com/vmware/govmomi/vim25/types"
)
var c *govmomi.Client
var ctx context.Context
var cancel context.CancelFunc
var (
c *govmomi.Client
ctx context.Context
cancel context.CancelFunc
location *time.Location
)
func exit(err error) {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
@@ -75,7 +78,7 @@ func getEvents(eventTypes []string, begin time.Duration, end time.Duration) []ty
event := events[i].GetEvent()
returnEvents = append(returnEvents, *event)
kind := reflect.TypeOf(events[i]).Elem().Name()
fmt.Printf("%d [%s] [%s] %s\n", event.Key, event.CreatedTime.Format(time.ANSIC), kind, event.FullFormattedMessage)
fmt.Printf("%d [%s] [%s] %s\n", event.Key, event.CreatedTime.In(location).Format(time.ANSIC), kind, event.FullFormattedMessage)
}
}
@@ -87,11 +90,15 @@ func main() {
vURL := flag.String("url", "", "The URL of a vCenter server, eg https://server.domain.example/sdk")
vUser := flag.String("user", "", "The username to use when connecting to vCenter")
vPass := flag.String("password", "", "The password to use when connecting to vCenter")
vTZ := flag.String("tz", "Australia/Sydney", "The timezone to use when converting vCenter UTC times")
vInsecure := flag.Bool("insecure", true, "Allow insecure connections to vCenter")
begin := flag.Duration("b", time.Hour, "Begin time") // default BeginTime is 1h ago
end := flag.Duration("e", 0, "End time")
flag.Parse()
// So we can convert vCenter UTC to our local timezone
location, _ = time.LoadLocation(*vTZ)
u, err := url.Parse(*vURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing url %s : %s\n", *vURL, err)