From ea1bbed761ae4172867c8a8140fce92608e6d92b Mon Sep 17 00:00:00 2001 From: IvanovOleg Date: Sat, 26 May 2018 10:25:58 +0300 Subject: [PATCH 1/3] Fixed the #108 issue. --- telemetry/telemetry_linux.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/telemetry/telemetry_linux.go b/telemetry/telemetry_linux.go index 09d2bd840d..a89743f240 100644 --- a/telemetry/telemetry_linux.go +++ b/telemetry/telemetry_linux.go @@ -88,14 +88,19 @@ func (report *Report) GetSystemDetails() { // This function creates a report with os details(ostype, version). func (report *Report) GetOSDetails() { - linesArr, err := ReadFileByLines("/etc/issue") + linesArr, err := ReadFileByLines("/etc/os-release") if err != nil || len(linesArr) <= 0 { report.OSDetails = &OSInfo{OSType: runtime.GOOS} - report.OSDetails.ErrorMessage = "reading /etc/issue failed with" + err.Error() + report.OSDetails.ErrorMessage = "reading /etc/os-release failed with" + err.Error() return } - osInfoArr := strings.Split(linesArr[0], " ") + osInfoArr := make(map[string]string) + + for i := range linesArr { + s := strings.Split(linesArr[i], "=") + osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n") + } out, err := exec.Command("uname", "-r").Output() if err != nil { @@ -109,8 +114,8 @@ func (report *Report) GetOSDetails() { report.OSDetails = &OSInfo{ OSType: runtime.GOOS, - OSVersion: osInfoArr[1], + OSVersion: osInfoArr["VERSION"], KernelVersion: kernelVersion, - OSDistribution: osInfoArr[0], + OSDistribution: osInfoArr["ID"], } } From 4d522426a7b2ccd9b3ae9348f6ce9cf7b1dbcd3d Mon Sep 17 00:00:00 2001 From: IvanovOleg Date: Fri, 1 Jun 2018 11:06:53 +0300 Subject: [PATCH 2/3] Added the array length check to the GetOSDetails function. --- telemetry/telemetry_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telemetry/telemetry_linux.go b/telemetry/telemetry_linux.go index a89743f240..c67bc6f1eb 100644 --- a/telemetry/telemetry_linux.go +++ b/telemetry/telemetry_linux.go @@ -99,7 +99,9 @@ func (report *Report) GetOSDetails() { for i := range linesArr { s := strings.Split(linesArr[i], "=") - osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n") + if len(s) = 2 { + osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n") + } } out, err := exec.Command("uname", "-r").Output() From 76badaffdec4484f4a0e6c7f0553751f66090dc6 Mon Sep 17 00:00:00 2001 From: IvanovOleg Date: Mon, 4 Jun 2018 21:59:12 +0300 Subject: [PATCH 3/3] Fixed typo --- telemetry/telemetry_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telemetry/telemetry_linux.go b/telemetry/telemetry_linux.go index c67bc6f1eb..9ea793fcbe 100644 --- a/telemetry/telemetry_linux.go +++ b/telemetry/telemetry_linux.go @@ -99,7 +99,7 @@ func (report *Report) GetOSDetails() { for i := range linesArr { s := strings.Split(linesArr[i], "=") - if len(s) = 2 { + if len(s) == 2 { osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n") } }