@@ -88,14 +88,21 @@ func (report *Report) GetSystemDetails() {
8888
8989// This function creates a report with os details(ostype, version).
9090func (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