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"
|
2023-02-03 21:40:30 +01:00
|
|
|
"os/exec"
|
2021-08-27 11:34:38 +02:00
|
|
|
"runtime"
|
2023-02-03 21:40:30 +01:00
|
|
|
"strings"
|
2023-03-15 07:54:51 +01:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"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 {
|
2022-07-30 11:31:27 +02:00
|
|
|
utsname := unix.Utsname{}
|
|
|
|
err := unix.Uname(&utsname)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("getInfo:", err)
|
2021-08-27 11:34:38 +02:00
|
|
|
}
|
2022-07-30 11:31:27 +02:00
|
|
|
sysName := string(bytes.Split(utsname.Sysname[:], []byte{0})[0])
|
|
|
|
machine := string(bytes.Split(utsname.Machine[:], []byte{0})[0])
|
|
|
|
release := string(bytes.Split(utsname.Release[:], []byte{0})[0])
|
2023-03-15 07:54:51 +01:00
|
|
|
swVersion, err := exec.Command("sw_vers", "-productVersion").Output()
|
2023-02-03 21:40:30 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Warnf("got an error while retrieving macOS version with sw_vers, error: %s. Using darwin version instead.\n", err)
|
2023-03-15 07:54:51 +01:00
|
|
|
swVersion = []byte(release)
|
2023-02-03 21:40:30 +01:00
|
|
|
}
|
2023-03-15 07:54:51 +01:00
|
|
|
gio := &Info{Kernel: sysName, OSVersion: strings.TrimSpace(string(swVersion)), Core: release, Platform: machine, OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
|
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
|
|
|
|
}
|