mirror of https://github.com/docker/docs.git
				
				
				
			Add OS Version to crash report
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
		
							parent
							
								
									5af18c9972
								
							
						
					
					
						commit
						8faaa2a51f
					
				|  | @ -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()) | ||||
| } | ||||
|  |  | |||
|  | @ -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) | ||||
| } | ||||
|  | @ -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) | ||||
| } | ||||
|  | @ -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 "" | ||||
| } | ||||
|  | @ -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)) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue