func getCPU(client *wsman.Client) string { msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_CPUView") msg.Selectors("InstanceID", "System.Embedded.1") res, err := msg.Send() if err != nil { log.Printf("Error getting cpus: %v\n", err) return "-1" } activeCores := 0 procs := search.All(search.Tag("DCIM_CPUView", "*"), res.AllBodyElements()) for _, proc := range procs { cores := search.First(search.Tag("NumberOfEnabledCores", "*"), proc.Children()) if cores == nil { log.Println("Could not find number of enabled cores!") os.Exit(1) } count, err := strconv.Atoi(string(cores.Content)) if err != nil { log.Println("Error parsing %s into an integer\n", string(cores.Content)) os.Exit(1) } activeCores += count } return strconv.Itoa(activeCores) }
func getDisk(client *wsman.Client) string { msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_VirtualDiskView") msg.Selectors("InstanceID", "System.Embedded.1") res, err := msg.Send() if err != nil { log.Printf("Error getting disks: %v\n", err) return "-1" } vds := search.All(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements()) return strconv.Itoa(len(vds)) }
func getMemory(client *wsman.Client) string { msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_SystemView") msg.Selectors("InstanceID", "System.Embedded.1") res, err := msg.Send() if err != nil { log.Printf("Error getting memory: %v\n", err) return "-1" } n := search.First(search.Tag("SysMemTotalSize", "*"), res.AllBodyElements()) if n == nil { log.Println("Could not find total system memory") return "-1" } return string(n.Content) }
func getMAC(client *wsman.Client) string { msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_NICView") msg.Selectors("InstanceID", "System.Embedded.1") res, err := msg.Send() if err != nil { log.Printf("Error getting nics: %v\n", err) return "" } bootnic := getBootNic(client, search.All(search.Tag("DCIM_NICView", "*"), res.AllBodyElements())) if bootnic == nil { return "" } return strings.ToLower( string(search.First( search.Tag("CurrentMACAddress", "*"), bootnic.Children()).Content)) }
func getDisk(client *wsman.Client) string { msg := client.Enumerate("http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_VirtualDiskView") msg.Selectors("InstanceID", "System.Embedded.1") res, err := msg.Send() if err != nil { log.Printf("Error getting disks: %v\n", err) return "-1" } 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) }