Skip to content

Commit b2da326

Browse files
committed
fix version print to fmt.Println instead of stdlog.Println
1 parent 72f6283 commit b2da326

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

vsphere-influxdb.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ var getversion, debug, test bool
103103
var stdlog, errlog *log.Logger
104104
var version = "master"
105105

106-
107106
// Connect to the actual vCenter connection used to query data
108107
func (vcenter *VCenter) Connect() error {
109108
ctx, cancel := context.WithCancel(context.Background())
@@ -377,6 +376,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
377376
// Initialize the map that will hold the host MOR to cluster reference
378377
hostToCluster := make(map[types.ManagedObjectReference]string)
379378

379+
// Initialize the map that will hold the vDisk UUID per VM MOR to datastore reference
380+
vDiskToDatastore := make(map[types.ManagedObjectReference]map[string]string)
381+
380382
// Retrieve properties for clusters, if any
381383
if len(clusterRefs) > 0 {
382384
if debug {
@@ -452,6 +454,18 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
452454
fmt.Println(err)
453455
}
454456
vmSummary[vm.Self]["datastore"] = strings.Replace(strings.Replace(re.FindString(fmt.Sprintln(vm.Summary.Config)), "[", "", -1), "]", "", -1)
457+
458+
// List all devices to get vDisks
459+
for _, device := range vm.Config.Hardware.Device {
460+
// Hacky way to check if it's a vDisk and if it's datastore is different than the main one for VM
461+
if device.Backing.FileName != nil && device.Backing.Datastore.Name != vmSummary[vm.Self]["datastore"] {
462+
if vDiskToDatastore[vm.Self] == nil {
463+
vDiskToDatastore[vm.Self] = make(map[string]string)
464+
}
465+
vDiskToDatastore[vm.Self][device.diskObjectId] = device.Backing.Datastore.Name
466+
}
467+
}
468+
455469
if vmToCluster[vm.Self] != "" {
456470
vmSummary[vm.Self]["cluster"] = vmToCluster[vm.Self]
457471
}
@@ -813,7 +827,7 @@ func main() {
813827
flag.Parse()
814828

815829
if getversion {
816-
stdlog.Println("Version:",version)
830+
fmt.Println("Version:", version)
817831
os.Exit(0)
818832
}
819833

0 commit comments

Comments
 (0)