diff --git a/README.md b/README.md index 51ef76b..38f33e1 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ yields (without logging output): ], "cpu": "12", "memory": "98304", - "disk": "7", + "disk": "500", "arch": "x86_64" }, { @@ -41,7 +41,7 @@ yields (without logging output): ], "cpu": "16", "memory": "131072", - "disk": "0", + "disk": "500", "arch": "x86_64" }, { @@ -59,7 +59,7 @@ yields (without logging output): ], "cpu": "20", "memory": "98304", - "disk": "1", + "disk": "1200", "arch": "x86_64" } ] diff --git a/main.go b/main.go index afbcd30..18b05f8 100644 --- a/main.go +++ b/main.go @@ -113,8 +113,19 @@ func getDisk(client *wsman.Client) string { log.Printf("Error getting disks: %v\n", err) return "-1" } - vds := search.All(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements()) - return strconv.Itoa(len(vds)) + vd := search.First(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements()) + if vd == nil { + log.Printf("Error getting first disk information\n") + return "-1" + } + sizeBytes := search.First(search.Tag("SizeInBytes", "*"), vd.Children()) + if sizeBytes == nil { + log.Printf("Error getting first disk size\n") + return "-1" + } + count, err := strconv.Atoi(string(sizeBytes.Content)) + sizeGBytes := count / (1024 * 1024 * 1024) + return strconv.Itoa(sizeGBytes) } func getCPU(client *wsman.Client) string { @@ -152,15 +163,15 @@ func getBootNic(client *wsman.Client, nics []*dom.Element) *dom.Element { os.Exit(1) } fqdd := string(n.Content) // Only care about integrated nics - if ! strings.HasPrefix(fqdd, "NIC.Integrated.") { - log.Printf("%s is not integrated, skipping\n",fqdd) + if !strings.HasPrefix(fqdd, "NIC.Integrated.") { + log.Printf("%s is not integrated, skipping\n", fqdd) continue } - speed := search.First(search.Tag("LinkSpeed","*"),nic.Children()) + speed := search.First(search.Tag("LinkSpeed", "*"), nic.Children()) // If there is not speed setting, then the server is too old to report it. // Happily enough, that also means it is too old for 10 gig ports to be a thing. if speed != nil && string(speed.Content) != "3" { - log.Printf("%s is not a gigabit Ethernet port\n",fqdd) + log.Printf("%s is not a gigabit Ethernet port\n", fqdd) continue } fqdds = append(fqdds, fqdd)