Commit 40724686 authored by Sandeep S. Shewalkar's avatar Sandeep S. Shewalkar
Browse files

Diskdetails changes

wmic full path added in command
1 merge request!44Diskdetails changes
Showing with 19 additions and 8 deletions
...@@ -3,6 +3,7 @@ package diskdetailshelper ...@@ -3,6 +3,7 @@ package diskdetailshelper
import ( import (
"bytes" "bytes"
"errors" "errors"
"os"
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
...@@ -19,6 +20,8 @@ import ( ...@@ -19,6 +20,8 @@ import (
"github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/mem"
) )
const WMIC_RELATIVE_PATH = "\\System32\\wbem\\wmic"
// UsageStat struct contains serial number and disk stats // UsageStat struct contains serial number and disk stats
type UsageStat struct { type UsageStat struct {
SerialNumber string `json:"serialNumber"` SerialNumber string `json:"serialNumber"`
...@@ -127,7 +130,8 @@ func AnalyseDisk() (UsageStat, error) { ...@@ -127,7 +130,8 @@ func AnalyseDisk() (UsageStat, error) {
// GetDiskDetails returns disk details for windows OS // GetDiskDetails returns disk details for windows OS
func GetDiskDetails() ([]DiskStats, error) { func GetDiskDetails() ([]DiskStats, error) {
diskStats := []DiskStats{} diskStats := []DiskStats{}
cmd := exec.Command("wmic") windowsDirPath := os.Getenv("SYSTEMROOT")
cmd := exec.Command(windowsDirPath + WMIC_RELATIVE_PATH)
cmd.Stdin = strings.NewReader("logicaldisk get caption,drivetype,freespace,size") cmd.Stdin = strings.NewReader("logicaldisk get caption,drivetype,freespace,size")
var out bytes.Buffer var out bytes.Buffer
...@@ -205,18 +209,19 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e ...@@ -205,18 +209,19 @@ 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 := "" serverOS := ""
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 serverOS = runtime.GOOS
} else { } else {
os = osInfo.OS serverOS = osInfo.OS
} }
switch os { switch serverOS {
case "windows": case "windows":
cmd := exec.Command("wmic", "CPU", "get", "ProcessorId") windowsDirPath := os.Getenv("SYSTEMROOT")
cmd := exec.Command(windowsDirPath+WMIC_RELATIVE_PATH, "CPU", "get", "ProcessorId")
// cmd.Stdin = strings.NewReader("CPU get ProcessorId") // cmd.Stdin = strings.NewReader("CPU get ProcessorId")
var out bytes.Buffer var out bytes.Buffer
......
...@@ -4,6 +4,7 @@ package gopsutil ...@@ -4,6 +4,7 @@ package gopsutil
import ( import (
"bytes" "bytes"
"os"
"regexp" "regexp"
"unsafe" "unsafe"
...@@ -23,6 +24,8 @@ var ( ...@@ -23,6 +24,8 @@ var (
provGetVolumeInformation = Modkernel32.NewProc("GetVolumeInformationW") provGetVolumeInformation = Modkernel32.NewProc("GetVolumeInformationW")
) )
const WMIC_RELATIVE_PATH = "\\System32\\wbem\\wmic"
var ( var (
FileFileCompression = int64(16) // 0x00000010 FileFileCompression = int64(16) // 0x00000010
FileReadOnlyVolume = int64(524288) // 0x00080000 FileReadOnlyVolume = int64(524288) // 0x00080000
...@@ -197,8 +200,10 @@ func GetDiskSerialNumber(name string) string { ...@@ -197,8 +200,10 @@ func GetDiskSerialNumber(name string) string {
serialNumberArray := []string{} serialNumberArray := []string{}
serialNumberMap := make(map[string]bool) serialNumberMap := make(map[string]bool)
windowsDirPath := os.Getenv("SYSTEMROOT")
cmd1 := &exec.Cmd{} cmd1 := &exec.Cmd{}
cmd1 = exec.Command("wmic", "path", "win32_physicalmedia", "get", "SerialNumber") cmd1 = exec.Command(windowsDirPath+WMIC_RELATIVE_PATH, "path", "win32_physicalmedia", "get", "SerialNumber")
var out1 bytes.Buffer var out1 bytes.Buffer
cmd1.Stdout = &out1 cmd1.Stdout = &out1
commandError := cmd1.Run() commandError := cmd1.Run()
...@@ -217,7 +222,8 @@ func GetDiskSerialNumber(name string) string { ...@@ -217,7 +222,8 @@ func GetDiskSerialNumber(name string) string {
} }
cmd2 := &exec.Cmd{} cmd2 := &exec.Cmd{}
cmd2 = exec.Command("wmic", "diskdrive", "get", "serialnumber") cmd2 = exec.Command(windowsDirPath+WMIC_RELATIVE_PATH, "diskdrive", "get", "serialnumber")
var out2 bytes.Buffer var out2 bytes.Buffer
cmd2.Stdout = &out2 cmd2.Stdout = &out2
commandError = cmd2.Run() commandError = cmd2.Run()
......
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