Commit 37374f9a authored by Onkar Sutar's avatar Onkar Sutar
Browse files

OS info related changes

parent c0c8894a
Branches
No related merge requests found
Showing with 18 additions and 9 deletions
......@@ -5,6 +5,7 @@ import (
"errors"
"os/exec"
"regexp"
"runtime"
"strconv"
"strings"
"time"
......@@ -78,12 +79,16 @@ type DiskStats struct {
// AnalyseDisk analyses the all disks and returns serial number of disk and path, total space, free space, used space, percentage of each drive
func AnalyseDisk() (UsageStat, error) {
UsageStatobj := UsageStat{}
os := ""
osInfo, err := host.Info()
if err != nil {
logginghelper.LogError("error occured while getting OS details", err)
return UsageStatobj, err
// return UsageStatobj, err
os = runtime.GOOS
} else {
os = osInfo.OS
}
switch osInfo.OS {
switch os {
case "windows":
UsageStatobj.SerialNumber = gopsutil.GetDiskSerialNumber("")
diskStats, err := GetDiskDetails()
......@@ -200,12 +205,16 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e
// GetCPUPhysicalID returns CPU Physical ID or empty string
func GetCPUPhysicalID() (string, error) {
cpuPhysicalID := ""
os := ""
osInfo, err := host.Info()
if err != nil {
logginghelper.LogError("error occured while getting OS details", err)
return cpuPhysicalID, err
// return cpuPhysicalID, err
os = runtime.GOOS
} else {
os = osInfo.OS
}
switch osInfo.OS {
switch os {
case "windows":
cmd := exec.Command("wmic", "CPU", "get", "ProcessorId")
// cmd.Stdin = strings.NewReader("CPU get ProcessorId")
......
......@@ -3,8 +3,8 @@
package gopsutil
import (
"regexp"
"bytes"
"regexp"
"unsafe"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/coreospackage/logginghelper"
......@@ -197,13 +197,13 @@ func GetDiskSerialNumber(name string) string {
info, err := host.Info()
if err != nil {
logginghelper.LogError("GetDiskSerialNumber Host Info() Err : ", err)
return ""
// return ""
}
cmd := &exec.Cmd{}
if strings.Contains(info.Platform, "Windows 7") || strings.Contains(info.Platform, "Windows 10") {
cmd = exec.Command("wmic","diskdrive","get","serialnumber")
if err == nil && (strings.Contains(info.Platform, "Windows 7") || strings.Contains(info.Platform, "Windows 10")) {
cmd = exec.Command("wmic", "diskdrive", "get", "serialnumber")
} else {
cmd = exec.Command("wmic","path","win32_physicalmedia","get","SerialNumber")
cmd = exec.Command("wmic", "path", "win32_physicalmedia", "get", "SerialNumber")
}
var out bytes.Buffer
cmd.Stdout = &out
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment