mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-04 01:41:17 +01:00
Add static system info to other OSs
This commit is contained in:
parent
07f0f9fdbd
commit
b4b9aedf5a
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetInfo retrieves and parses the system information
|
// GetInfo retrieves and parses the system information
|
||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context, _ *StaticInfo) *Info {
|
||||||
kernel := "android"
|
kernel := "android"
|
||||||
osInfo := uname()
|
osInfo := uname()
|
||||||
if len(osInfo) == 2 {
|
if len(osInfo) == 2 {
|
||||||
@ -44,6 +44,10 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// checkFileAndProcess checks if the file path exists and if a process is running at that path.
|
// checkFileAndProcess checks if the file path exists and if a process is running at that path.
|
||||||
func checkFileAndProcess(paths []string) ([]File, error) {
|
func checkFileAndProcess(paths []string) ([]File, error) {
|
||||||
return []File{}, nil
|
return []File{}, nil
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetInfo retrieves and parses the system information
|
// GetInfo retrieves and parses the system information
|
||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info {
|
||||||
out := _getInfo()
|
out := _getInfo()
|
||||||
for strings.Contains(out, "broken pipe") {
|
for strings.Contains(out, "broken pipe") {
|
||||||
out = _getInfo()
|
out = _getInfo()
|
||||||
@ -29,16 +29,11 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
osStr = strings.ReplaceAll(osStr, "\r\n", "")
|
osStr = strings.ReplaceAll(osStr, "\r\n", "")
|
||||||
osInfo := strings.Split(osStr, " ")
|
osInfo := strings.Split(osStr, " ")
|
||||||
|
|
||||||
env := Environment{
|
|
||||||
Cloud: detect_cloud.Detect(ctx),
|
|
||||||
Platform: detect_platform.Detect(ctx),
|
|
||||||
}
|
|
||||||
|
|
||||||
osName, osVersion := readOsReleaseFile()
|
osName, osVersion := readOsReleaseFile()
|
||||||
|
|
||||||
systemHostname, _ := os.Hostname()
|
systemHostname, _ := os.Hostname()
|
||||||
|
|
||||||
return &Info{
|
info := &Info{
|
||||||
GoOS: runtime.GOOS,
|
GoOS: runtime.GOOS,
|
||||||
Kernel: osInfo[0],
|
Kernel: osInfo[0],
|
||||||
Platform: runtime.GOARCH,
|
Platform: runtime.GOARCH,
|
||||||
@ -49,7 +44,25 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
WiretrusteeVersion: version.NetbirdVersion(),
|
WiretrusteeVersion: version.NetbirdVersion(),
|
||||||
UIVersion: extractUserAgent(ctx),
|
UIVersion: extractUserAgent(ctx),
|
||||||
KernelVersion: osInfo[1],
|
KernelVersion: osInfo[1],
|
||||||
Environment: env,
|
}
|
||||||
|
if staticInfo != nil {
|
||||||
|
info.SystemSerialNumber = staticInfo.SystemSerialNumber
|
||||||
|
info.SystemProductName = staticInfo.SystemProductName
|
||||||
|
info.SystemManufacturer = staticInfo.SystemManufacturer
|
||||||
|
info.Environment = staticInfo.Environment
|
||||||
|
}
|
||||||
|
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
||||||
|
env := Environment{
|
||||||
|
Cloud: detect_cloud.Detect(ctx),
|
||||||
|
Platform: detect_platform.Detect(ctx),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StaticInfo{
|
||||||
|
Environment: env,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetInfo retrieves and parses the system information
|
// GetInfo retrieves and parses the system information
|
||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context, _ *StaticInfo) *Info {
|
||||||
|
|
||||||
// Convert fixed-size byte arrays to Go strings
|
// Convert fixed-size byte arrays to Go strings
|
||||||
sysName := extractOsName(ctx, "sysName")
|
sysName := extractOsName(ctx, "sysName")
|
||||||
@ -25,6 +25,10 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// checkFileAndProcess checks if the file path exists and if a process is running at that path.
|
// checkFileAndProcess checks if the file path exists and if a process is running at that path.
|
||||||
func checkFileAndProcess(paths []string) ([]File, error) {
|
func checkFileAndProcess(paths []string) ([]File, error) {
|
||||||
return []File{}, nil
|
return []File{}, nil
|
||||||
|
@ -42,7 +42,7 @@ func (s SysInfoWrapper) GetSysInfo() SysInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInfo retrieves and parses the system information
|
// GetInfo retrieves and parses the system information
|
||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info {
|
||||||
info := _getInfo()
|
info := _getInfo()
|
||||||
for strings.Contains(info, "broken pipe") {
|
for strings.Contains(info, "broken pipe") {
|
||||||
info = _getInfo()
|
info = _getInfo()
|
||||||
@ -65,14 +65,6 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
log.Warnf("failed to discover network addresses: %s", err)
|
log.Warnf("failed to discover network addresses: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
si := SysInfoWrapper{}
|
|
||||||
serialNum, prodName, manufacturer := sysInfo(si.GetSysInfo())
|
|
||||||
|
|
||||||
env := Environment{
|
|
||||||
Cloud: detect_cloud.Detect(ctx),
|
|
||||||
Platform: detect_platform.Detect(ctx),
|
|
||||||
}
|
|
||||||
|
|
||||||
gio := &Info{
|
gio := &Info{
|
||||||
Kernel: osInfo[0],
|
Kernel: osInfo[0],
|
||||||
Platform: osInfo[2],
|
Platform: osInfo[2],
|
||||||
@ -85,13 +77,32 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
UIVersion: extractUserAgent(ctx),
|
UIVersion: extractUserAgent(ctx),
|
||||||
KernelVersion: osInfo[1],
|
KernelVersion: osInfo[1],
|
||||||
NetworkAddresses: addrs,
|
NetworkAddresses: addrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
if staticInfo != nil {
|
||||||
|
gio.SystemSerialNumber = staticInfo.SystemSerialNumber
|
||||||
|
gio.SystemProductName = staticInfo.SystemProductName
|
||||||
|
gio.SystemManufacturer = staticInfo.SystemManufacturer
|
||||||
|
gio.Environment = staticInfo.Environment
|
||||||
|
}
|
||||||
|
|
||||||
|
return gio
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
||||||
|
si := SysInfoWrapper{}
|
||||||
|
serialNum, prodName, manufacturer := sysInfo(si.GetSysInfo())
|
||||||
|
env := Environment{
|
||||||
|
Cloud: detect_cloud.Detect(ctx),
|
||||||
|
Platform: detect_platform.Detect(ctx),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StaticInfo{
|
||||||
SystemSerialNumber: serialNum,
|
SystemSerialNumber: serialNum,
|
||||||
SystemProductName: prodName,
|
SystemProductName: prodName,
|
||||||
SystemManufacturer: manufacturer,
|
SystemManufacturer: manufacturer,
|
||||||
Environment: env,
|
Environment: env,
|
||||||
}
|
}
|
||||||
|
|
||||||
return gio
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func _getInfo() string {
|
func _getInfo() string {
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/yusufpapurcu/wmi"
|
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/system/detect_cloud"
|
"github.com/netbirdio/netbird/client/system/detect_cloud"
|
||||||
@ -33,7 +32,7 @@ type Win32_BIOS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetInfo retrieves and parses the system information
|
// GetInfo retrieves and parses the system information
|
||||||
func GetInfo(ctx context.Context) *Info {
|
func GetInfo(ctx context.Context, staticInfo *StaticInfo) *Info {
|
||||||
osName, osVersion := getOSNameAndVersion()
|
osName, osVersion := getOSNameAndVersion()
|
||||||
buildVersion := getBuildVersion()
|
buildVersion := getBuildVersion()
|
||||||
|
|
||||||
@ -42,39 +41,22 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
log.Warnf("failed to discover network addresses: %s", err)
|
log.Warnf("failed to discover network addresses: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
serialNum, err := sysNumber()
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("failed to get system serial number: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
prodName, err := sysProductName()
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("failed to get system product name: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
manufacturer, err := sysManufacturer()
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("failed to get system manufacturer: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
env := Environment{
|
|
||||||
Cloud: detect_cloud.Detect(ctx),
|
|
||||||
Platform: detect_platform.Detect(ctx),
|
|
||||||
}
|
|
||||||
|
|
||||||
gio := &Info{
|
gio := &Info{
|
||||||
Kernel: "windows",
|
Kernel: "windows",
|
||||||
OSVersion: osVersion,
|
OSVersion: osVersion,
|
||||||
Platform: "unknown",
|
Platform: "unknown",
|
||||||
OS: osName,
|
OS: osName,
|
||||||
GoOS: runtime.GOOS,
|
GoOS: runtime.GOOS,
|
||||||
CPUs: runtime.NumCPU(),
|
CPUs: runtime.NumCPU(),
|
||||||
KernelVersion: buildVersion,
|
KernelVersion: buildVersion,
|
||||||
NetworkAddresses: addrs,
|
NetworkAddresses: addrs,
|
||||||
SystemSerialNumber: serialNum,
|
}
|
||||||
SystemProductName: prodName,
|
|
||||||
SystemManufacturer: manufacturer,
|
if staticInfo != nil {
|
||||||
Environment: env,
|
gio.SystemSerialNumber = staticInfo.SystemSerialNumber
|
||||||
|
gio.SystemProductName = staticInfo.SystemProductName
|
||||||
|
gio.SystemManufacturer = staticInfo.SystemManufacturer
|
||||||
|
gio.Environment = staticInfo.Environment
|
||||||
}
|
}
|
||||||
|
|
||||||
systemHostname, _ := os.Hostname()
|
systemHostname, _ := os.Hostname()
|
||||||
@ -85,6 +67,41 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStaticInfo(ctx context.Context) *StaticInfo {
|
||||||
|
serialNum, prodName, manufacturer := sysInfo()
|
||||||
|
env := Environment{
|
||||||
|
Cloud: detect_cloud.Detect(ctx),
|
||||||
|
Platform: detect_platform.Detect(ctx),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &StaticInfo{
|
||||||
|
SystemSerialNumber: serialNum,
|
||||||
|
SystemProductName: prodName,
|
||||||
|
SystemManufacturer: manufacturer,
|
||||||
|
Environment: env,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysInfo() (serialNumber string, productName string, manufacturer string) {
|
||||||
|
var err error
|
||||||
|
serialNumber, err = sysNumber()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed to get system serial number: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
productName, err = sysProductName()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed to get system product name: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
manufacturer, err = sysManufacturer()
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed to get system manufacturer: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return serialNumber, productName, manufacturer
|
||||||
|
}
|
||||||
|
|
||||||
func getOSNameAndVersion() (string, string) {
|
func getOSNameAndVersion() (string, string) {
|
||||||
var dst []Win32_OperatingSystem
|
var dst []Win32_OperatingSystem
|
||||||
query := wmi.CreateQuery(&dst, "")
|
query := wmi.CreateQuery(&dst, "")
|
||||||
|
Loading…
Reference in New Issue
Block a user