diff --git a/Makefile b/Makefile index 987af22..dbe306a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ build_test: ## test only buildable CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) # Operating systems supported for building only (not implemented error if used) - GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) @echo 'Successfully built on all known operating systems' diff --git a/disk/disk_fallback.go b/disk/disk_fallback.go index db52184..ae9ffa8 100644 --- a/disk/disk_fallback.go +++ b/disk/disk_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!openbsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris package disk diff --git a/host/host_darwin.go b/host/host_darwin.go index c5b24b8..0ea6d51 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -181,8 +181,10 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err } diff --git a/host/host_fallback.go b/host/host_fallback.go index bfd0143..173f58c 100644 --- a/host/host_fallback.go +++ b/host/host_fallback.go @@ -19,3 +19,11 @@ func Uptime() (uint64, error) { func Users() ([]UserStat, error) { return []UserStat{}, common.ErrNotImplementedError } + +func Virtualization() (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + return "", common.ErrNotImplementedError +} diff --git a/host/host_freebsd.go b/host/host_freebsd.go index e7924f9..6b2962c 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -174,10 +174,7 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError } // before 9.0 @@ -222,3 +219,8 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +} diff --git a/host/host_openbsd.go b/host/host_openbsd.go index 5565bc3..13000b5 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -110,10 +110,7 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError } func Users() ([]UserStat, error) { @@ -158,3 +155,8 @@ func Users() ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +} diff --git a/host/host_solaris.go b/host/host_solaris.go index 3076f22..24461fd 100644 --- a/host/host_solaris.go +++ b/host/host_solaris.go @@ -179,3 +179,26 @@ func Users() ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func Virtualization() (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + // Parse versions from output of `uname(1)` + uname, err := exec.LookPath("/usr/bin/uname") + if err != nil { + return "", err + } + + out, err := invoke.Command(uname, "-srv") + if err != nil { + return "", err + } + + fields := strings.Fields(string(out)) + if len(fields) >= 2 { + return fields[1], nil + } + return "", fmt.Errorf("could not get kernel version") +} diff --git a/host/host_test.go b/host/host_test.go index aa0ed0f..65f7a75 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -126,3 +126,15 @@ func TestVirtualization(t *testing.T) { t.Logf("Virtualization(): %s, %s", system, role) } + +func TestKernelVersion(t *testing.T) { + version, err := KernelVersion() + if err != nil { + t.Errorf("KernelVersion() failed, %v", err) + } + if version == "" { + t.Errorf("KernelVersion() retuns empty: %s", version) + } + + t.Logf("KernelVersion(): %s", version) +} diff --git a/host/host_windows.go b/host/host_windows.go index 7e609fa..9894302 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -192,3 +192,8 @@ func SensorsTemperatures() ([]TemperatureStat, error) { func Virtualization() (string, string, error) { return "", "", common.ErrNotImplementedError } + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +}