Skip to content

Commit f2aac20

Browse files
IvanovOlegtamilmani1989
authored andcommitted
Fixed the #108 issue. (#154)
* Fixed the #108 issue. * Added the array length check to the GetOSDetails function. * Fixed typo
1 parent 4baf30a commit f2aac20

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

telemetry/telemetry_linux.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,21 @@ func (report *Report) GetSystemDetails() {
8888

8989
// This function creates a report with os details(ostype, version).
9090
func (report *Report) GetOSDetails() {
91-
linesArr, err := ReadFileByLines("/etc/issue")
91+
linesArr, err := ReadFileByLines("/etc/os-release")
9292
if err != nil || len(linesArr) <= 0 {
9393
report.OSDetails = &OSInfo{OSType: runtime.GOOS}
94-
report.OSDetails.ErrorMessage = "reading /etc/issue failed with" + err.Error()
94+
report.OSDetails.ErrorMessage = "reading /etc/os-release failed with" + err.Error()
9595
return
9696
}
9797

98-
osInfoArr := strings.Split(linesArr[0], " ")
98+
osInfoArr := make(map[string]string)
99+
100+
for i := range linesArr {
101+
s := strings.Split(linesArr[i], "=")
102+
if len(s) == 2 {
103+
osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n")
104+
}
105+
}
99106

100107
out, err := exec.Command("uname", "-r").Output()
101108
if err != nil {
@@ -109,8 +116,8 @@ func (report *Report) GetOSDetails() {
109116

110117
report.OSDetails = &OSInfo{
111118
OSType: runtime.GOOS,
112-
OSVersion: osInfoArr[1],
119+
OSVersion: osInfoArr["VERSION"],
113120
KernelVersion: kernelVersion,
114-
OSDistribution: osInfoArr[0],
121+
OSDistribution: osInfoArr["ID"],
115122
}
116123
}

0 commit comments

Comments
 (0)