diff --git a/libmachine/crashreport/crash_report.go b/libmachine/crashreport/crash_report.go index 6a1d87c78d..0485258fc4 100644 --- a/libmachine/crashreport/crash_report.go +++ b/libmachine/crashreport/crash_report.go @@ -16,6 +16,7 @@ import ( "github.com/bugsnag/bugsnag-go" "github.com/docker/machine/commands/mcndirs" "github.com/docker/machine/libmachine/log" + "github.com/docker/machine/libmachine/mcnutils" "github.com/docker/machine/version" ) @@ -65,6 +66,7 @@ func Send(err error, context string, driverName string, command string) error { detectRunningShell(&metaData) detectUname(&metaData) + detectOSVersion(&metaData) var buffer bytes.Buffer for _, message := range log.History() { @@ -101,3 +103,7 @@ func detectUname(metaData *bugsnag.MetaData) { } metaData.Add("device", "uname", string(output)) } + +func detectOSVersion(metaData *bugsnag.MetaData) { + metaData.Add("device", "os version", mcnutils.LocalOSVersion()) +} diff --git a/libmachine/mcnutils/os_darwin.go b/libmachine/mcnutils/os_darwin.go new file mode 100644 index 0000000000..8de0bdc3d2 --- /dev/null +++ b/libmachine/mcnutils/os_darwin.go @@ -0,0 +1,12 @@ +package mcnutils + +import "os/exec" + +func LocalOSVersion() string { + command := exec.Command("bash", "-c", `sw_vers | grep ProductVersion | cut -d$'\t' -f2`) + output, err := command.Output() + if err != nil { + return "" + } + return string(output) +} diff --git a/libmachine/mcnutils/os_linux.go b/libmachine/mcnutils/os_linux.go new file mode 100644 index 0000000000..0c869f0c5e --- /dev/null +++ b/libmachine/mcnutils/os_linux.go @@ -0,0 +1,12 @@ +package mcnutils + +import "os/exec" + +func LocalOSVersion() string { + command := exec.Command("bash", "-c", `cat /etc/os-release | grep 'VERSION=' | cut -d'=' -f2`) + output, err := command.Output() + if err != nil { + return "" + } + return string(output) +} diff --git a/libmachine/mcnutils/os_windows.go b/libmachine/mcnutils/os_windows.go new file mode 100644 index 0000000000..0a838fa9de --- /dev/null +++ b/libmachine/mcnutils/os_windows.go @@ -0,0 +1,25 @@ +package mcnutils + +import ( + "os/exec" + "strings" +) + +func LocalOSVersion() string { + command := exec.Command(`systeminfo`) + output, err := command.Output() + if err != nil { + return "" + } + return parseOutput(string(output)) +} + +func parseOutput(output string) string { + lines := strings.Split(string(output), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "OS Version") { + return strings.TrimSpace(line[len("OS Version:"):]) + } + } + return "" +} diff --git a/libmachine/mcnutils/os_windows_test.go b/libmachine/mcnutils/os_windows_test.go new file mode 100644 index 0000000000..5134d289cb --- /dev/null +++ b/libmachine/mcnutils/os_windows_test.go @@ -0,0 +1,20 @@ +package mcnutils + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestOSWindows(t *testing.T) { + output := ` +Host Name: DESKTOP-3A5PULA +OS Name: Microsoft Windows 10 Enterprise +OS Version: 10.0.10240 N/A Build 10240 +OS Manufacturer: Microsoft Corporation +OS Configuration: Standalone Workstation +OS Build Type: Multiprocessor Free +Registered Owner: Windows User +` + assert.Equal(t, "10.0.10240 N/A Build 10240", parseOutput(output)) +}