Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions telemetry/telemetry_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ 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], "=")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we check if split succeeds by checking the length of s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the latest commit is what you want.

if len(s) == 2 {
osInfoArr[s[0]] = strings.TrimSuffix(s[1], "\n")
}
}

out, err := exec.Command("uname", "-r").Output()
if err != nil {
Expand All @@ -109,8 +116,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"],
}
}