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 ( ...@@ -5,6 +5,7 @@ import (
"errors" "errors"
"os/exec" "os/exec"
"regexp" "regexp"
"runtime"
"strconv" "strconv"
"strings" "strings"
"time" "time"
...@@ -78,12 +79,16 @@ type DiskStats struct { ...@@ -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 // 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) { func AnalyseDisk() (UsageStat, error) {
UsageStatobj := UsageStat{} UsageStatobj := UsageStat{}
os := ""
osInfo, err := host.Info() osInfo, err := host.Info()
if err != nil { if err != nil {
logginghelper.LogError("error occured while getting OS details", err) 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": case "windows":
UsageStatobj.SerialNumber = gopsutil.GetDiskSerialNumber("") UsageStatobj.SerialNumber = gopsutil.GetDiskSerialNumber("")
diskStats, err := GetDiskDetails() diskStats, err := GetDiskDetails()
...@@ -200,12 +205,16 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e ...@@ -200,12 +205,16 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e
// GetCPUPhysicalID returns CPU Physical ID or empty string // GetCPUPhysicalID returns CPU Physical ID or empty string
func GetCPUPhysicalID() (string, error) { func GetCPUPhysicalID() (string, error) {
cpuPhysicalID := "" cpuPhysicalID := ""
os := ""
osInfo, err := host.Info() osInfo, err := host.Info()
if err != nil { if err != nil {
logginghelper.LogError("error occured while getting OS details", err) 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": case "windows":
cmd := exec.Command("wmic", "CPU", "get", "ProcessorId") cmd := exec.Command("wmic", "CPU", "get", "ProcessorId")
// cmd.Stdin = strings.NewReader("CPU get ProcessorId") // cmd.Stdin = strings.NewReader("CPU get ProcessorId")
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
package gopsutil package gopsutil
import ( import (
"regexp"
"bytes" "bytes"
"regexp"
"unsafe" "unsafe"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/coreospackage/logginghelper" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/coreospackage/logginghelper"
...@@ -197,13 +197,13 @@ func GetDiskSerialNumber(name string) string { ...@@ -197,13 +197,13 @@ func GetDiskSerialNumber(name string) string {
info, err := host.Info() info, err := host.Info()
if err != nil { if err != nil {
logginghelper.LogError("GetDiskSerialNumber Host Info() Err : ", err) logginghelper.LogError("GetDiskSerialNumber Host Info() Err : ", err)
return "" // return ""
} }
cmd := &exec.Cmd{} cmd := &exec.Cmd{}
if strings.Contains(info.Platform, "Windows 7") || strings.Contains(info.Platform, "Windows 10") { if err == nil && (strings.Contains(info.Platform, "Windows 7") || strings.Contains(info.Platform, "Windows 10")) {
cmd = exec.Command("wmic","diskdrive","get","serialnumber") cmd = exec.Command("wmic", "diskdrive", "get", "serialnumber")
} else { } else {
cmd = exec.Command("wmic","path","win32_physicalmedia","get","SerialNumber") cmd = exec.Command("wmic", "path", "win32_physicalmedia", "get", "SerialNumber")
} }
var out bytes.Buffer var out bytes.Buffer
cmd.Stdout = &out 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