mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-05 18:31:16 +01:00
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
//go:build !ios
|
|
// +build !ios
|
|
|
|
package system
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/netbird/version"
|
|
)
|
|
|
|
// GetInfo retrieves and parses the system information
|
|
func GetInfo(ctx context.Context) *Info {
|
|
utsname := unix.Utsname{}
|
|
err := unix.Uname(&utsname)
|
|
if err != nil {
|
|
log.Warnf("getInfo: %s", err)
|
|
}
|
|
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])
|
|
swVersion, err := exec.Command("sw_vers", "-productVersion").Output()
|
|
if err != nil {
|
|
log.Warnf("got an error while retrieving macOS version with sw_vers, error: %s. Using darwin version instead.\n", err)
|
|
swVersion = []byte(release)
|
|
}
|
|
|
|
systemHostname, _ := os.Hostname()
|
|
localAddr, macAddr := localAddresses()
|
|
gio := &Info{
|
|
Kernel: sysName,
|
|
OSVersion: strings.TrimSpace(string(swVersion)),
|
|
Core: release,
|
|
Platform: machine,
|
|
OS: sysName,
|
|
GoOS: runtime.GOOS,
|
|
CPUs: runtime.NumCPU(),
|
|
Hostname: extractDeviceName(ctx, systemHostname),
|
|
WiretrusteeVersion: version.NetbirdVersion(),
|
|
UIVersion: extractUserAgent(ctx),
|
|
LastReboot: lastReboot(),
|
|
LocalIp: localAddr,
|
|
MacAddress: macAddr,
|
|
}
|
|
return gio
|
|
}
|