2021-08-27 11:34:38 +02:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-05-25 23:25:02 +02:00
|
|
|
"context"
|
2021-08-27 11:34:38 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2023-03-15 07:54:51 +01:00
|
|
|
|
|
|
|
"github.com/netbirdio/netbird/version"
|
2021-08-27 11:34:38 +02:00
|
|
|
)
|
|
|
|
|
2022-05-25 23:25:02 +02:00
|
|
|
// GetInfo retrieves and parses the system information
|
|
|
|
func GetInfo(ctx context.Context) *Info {
|
2021-08-27 11:34:38 +02:00
|
|
|
out := _getInfo()
|
2021-08-29 13:34:17 +02:00
|
|
|
for strings.Contains(out, "broken pipe") {
|
2021-08-27 11:34:38 +02:00
|
|
|
out = _getInfo()
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
osStr := strings.Replace(out, "\n", "", -1)
|
|
|
|
osStr = strings.Replace(osStr, "\r\n", "", -1)
|
|
|
|
osInfo := strings.Split(osStr, " ")
|
2024-02-20 09:59:56 +01:00
|
|
|
gio := &Info{Kernel: osInfo[0], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: osInfo[1]}
|
2023-04-20 16:00:22 +02:00
|
|
|
systemHostname, _ := os.Hostname()
|
|
|
|
gio.Hostname = extractDeviceName(ctx, systemHostname)
|
2023-03-15 07:54:51 +01:00
|
|
|
gio.WiretrusteeVersion = version.NetbirdVersion()
|
2022-05-25 23:25:02 +02:00
|
|
|
gio.UIVersion = extractUserAgent(ctx)
|
|
|
|
|
2021-08-27 11:34:38 +02:00
|
|
|
return gio
|
|
|
|
}
|
|
|
|
|
|
|
|
func _getInfo() string {
|
|
|
|
cmd := exec.Command("uname", "-sri")
|
|
|
|
cmd.Stdin = strings.NewReader("some input")
|
|
|
|
var out bytes.Buffer
|
|
|
|
var stderr bytes.Buffer
|
|
|
|
cmd.Stdout = &out
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
err := cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("getInfo:", err)
|
|
|
|
}
|
|
|
|
return out.String()
|
|
|
|
}
|