fix: Enrollment-Duplikate, IPv6-Adresse, Agent-Status

- Backend: Enroll-Upsert via MAC-Adresse (kein Duplikat bei Neustart)
  HeartbeatInterval auf 30s reduziert
- Go collector: IPv4 bevorzugen, Loopback/Teredo/ISATAP überspringen,
  Link-Local IPv6 ignorieren
- Go main.go: Enrollment nimmt beste IPv4-Schnittstelle statt Networks[0]
This commit is contained in:
Claude Agent
2026-03-19 15:29:11 +01:00
parent 544d97b1ff
commit e55640d6a7
3 changed files with 64 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
package collector
import (
"net"
"strings"
"time"
"github.com/shirou/gopsutil/v3/cpu"
@@ -79,15 +81,41 @@ func Collect() (*Metrics, error) {
counterMap[c.Name] = c
}
for _, iface := range interfaces {
if len(iface.Addrs) == 0 {
if len(iface.Addrs) == 0 || iface.HardwareAddr == "" {
continue
}
// Loopback und virtuelle Adapter überspringen
nameLower := strings.ToLower(iface.Name)
if strings.Contains(nameLower, "loopback") || strings.Contains(nameLower, "teredo") ||
strings.Contains(nameLower, "isatap") || strings.Contains(nameLower, "6to4") {
continue
}
ni := NetInfo{
Name: iface.Name,
MAC: iface.HardwareAddr,
}
if len(iface.Addrs) > 0 {
ni.IPAddress = iface.Addrs[0].Addr
// IPv4 bevorzugen, IPv6 als Fallback
for _, addr := range iface.Addrs {
ip, _, err := net.ParseCIDR(addr.Addr)
if err != nil {
// Versuche direkte IP-Adresse (ohne CIDR)
ip = net.ParseIP(addr.Addr)
}
if ip == nil || ip.IsLoopback() || ip.IsLinkLocalUnicast() {
continue
}
if ip.To4() != nil {
// IPv4 gefunden — nehmen und abbrechen
ni.IPAddress = addr.Addr
break
}
if ni.IPAddress == "" {
// IPv6 als vorläufiger Fallback
ni.IPAddress = addr.Addr
}
}
if ni.IPAddress == "" {
continue
}
if c, ok := counterMap[iface.Name]; ok {
ni.BytesSent = c.BytesSent